mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-26 23:01:04 +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:
parent
1d4014dc52
commit
69b2affe05
181
CMakeLists.txt
181
CMakeLists.txt
@ -290,7 +290,6 @@ if (LIBZMQ_WERROR)
|
||||
zmq_check_cxx_flag_prepend ("-errwarn=%all")
|
||||
endif ()
|
||||
|
||||
|
||||
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^sparc")
|
||||
zmq_check_cxx_flag_prepend ("-mcpu=v9")
|
||||
endif ()
|
||||
@ -724,27 +723,45 @@ endif ()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# 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)
|
||||
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})
|
||||
set_target_properties (zmq-shared PROPERTIES
|
||||
PUBLIC_HEADER "${public_headers}"
|
||||
RELEASE_POSTFIX "${MSVC_TOOLSET}-mt-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
|
||||
RELWITHDEBINFO_POSTFIX "${MSVC_TOOLSET}-mt-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
|
||||
DEBUG_POSTFIX "${MSVC_TOOLSET}-mt-gd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
|
||||
COMPILE_DEFINITIONS "DLL_EXPORT"
|
||||
OUTPUT_NAME "libzmq")
|
||||
add_library (zmq-static STATIC ${sources})
|
||||
set_target_properties (zmq-static PROPERTIES
|
||||
PUBLIC_HEADER "${public_headers}"
|
||||
RELEASE_POSTFIX "${MSVC_TOOLSET}-mt-s-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
|
||||
RELWITHDEBINFO_POSTFIX "${MSVC_TOOLSET}-mt-s-${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"
|
||||
OUTPUT_NAME "libzmq")
|
||||
if (BUILD_SHARED)
|
||||
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})
|
||||
set_target_properties (zmq-shared PROPERTIES
|
||||
PUBLIC_HEADER "${public_headers}"
|
||||
RELEASE_POSTFIX "${MSVC_TOOLSET}-mt-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
|
||||
RELWITHDEBINFO_POSTFIX "${MSVC_TOOLSET}-mt-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
|
||||
DEBUG_POSTFIX "${MSVC_TOOLSET}-mt-gd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
|
||||
COMPILE_DEFINITIONS "DLL_EXPORT"
|
||||
OUTPUT_NAME "libzmq")
|
||||
endif()
|
||||
|
||||
if (BUILD_STATIC)
|
||||
add_library (zmq-static STATIC ${sources})
|
||||
set_target_properties (zmq-static PROPERTIES
|
||||
PUBLIC_HEADER "${public_headers}"
|
||||
RELEASE_POSTFIX "${MSVC_TOOLSET}-mt-s-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
|
||||
RELWITHDEBINFO_POSTFIX "${MSVC_TOOLSET}-mt-s-${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"
|
||||
OUTPUT_NAME "libzmq")
|
||||
endif()
|
||||
else ()
|
||||
if (BUILD_SHARED)
|
||||
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!
|
||||
set_target_properties (zmq-shared PROPERTIES
|
||||
@ -767,15 +784,19 @@ else ()
|
||||
set_source_files_properties (${zmq-pkgconfig} PROPERTIES
|
||||
MACOSX_PACKAGE_LOCATION lib/pkgconfig)
|
||||
endif ()
|
||||
endif()
|
||||
|
||||
if (BUILD_STATIC)
|
||||
add_library (zmq-static STATIC ${sources} ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig})
|
||||
set_target_properties (zmq-static PROPERTIES
|
||||
PUBLIC_HEADER "${public_headers}"
|
||||
COMPILE_DEFINITIONS "ZMQ_STATIC"
|
||||
OUTPUT_NAME "zmq"
|
||||
PREFIX "lib")
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
foreach (target zmq-shared zmq-static)
|
||||
foreach (target ${target_outputs})
|
||||
target_include_directories (${target}
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
@ -784,66 +805,72 @@ foreach (target zmq-shared zmq-static)
|
||||
)
|
||||
endforeach()
|
||||
|
||||
target_link_libraries (zmq-shared ${CMAKE_THREAD_LIBS_INIT})
|
||||
if (BUILD_SHARED)
|
||||
target_link_libraries (zmq-shared ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
if (SODIUM_FOUND)
|
||||
target_link_libraries (zmq-shared ${SODIUM_LIBRARIES})
|
||||
endif ()
|
||||
if (HAVE_WS2_32)
|
||||
target_link_libraries (zmq-shared ws2_32)
|
||||
elseif (HAVE_WS2)
|
||||
target_link_libraries (zmq-shared ws2)
|
||||
if (SODIUM_FOUND)
|
||||
target_link_libraries (zmq-shared ${SODIUM_LIBRARIES})
|
||||
endif ()
|
||||
if (HAVE_WS2_32)
|
||||
target_link_libraries (zmq-shared ws2_32)
|
||||
elseif (HAVE_WS2)
|
||||
target_link_libraries (zmq-shared ws2)
|
||||
endif ()
|
||||
|
||||
if (HAVE_RPCRT4)
|
||||
target_link_libraries (zmq-shared rpcrt4)
|
||||
endif ()
|
||||
|
||||
if (HAVE_IPHLAPI)
|
||||
target_link_libraries (zmq-shared iphlpapi)
|
||||
endif ()
|
||||
|
||||
if (RT_LIBRARY)
|
||||
target_link_libraries (zmq-shared ${RT_LIBRARY})
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
if (HAVE_RPCRT4)
|
||||
target_link_libraries (zmq-shared rpcrt4)
|
||||
endif ()
|
||||
if (BUILD_SHARED)
|
||||
set (perf-tools local_lat
|
||||
remote_lat
|
||||
local_thr
|
||||
remote_thr
|
||||
inproc_lat
|
||||
inproc_thr)
|
||||
|
||||
if (HAVE_IPHLAPI)
|
||||
target_link_libraries (zmq-shared iphlpapi)
|
||||
endif ()
|
||||
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug") # Why?
|
||||
option (WITH_PERF_TOOL "Build with perf-tools" ON)
|
||||
else ()
|
||||
option (WITH_PERF_TOOL "Build with perf-tools" OFF)
|
||||
endif ()
|
||||
|
||||
if (RT_LIBRARY)
|
||||
target_link_libraries (zmq-shared ${RT_LIBRARY})
|
||||
endif ()
|
||||
if (WITH_PERF_TOOL)
|
||||
foreach (perf-tool ${perf-tools})
|
||||
add_executable (${perf-tool} perf/${perf-tool}.cpp)
|
||||
target_link_libraries (${perf-tool} zmq-shared ${OPTIONAL_LIBRARIES})
|
||||
|
||||
set (perf-tools local_lat
|
||||
remote_lat
|
||||
local_thr
|
||||
remote_thr
|
||||
inproc_lat
|
||||
inproc_thr)
|
||||
if (RT_LIBRARY)
|
||||
target_link_libraries (${perf-tool} ${RT_LIBRARY})
|
||||
endif ()
|
||||
|
||||
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug") # Why?
|
||||
option (WITH_PERF_TOOL "Build with perf-tools" ON)
|
||||
else ()
|
||||
option (WITH_PERF_TOOL "Build with perf-tools" OFF)
|
||||
endif ()
|
||||
|
||||
if (WITH_PERF_TOOL)
|
||||
foreach (perf-tool ${perf-tools})
|
||||
add_executable (${perf-tool} perf/${perf-tool}.cpp)
|
||||
target_link_libraries (${perf-tool} zmq-shared ${OPTIONAL_LIBRARIES})
|
||||
|
||||
if (RT_LIBRARY)
|
||||
target_link_libraries (${perf-tool} ${RT_LIBRARY})
|
||||
endif ()
|
||||
|
||||
if (ZMQ_BUILD_FRAMEWORK)
|
||||
# Copy perf-tools binaries into Framework
|
||||
add_custom_command (
|
||||
TARGET zmq-shared ${perf-tool}
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
ARGS -E copy "$<TARGET_FILE:${perf-tool}>" "${LIBRARY_OUTPUT_PATH}/ZeroMQ.framework/Versions/${ZMQ_VERSION_STRING}/MacOS/${perf-tool}"
|
||||
VERBATIM
|
||||
COMMENT "Perf tools")
|
||||
else ()
|
||||
install (TARGETS ${perf-tool}
|
||||
RUNTIME DESTINATION bin
|
||||
COMPONENT PerfTools)
|
||||
endif ()
|
||||
endforeach ()
|
||||
if (ZMQ_BUILD_FRAMEWORK)
|
||||
# Copy perf-tools binaries into Framework
|
||||
add_custom_command (
|
||||
TARGET zmq-shared ${perf-tool}
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
ARGS -E copy "$<TARGET_FILE:${perf-tool}>" "${LIBRARY_OUTPUT_PATH}/ZeroMQ.framework/Versions/${ZMQ_VERSION_STRING}/MacOS/${perf-tool}"
|
||||
VERBATIM
|
||||
COMMENT "Perf tools")
|
||||
else ()
|
||||
install (TARGETS ${perf-tool}
|
||||
RUNTIME DESTINATION bin
|
||||
COMPONENT PerfTools)
|
||||
endif ()
|
||||
endforeach ()
|
||||
endif ()
|
||||
elseif (WITH_PERF_TOOL)
|
||||
message(FATAL_ERROR "Shared library disabled - perf-tools unavailable.")
|
||||
endif ()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
@ -862,14 +889,14 @@ endif ()
|
||||
include(GNUInstallDirs)
|
||||
|
||||
if (MSVC)
|
||||
install (TARGETS zmq-shared zmq-static
|
||||
install (TARGETS ${target_outputs}
|
||||
EXPORT ${PROJECT_NAME}-targets
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
COMPONENT SDK)
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
install (TARGETS zmq-shared zmq-static
|
||||
install (TARGETS ${target_outputs}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
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
|
||||
COMPONENT SDK)
|
||||
endif ()
|
||||
else ()
|
||||
elseif (BUILD_SHARED)
|
||||
install (TARGETS zmq-shared
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
COMPONENT Runtime)
|
||||
endif ()
|
||||
else ()
|
||||
install (TARGETS zmq-shared zmq-static
|
||||
install (TARGETS ${target_outputs}
|
||||
EXPORT ${PROJECT_NAME}-targets
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
|
Loading…
x
Reference in New Issue
Block a user