SET(SOURCES
    apr.cpp
    client_annotate.cpp
    client_cat.cpp
    client.cpp
    client_diff.cpp
    client_ls.cpp
    client_modify.cpp
    client_property.cpp
    client_status.cpp
    context.cpp
    datetime.cpp
    dirent.cpp
    entry.cpp
    exception.cpp
    log_entry.cpp
    path.cpp
    pool.cpp
    revision.cpp
    status.cpp
    targets.cpp
    url.cpp
    wc.cpp
    version_check.cpp
    lock_entry.cpp
    client_lock.cpp
    info_entry.cpp
    client_impl.cpp
    contextdata.cpp
    commititem.cpp
    repository.cpp
    repositorydata.cpp
    repositorylistener.cpp
    svnstream.cpp
    svnfilestream.cpp)

FILE(GLOB HEADERS *.hpp)

IF(NOT WIN32)
    ADD_LIBRARY(svnqt SHARED ${SOURCES} )
ELSE(NOT WIN32)
    ADD_LIBRARY(svnqt STATIC ${SOURCES} )
ENDIF(NOT WIN32)

#for a libtool like .la file
SET(LIBLA_CURRENT 4)
SET(LIBLA_AGE 2)
SET(LIBLA_REVISION 2)

MATH(EXPR LIB_MAJOR '${LIBLA_CURRENT}-${LIBLA_AGE}')
SET(LIB_MINOR ${LIBLA_AGE})
SET(LIB_RELEASE ${LIBLA_REVISION})

SET(_soversion ${LIB_MAJOR}.${LIB_MINOR}.${LIB_RELEASE})
IF (WIN32)
   SET(_soversion "-${LIB_MAJOR}")
ENDIF (WIN32)
IF(SUNOS)
   SET(LIB_MAJOR ${LIBLA_CURRENT})
   SET(_soversion "${LIBLA_CURRENT}.${LIBLA_REVISION}")
ENDIF(SUNOS)
#don't understand how to do that with darwin and freebsd and so on
#may some of that guy may give a hint.

IF(NOT WIN32)
SET_TARGET_PROPERTIES(svnqt PROPERTIES 
    SOVERSION ${LIB_MAJOR} 
    VERSION ${_soversion})
ENDIF(NOT WIN32)

SET(ALL_LINKFLAGS ${APR_EXTRA_LIBFLAGS})
SET(ALL_LINKFLAGS "${ALL_LINKFLAGS} ${APU_EXTRA_LIBFLAGS}")
SET_TARGET_PROPERTIES(svnqt PROPERTIES LINK_FLAGS "${ALL_LINKFLAGS} ${LINK_NO_UNDEFINED}")
TARGET_LINK_LIBRARIES(svnqt ${QT_LIBRARIES} ${SUBVERSION_ALL_LIBS})

# Just a small linking test
ADD_EXECUTABLE(testlink testmain.cpp)
TARGET_LINK_LIBRARIES(testlink svnqt)

# install rules
# in win32 we don't install it
IF(NOT WIN32)
    INSTALL(TARGETS svnqt DESTINATION lib)
    INSTALL(FILES ${HEADERS} DESTINATION include/svnqt)

    # and a libtool file
    GET_TARGET_PROPERTY(_target_location svnqt LOCATION)

    GET_FILENAME_COMPONENT(_laname ${_target_location} NAME_WE)
    GET_FILENAME_COMPONENT(_soname ${_target_location} NAME)
    SET(_laname ${LIBRARY_OUTPUT_PATH}/${_laname}.la)

    FILE(WRITE ${_laname} "# libsvnqt.la - a libtool library file, generated by cmake \n")
    FILE(APPEND ${_laname} "# The name that we can dlopen(3).\n")
    FILE(APPEND ${_laname} "dlname='${_soname}.${LIB_MAJOR}'\n")
    FILE(APPEND ${_laname} "# Names of this library\n")
    FILE(APPEND ${_laname} "library_names='${_soname}.${LIB_MAJOR}.${LIB_MINOR}.${LIB_RELEASE} ${_soname}.${LIB_MAJOR} ${_soname}'\n")
    FILE(APPEND ${_laname} "# The name of the static archive\n")
    FILE(APPEND ${_laname} "old_library=''\n")
    FILE(APPEND ${_laname} "# Libraries that this one depends upon.\n")
    FILE(APPEND ${_laname} "dependency_libs=''\n")
    FILE(APPEND ${_laname} "# Version information for ${_soname}\n")
    FILE(APPEND ${_laname} "current=${LIBLA_CURRENT}\nage=${LIBLA_AGE}\nrevision=${LIBLA_REVISION}\n")
    FILE(APPEND ${_laname} "# Is this an already installed library?\ninstalled=yes\n")
    FILE(APPEND ${_laname} "# Should we warn about portability when linking against -modules?\nshouldnotlink=no\n")
    FILE(APPEND ${_laname} "# Files to dlopen/dlpreopen\ndlopen=''\ndlpreopen=''\n")
    FILE(APPEND ${_laname} "# Directory that this library needs to be installed in:\n")
    FILE(APPEND ${_laname} "libdir='${CMAKE_INSTALL_PREFIX}/lib'\n")
    INSTALL_FILES(/lib FILES ${_laname})
ENDIF(NOT WIN32)
