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()
# Shared library
ADD_LIBRARY(
${VMIME_LIBRARY_NAME}
SHARED
${VMIME_LIBRARY_SRC_FILES}
${VMIME_LIBRARY_INCLUDE_FILES}
OPTION(
VMIME_BUILD_SHARED_LIBRARY
"Build shared library"
ON
)
SET_TARGET_PROPERTIES(
${VMIME_LIBRARY_NAME}
PROPERTIES
VERSION "${VMIME_VERSION}"
SOVERSION "${VMIME_API_VERSION}"
)
IF(VMIME_BUILD_SHARED_LIBRARY)
ADD_LIBRARY(
${VMIME_LIBRARY_NAME}
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
#
# 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.
ADD_LIBRARY(
${VMIME_LIBRARY_NAME}-static
STATIC
${VMIME_LIBRARY_SRC_FILES}
${VMIME_LIBRARY_INCLUDE_FILES}
OPTION(
VMIME_BUILD_STATIC_LIBRARY
"Build static library"
ON
)
SET_TARGET_PROPERTIES(
${VMIME_LIBRARY_NAME}-static
PROPERTIES
OUTPUT_NAME ${VMIME_LIBRARY_NAME}
)
IF(VMIME_BUILD_STATIC_LIBRARY)
ADD_LIBRARY(
${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.
# The CMake FAQ mentions they are necessary and it does not work otherwise.
SET_TARGET_PROPERTIES(${VMIME_LIBRARY_NAME} PROPERTIES CLEAN_DIRECT_OUTPUT 1)
SET_TARGET_PROPERTIES(${VMIME_LIBRARY_NAME}-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
IF(VMIME_BUILD_SHARED_LIBRARY)
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")
# Installation of libraries
INSTALL(
TARGETS ${VMIME_LIBRARY_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT sharedlibs
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT sharedlibs
)
IF(VMIME_BUILD_SHARED_LIBRARY)
INSTALL(
TARGETS ${VMIME_LIBRARY_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT sharedlibs
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT sharedlibs
)
ENDIF()
INSTALL(
TARGETS ${VMIME_LIBRARY_NAME}-static
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT staticlibs
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT staticlibs
)
IF(VMIME_BUILD_STATIC_LIBRARY)
INSTALL(
TARGETS ${VMIME_LIBRARY_NAME}-static
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT staticlibs
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT staticlibs
)
ENDIF()
# Installation of header files
INSTALL_HEADERS_WITH_DIRECTORY(VMIME_LIBRARY_INCLUDE_FILES headers)
@ -440,11 +473,13 @@ IF(VMIME_HAVE_SASL_SUPPORT)
${GSASL_INCLUDE_DIR}
)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME}
${TARGET_LINK_LIBRARIES}
${GSASL_LIBRARIES}
)
IF(VMIME_BUILD_SHARED_LIBRARY)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME}
${TARGET_LINK_LIBRARIES}
${GSASL_LIBRARIES}
)
ENDIF()
SET(VMIME_PKGCONFIG_LIBS "${VMIME_PKGCONFIG_LIBS} ${GSASL_LIBRARIES}")
SET(VMIME_PKGCONFIG_CFLAGS "${VMIME_PKGCONFIG_CFLAGS} ${GSASL_INCLUDE_DIR}")
@ -495,11 +530,13 @@ IF(VMIME_HAVE_TLS_SUPPORT)
${GNUTLS_LIBRARY_DIRS}
)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME}
${TARGET_LINK_LIBRARIES}
${GNUTLS_LIBRARY}
)
IF(VMIME_BUILD_SHARED_LIBRARY)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME}
${TARGET_LINK_LIBRARIES}
${GNUTLS_LIBRARY}
)
ENDIF()
SET(VMIME_PKGCONFIG_LIBS "${VMIME_PKGCONFIG_LIBS} ${GNUTLS_LIBRARY_DIRS} ${GNUTLS_LIBRARY}")
SET(VMIME_PKGCONFIG_CFLAGS "${VMIME_PKGCONFIG_CFLAGS} ${GNUTLS_INCLUDE_DIR}")
@ -512,11 +549,13 @@ IF(VMIME_HAVE_TLS_SUPPORT)
${OPENSSL_INCLUDE_DIR}
)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME}
${TARGET_LINK_LIBRARIES}
${OPENSSL_LIBRARIES}
)
IF(VMIME_BUILD_SHARED_LIBRARY)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME}
${TARGET_LINK_LIBRARIES}
${OPENSSL_LIBRARIES}
)
ENDIF()
SET(VMIME_PKGCONFIG_LIBS "${VMIME_PKGCONFIG_LIBS} ${OPENSSL_LIBRARIES}")
SET(VMIME_PKGCONFIG_CFLAGS "${VMIME_PKGCONFIG_CFLAGS} ${OPENSSL_INCLUDE_DIR}")
@ -541,11 +580,13 @@ INCLUDE_DIRECTORIES(
${ICONV_INCLUDE_DIR}
)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME}
${TARGET_LINK_LIBRARIES}
${ICONV_LIBRARIES}
)
IF(VMIME_BUILD_SHARED_LIBRARY)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME}
${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)
IF(VMIME_HAVE_LIBWS2_32)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME}
${TARGET_LINK_LIBRARIES}
"ws2_32"
)
IF(VMIME_BUILD_SHARED_LIBRARY)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME}
${TARGET_LINK_LIBRARIES}
"ws2_32"
)
ENDIF()
ENDIF()
# MLang
@ -595,11 +638,13 @@ IF(WIN32)
IF(VMIME_HAVE_MLANG_LIB)
SET(VMIME_HAVE_MLANG ON)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME}
${TARGET_LINK_LIBRARIES}
"mlang"
)
IF(VMIME_BUILD_SHARED_LIBRARY)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME}
${TARGET_LINK_LIBRARIES}
"mlang"
)
ENDIF()
ENDIF()
ENDIF()
@ -618,21 +663,26 @@ CHECK_SYMBOL_EXISTS(SYS_gettid sys/syscall.h VMIME_HAVE_SYSCALL_GETTID)
FIND_PACKAGE(Threads)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME}
${TARGET_LINK_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
IF(VMIME_BUILD_SHARED_LIBRARY)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME}
${TARGET_LINK_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
ENDIF()
FIND_LIBRARY(PTHREAD_LIB pthread)
IF(PTHREAD_LIB)
SET(VMIME_HAVE_PTHREAD 1)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME}
${TARGET_LINK_LIBRARIES}
${PTHREAD_LIB}
)
IF(VMIME_BUILD_SHARED_LIBRARY)
TARGET_LINK_LIBRARIES(
${VMIME_LIBRARY_NAME}
${TARGET_LINK_LIBRARIES}
${PTHREAD_LIB}
)
ENDIF()
ELSE(PTHREAD_LIB)
SET(VMIME_HAVE_PTHREAD 0)
ENDIF(PTHREAD_LIB)