0
0
mirror of https://github.com/zeromq/libzmq.git synced 2025-01-14 09:47:56 +08:00

Add CMake Build Output Options

Add two new options to CMakeLists.txt:

`BUILD_SHARED` - Whether or not to build the shared object (Default: ON)
`BUILD_STATIC` - Whether or not to build the static archive (Default: ON)
This commit is contained in:
RPGillespie6 2017-04-17 18:26:04 -04:00 committed by GitHub
parent 1d4014dc52
commit 69b2affe05

View File

@ -290,7 +290,6 @@ if (LIBZMQ_WERROR)
zmq_check_cxx_flag_prepend ("-errwarn=%all") zmq_check_cxx_flag_prepend ("-errwarn=%all")
endif () endif ()
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^sparc") if (CMAKE_SYSTEM_PROCESSOR MATCHES "^sparc")
zmq_check_cxx_flag_prepend ("-mcpu=v9") zmq_check_cxx_flag_prepend ("-mcpu=v9")
endif () endif ()
@ -724,8 +723,21 @@ endif ()
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# output # output
option(BUILD_SHARED "Whether or not to build the shared object" ON)
option(BUILD_STATIC "Whether or not to build the static archive" ON)
list(APPEND target_outputs "")
if (BUILD_SHARED)
list(APPEND target_outputs "zmq-shared")
endif()
if (BUILD_STATIC)
list(APPEND target_outputs "zmq-static")
endif()
if (MSVC) if (MSVC)
if (BUILD_SHARED)
add_library (zmq-shared SHARED ${sources} ${public_headers} ${html-docs} ${readme-docs} ${CMAKE_CURRENT_BINARY_DIR}/NSIS.template.in) add_library (zmq-shared SHARED ${sources} ${public_headers} ${html-docs} ${readme-docs} ${CMAKE_CURRENT_BINARY_DIR}/NSIS.template.in)
target_link_libraries (zmq-shared ${OPTIONAL_LIBRARIES}) target_link_libraries (zmq-shared ${OPTIONAL_LIBRARIES})
set_target_properties (zmq-shared PROPERTIES set_target_properties (zmq-shared PROPERTIES
@ -736,6 +748,9 @@ if (MSVC)
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
COMPILE_DEFINITIONS "DLL_EXPORT" COMPILE_DEFINITIONS "DLL_EXPORT"
OUTPUT_NAME "libzmq") OUTPUT_NAME "libzmq")
endif()
if (BUILD_STATIC)
add_library (zmq-static STATIC ${sources}) add_library (zmq-static STATIC ${sources})
set_target_properties (zmq-static PROPERTIES set_target_properties (zmq-static PROPERTIES
PUBLIC_HEADER "${public_headers}" PUBLIC_HEADER "${public_headers}"
@ -744,7 +759,9 @@ if (MSVC)
DEBUG_POSTFIX "${MSVC_TOOLSET}-mt-sgd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}" DEBUG_POSTFIX "${MSVC_TOOLSET}-mt-sgd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
COMPILE_FLAGS "/DZMQ_STATIC" COMPILE_FLAGS "/DZMQ_STATIC"
OUTPUT_NAME "libzmq") OUTPUT_NAME "libzmq")
endif()
else () else ()
if (BUILD_SHARED)
add_library (zmq-shared SHARED ${sources} ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig}) add_library (zmq-shared SHARED ${sources} ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig})
# NOTE: the SOVERSION MUST be the same as the one generated by libtool! # NOTE: the SOVERSION MUST be the same as the one generated by libtool!
set_target_properties (zmq-shared PROPERTIES set_target_properties (zmq-shared PROPERTIES
@ -767,6 +784,9 @@ else ()
set_source_files_properties (${zmq-pkgconfig} PROPERTIES set_source_files_properties (${zmq-pkgconfig} PROPERTIES
MACOSX_PACKAGE_LOCATION lib/pkgconfig) MACOSX_PACKAGE_LOCATION lib/pkgconfig)
endif () endif ()
endif()
if (BUILD_STATIC)
add_library (zmq-static STATIC ${sources} ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig}) add_library (zmq-static STATIC ${sources} ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig})
set_target_properties (zmq-static PROPERTIES set_target_properties (zmq-static PROPERTIES
PUBLIC_HEADER "${public_headers}" PUBLIC_HEADER "${public_headers}"
@ -774,8 +794,9 @@ else ()
OUTPUT_NAME "zmq" OUTPUT_NAME "zmq"
PREFIX "lib") PREFIX "lib")
endif() endif()
endif ()
foreach (target zmq-shared zmq-static) foreach (target ${target_outputs})
target_include_directories (${target} target_include_directories (${target}
PUBLIC PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
@ -784,6 +805,7 @@ foreach (target zmq-shared zmq-static)
) )
endforeach() endforeach()
if (BUILD_SHARED)
target_link_libraries (zmq-shared ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (zmq-shared ${CMAKE_THREAD_LIBS_INIT})
if (SODIUM_FOUND) if (SODIUM_FOUND)
@ -806,7 +828,9 @@ endif ()
if (RT_LIBRARY) if (RT_LIBRARY)
target_link_libraries (zmq-shared ${RT_LIBRARY}) target_link_libraries (zmq-shared ${RT_LIBRARY})
endif () endif ()
endif ()
if (BUILD_SHARED)
set (perf-tools local_lat set (perf-tools local_lat
remote_lat remote_lat
local_thr local_thr
@ -845,6 +869,9 @@ if (WITH_PERF_TOOL)
endif () endif ()
endforeach () endforeach ()
endif () endif ()
elseif (WITH_PERF_TOOL)
message(FATAL_ERROR "Shared library disabled - perf-tools unavailable.")
endif ()
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# tests # tests
@ -862,14 +889,14 @@ endif ()
include(GNUInstallDirs) include(GNUInstallDirs)
if (MSVC) if (MSVC)
install (TARGETS zmq-shared zmq-static install (TARGETS ${target_outputs}
EXPORT ${PROJECT_NAME}-targets EXPORT ${PROJECT_NAME}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT SDK) COMPONENT SDK)
if (CMAKE_BUILD_TYPE STREQUAL "Debug") if (CMAKE_BUILD_TYPE STREQUAL "Debug")
install (TARGETS zmq-shared zmq-static install (TARGETS ${target_outputs}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
@ -878,14 +905,14 @@ if (MSVC)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/bin/libzmq${MSVC_TOOLSET}-mt-gd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}.pdb DESTINATION lib install (FILES ${CMAKE_CURRENT_BINARY_DIR}/bin/libzmq${MSVC_TOOLSET}-mt-gd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}.pdb DESTINATION lib
COMPONENT SDK) COMPONENT SDK)
endif () endif ()
else () elseif (BUILD_SHARED)
install (TARGETS zmq-shared install (TARGETS zmq-shared
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT Runtime) COMPONENT Runtime)
endif () endif ()
else () else ()
install (TARGETS zmq-shared zmq-static install (TARGETS ${target_outputs}
EXPORT ${PROJECT_NAME}-targets EXPORT ${PROJECT_NAME}-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}