Selective build of shared/static library (issue #27).

This commit is contained in:
Vincent Richard 2013-03-01 10:53:43 +01:00
parent b9ace81807
commit 18846c3691

View File

@ -89,56 +89,89 @@ IF(UNIX AND NOT APPLE AND NOT CMAKE_CROSSCOMPILING AND NOT EXISTS "/etc/debian_v
ENDIF() ENDIF()
# Shared library # Shared library
ADD_LIBRARY( OPTION(
${VMIME_LIBRARY_NAME} VMIME_BUILD_SHARED_LIBRARY
SHARED "Build shared library"
${VMIME_LIBRARY_SRC_FILES} ON
${VMIME_LIBRARY_INCLUDE_FILES}
) )
SET_TARGET_PROPERTIES( IF(VMIME_BUILD_SHARED_LIBRARY)
${VMIME_LIBRARY_NAME}
PROPERTIES ADD_LIBRARY(
VERSION "${VMIME_VERSION}" ${VMIME_LIBRARY_NAME}
SOVERSION "${VMIME_API_VERSION}" SHARED
) ${VMIME_LIBRARY_SRC_FILES}
${VMIME_LIBRARY_INCLUDE_FILES}
)
SET_TARGET_PROPERTIES(
${VMIME_LIBRARY_NAME}
PROPERTIES
VERSION "${VMIME_VERSION}"
SOVERSION "${VMIME_API_VERSION}"
)
ENDIF()
# Static library # Static library
# #
# Note: cannot have two targets with the same name so the static version has # Note: cannot have two targets with the same name so the static version has
# '-static' appended and then the name of the output file is set separately. # '-static' appended and then the name of the output file is set separately.
ADD_LIBRARY( OPTION(
${VMIME_LIBRARY_NAME}-static VMIME_BUILD_STATIC_LIBRARY
STATIC "Build static library"
${VMIME_LIBRARY_SRC_FILES} ON
${VMIME_LIBRARY_INCLUDE_FILES}
) )
SET_TARGET_PROPERTIES( IF(VMIME_BUILD_STATIC_LIBRARY)
${VMIME_LIBRARY_NAME}-static
PROPERTIES ADD_LIBRARY(
OUTPUT_NAME ${VMIME_LIBRARY_NAME} ${VMIME_LIBRARY_NAME}-static
) STATIC
${VMIME_LIBRARY_SRC_FILES}
${VMIME_LIBRARY_INCLUDE_FILES}
)
SET_TARGET_PROPERTIES(
${VMIME_LIBRARY_NAME}-static
PROPERTIES
OUTPUT_NAME ${VMIME_LIBRARY_NAME}
)
ENDIF()
# Ensure at least one type of library (either shared or static) is build
IF(NOT(VMIME_BUILD_SHARED_LIBRARY OR VMIME_BUILD_STATIC_LIBRARY))
MESSAGE(FATAL_ERROR "You should select at least one library to build (either VMIME_BUILD_SHARED_LIBRARY or VMIME_BUILD_STATIC_LIBRARY must be set to YES.")
ENDIF()
# These next two lines are required but it is unclear exactly what they do. # These next two lines are required but it is unclear exactly what they do.
# The CMake FAQ mentions they are necessary and it does not work otherwise. # The CMake FAQ mentions they are necessary and it does not work otherwise.
SET_TARGET_PROPERTIES(${VMIME_LIBRARY_NAME} PROPERTIES CLEAN_DIRECT_OUTPUT 1) IF(VMIME_BUILD_SHARED_LIBRARY)
SET_TARGET_PROPERTIES(${VMIME_LIBRARY_NAME}-static PROPERTIES CLEAN_DIRECT_OUTPUT 1) SET_TARGET_PROPERTIES(${VMIME_LIBRARY_NAME} PROPERTIES CLEAN_DIRECT_OUTPUT 1)
ENDIF()
IF(VMIME_BUILD_STATIC_LIBRARY)
SET_TARGET_PROPERTIES(${VMIME_LIBRARY_NAME}-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
ENDIF()
SET(CMAKE_INSTALL_LIBDIR lib CACHE PATH "Output directory for libraries") SET(CMAKE_INSTALL_LIBDIR lib CACHE PATH "Output directory for libraries")
# Installation of libraries # Installation of libraries
INSTALL( IF(VMIME_BUILD_SHARED_LIBRARY)
TARGETS ${VMIME_LIBRARY_NAME} INSTALL(
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT sharedlibs TARGETS ${VMIME_LIBRARY_NAME}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT sharedlibs LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT sharedlibs
) ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT sharedlibs
)
ENDIF()
INSTALL( IF(VMIME_BUILD_STATIC_LIBRARY)
TARGETS ${VMIME_LIBRARY_NAME}-static INSTALL(
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT staticlibs TARGETS ${VMIME_LIBRARY_NAME}-static
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT staticlibs LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT staticlibs
) ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT staticlibs
)
ENDIF()
# Installation of header files # Installation of header files
INSTALL_HEADERS_WITH_DIRECTORY(VMIME_LIBRARY_INCLUDE_FILES headers) INSTALL_HEADERS_WITH_DIRECTORY(VMIME_LIBRARY_INCLUDE_FILES headers)
@ -440,11 +473,13 @@ IF(VMIME_HAVE_SASL_SUPPORT)
${GSASL_INCLUDE_DIR} ${GSASL_INCLUDE_DIR}
) )
TARGET_LINK_LIBRARIES( IF(VMIME_BUILD_SHARED_LIBRARY)
${VMIME_LIBRARY_NAME} TARGET_LINK_LIBRARIES(
${TARGET_LINK_LIBRARIES} ${VMIME_LIBRARY_NAME}
${GSASL_LIBRARIES} ${TARGET_LINK_LIBRARIES}
) ${GSASL_LIBRARIES}
)
ENDIF()
SET(VMIME_PKGCONFIG_LIBS "${VMIME_PKGCONFIG_LIBS} ${GSASL_LIBRARIES}") SET(VMIME_PKGCONFIG_LIBS "${VMIME_PKGCONFIG_LIBS} ${GSASL_LIBRARIES}")
SET(VMIME_PKGCONFIG_CFLAGS "${VMIME_PKGCONFIG_CFLAGS} ${GSASL_INCLUDE_DIR}") SET(VMIME_PKGCONFIG_CFLAGS "${VMIME_PKGCONFIG_CFLAGS} ${GSASL_INCLUDE_DIR}")
@ -495,11 +530,13 @@ IF(VMIME_HAVE_TLS_SUPPORT)
${GNUTLS_LIBRARY_DIRS} ${GNUTLS_LIBRARY_DIRS}
) )
TARGET_LINK_LIBRARIES( IF(VMIME_BUILD_SHARED_LIBRARY)
${VMIME_LIBRARY_NAME} TARGET_LINK_LIBRARIES(
${TARGET_LINK_LIBRARIES} ${VMIME_LIBRARY_NAME}
${GNUTLS_LIBRARY} ${TARGET_LINK_LIBRARIES}
) ${GNUTLS_LIBRARY}
)
ENDIF()
SET(VMIME_PKGCONFIG_LIBS "${VMIME_PKGCONFIG_LIBS} ${GNUTLS_LIBRARY_DIRS} ${GNUTLS_LIBRARY}") SET(VMIME_PKGCONFIG_LIBS "${VMIME_PKGCONFIG_LIBS} ${GNUTLS_LIBRARY_DIRS} ${GNUTLS_LIBRARY}")
SET(VMIME_PKGCONFIG_CFLAGS "${VMIME_PKGCONFIG_CFLAGS} ${GNUTLS_INCLUDE_DIR}") SET(VMIME_PKGCONFIG_CFLAGS "${VMIME_PKGCONFIG_CFLAGS} ${GNUTLS_INCLUDE_DIR}")
@ -512,11 +549,13 @@ IF(VMIME_HAVE_TLS_SUPPORT)
${OPENSSL_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR}
) )
TARGET_LINK_LIBRARIES( IF(VMIME_BUILD_SHARED_LIBRARY)
${VMIME_LIBRARY_NAME} TARGET_LINK_LIBRARIES(
${TARGET_LINK_LIBRARIES} ${VMIME_LIBRARY_NAME}
${OPENSSL_LIBRARIES} ${TARGET_LINK_LIBRARIES}
) ${OPENSSL_LIBRARIES}
)
ENDIF()
SET(VMIME_PKGCONFIG_LIBS "${VMIME_PKGCONFIG_LIBS} ${OPENSSL_LIBRARIES}") SET(VMIME_PKGCONFIG_LIBS "${VMIME_PKGCONFIG_LIBS} ${OPENSSL_LIBRARIES}")
SET(VMIME_PKGCONFIG_CFLAGS "${VMIME_PKGCONFIG_CFLAGS} ${OPENSSL_INCLUDE_DIR}") SET(VMIME_PKGCONFIG_CFLAGS "${VMIME_PKGCONFIG_CFLAGS} ${OPENSSL_INCLUDE_DIR}")
@ -541,11 +580,13 @@ INCLUDE_DIRECTORIES(
${ICONV_INCLUDE_DIR} ${ICONV_INCLUDE_DIR}
) )
TARGET_LINK_LIBRARIES( IF(VMIME_BUILD_SHARED_LIBRARY)
${VMIME_LIBRARY_NAME} TARGET_LINK_LIBRARIES(
${TARGET_LINK_LIBRARIES} ${VMIME_LIBRARY_NAME}
${ICONV_LIBRARIES} ${TARGET_LINK_LIBRARIES}
) ${ICONV_LIBRARIES}
)
ENDIF()
############################################################################## ##############################################################################
@ -580,11 +621,13 @@ IF(WIN32)
CHECK_LIBRARY_EXISTS("ws2_32" getch "${CMAKE_LIBRARY_PATH}" VMIME_HAVE_LIBWS2_32) CHECK_LIBRARY_EXISTS("ws2_32" getch "${CMAKE_LIBRARY_PATH}" VMIME_HAVE_LIBWS2_32)
IF(VMIME_HAVE_LIBWS2_32) IF(VMIME_HAVE_LIBWS2_32)
TARGET_LINK_LIBRARIES( IF(VMIME_BUILD_SHARED_LIBRARY)
${VMIME_LIBRARY_NAME} TARGET_LINK_LIBRARIES(
${TARGET_LINK_LIBRARIES} ${VMIME_LIBRARY_NAME}
"ws2_32" ${TARGET_LINK_LIBRARIES}
) "ws2_32"
)
ENDIF()
ENDIF() ENDIF()
# MLang # MLang
@ -595,11 +638,13 @@ IF(WIN32)
IF(VMIME_HAVE_MLANG_LIB) IF(VMIME_HAVE_MLANG_LIB)
SET(VMIME_HAVE_MLANG ON) SET(VMIME_HAVE_MLANG ON)
TARGET_LINK_LIBRARIES( IF(VMIME_BUILD_SHARED_LIBRARY)
${VMIME_LIBRARY_NAME} TARGET_LINK_LIBRARIES(
${TARGET_LINK_LIBRARIES} ${VMIME_LIBRARY_NAME}
"mlang" ${TARGET_LINK_LIBRARIES}
) "mlang"
)
ENDIF()
ENDIF() ENDIF()
ENDIF() ENDIF()
@ -618,21 +663,26 @@ CHECK_SYMBOL_EXISTS(SYS_gettid sys/syscall.h VMIME_HAVE_SYSCALL_GETTID)
FIND_PACKAGE(Threads) FIND_PACKAGE(Threads)
TARGET_LINK_LIBRARIES( IF(VMIME_BUILD_SHARED_LIBRARY)
${VMIME_LIBRARY_NAME} TARGET_LINK_LIBRARIES(
${TARGET_LINK_LIBRARIES} ${VMIME_LIBRARY_NAME}
${CMAKE_THREAD_LIBS_INIT} ${TARGET_LINK_LIBRARIES}
) ${CMAKE_THREAD_LIBS_INIT}
)
ENDIF()
FIND_LIBRARY(PTHREAD_LIB pthread) FIND_LIBRARY(PTHREAD_LIB pthread)
IF(PTHREAD_LIB) IF(PTHREAD_LIB)
SET(VMIME_HAVE_PTHREAD 1) SET(VMIME_HAVE_PTHREAD 1)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME} IF(VMIME_BUILD_SHARED_LIBRARY)
${TARGET_LINK_LIBRARIES} TARGET_LINK_LIBRARIES(
${PTHREAD_LIB} ${VMIME_LIBRARY_NAME}
) ${TARGET_LINK_LIBRARIES}
${PTHREAD_LIB}
)
ENDIF()
ELSE(PTHREAD_LIB) ELSE(PTHREAD_LIB)
SET(VMIME_HAVE_PTHREAD 0) SET(VMIME_HAVE_PTHREAD 0)
ENDIF(PTHREAD_LIB) ENDIF(PTHREAD_LIB)