mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-26 23:01:04 +08:00
Problem: CMake rebuilds everything twice
Solution: build all the objects separately before the link step, to avoid rebuilding when doing both static and shared builds
This commit is contained in:
parent
5264d49eab
commit
0298d037d0
@ -575,8 +575,6 @@ set (cxx-sources
|
||||
gather.cpp
|
||||
zap_client.cpp)
|
||||
|
||||
set (rc-sources version.rc)
|
||||
|
||||
if (MINGW)
|
||||
# Generate the right type when using -m32 or -m64
|
||||
macro (set_rc_arch rc_target)
|
||||
@ -643,10 +641,7 @@ foreach (source ${cxx-sources})
|
||||
list (APPEND sources ${CMAKE_CURRENT_SOURCE_DIR}/src/${source})
|
||||
endforeach ()
|
||||
|
||||
foreach (source ${rc-sources})
|
||||
list (APPEND sources ${CMAKE_CURRENT_BINARY_DIR}/${source})
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/src/${source}.in ${CMAKE_CURRENT_BINARY_DIR}/${source})
|
||||
endforeach ()
|
||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/src/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
|
||||
|
||||
# Delete any src/platform.hpp left by configure
|
||||
file (REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/src/platform.hpp)
|
||||
@ -751,12 +746,16 @@ if (BUILD_STATIC)
|
||||
list(APPEND target_outputs "libzmq-static")
|
||||
endif()
|
||||
|
||||
# avoid building everything twice for shared + static
|
||||
add_library (objects OBJECT ${sources})
|
||||
set_property(TARGET objects PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
if (MSVC)
|
||||
# Suppress linker warnings caused by #ifdef omission
|
||||
# of file content.
|
||||
set( CMAKE_STATIC_LINKER_FLAGS /ignore:4221 )
|
||||
if (BUILD_SHARED)
|
||||
add_library (libzmq SHARED ${sources} ${public_headers} ${html-docs} ${readme-docs} ${CMAKE_CURRENT_BINARY_DIR}/NSIS.template.in)
|
||||
add_library (libzmq SHARED $<TARGET_OBJECTS:objects> ${public_headers} ${html-docs} ${readme-docs} ${CMAKE_CURRENT_BINARY_DIR}/NSIS.template.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
|
||||
target_link_libraries (libzmq ${OPTIONAL_LIBRARIES})
|
||||
set_target_properties (libzmq PROPERTIES
|
||||
PUBLIC_HEADER "${public_headers}"
|
||||
@ -769,7 +768,7 @@ if (MSVC)
|
||||
endif()
|
||||
|
||||
if (BUILD_STATIC)
|
||||
add_library (libzmq-static STATIC ${sources})
|
||||
add_library (libzmq-static STATIC $<TARGET_OBJECTS:objects> ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
|
||||
set_target_properties (libzmq-static PROPERTIES
|
||||
PUBLIC_HEADER "${public_headers}"
|
||||
RELEASE_POSTFIX "${MSVC_TOOLSET}-mt-s-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
|
||||
@ -780,7 +779,7 @@ if (MSVC)
|
||||
endif()
|
||||
else ()
|
||||
if (BUILD_SHARED)
|
||||
add_library (libzmq SHARED ${sources} ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig})
|
||||
add_library (libzmq SHARED $<TARGET_OBJECTS:objects> ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig} ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
|
||||
target_link_libraries (libzmq ${OPTIONAL_LIBRARIES})
|
||||
# NOTE: the SOVERSION MUST be the same as the one generated by libtool!
|
||||
set_target_properties (libzmq PROPERTIES
|
||||
@ -806,7 +805,7 @@ else ()
|
||||
endif()
|
||||
|
||||
if (BUILD_STATIC)
|
||||
add_library (libzmq-static STATIC ${sources} ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig})
|
||||
add_library (libzmq-static STATIC $<TARGET_OBJECTS:objects> ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig} ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
|
||||
set_target_properties (libzmq-static PROPERTIES
|
||||
PUBLIC_HEADER "${public_headers}"
|
||||
COMPILE_DEFINITIONS "ZMQ_STATIC"
|
||||
@ -815,7 +814,7 @@ else ()
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
foreach (target ${target_outputs})
|
||||
foreach (target ${target_outputs} objects)
|
||||
target_include_directories (${target}
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
|
@ -145,8 +145,12 @@ if(WIN32)
|
||||
endif()
|
||||
|
||||
# add library and include dirs for all targets
|
||||
link_libraries(libzmq ${OPTIONAL_LIBRARIES})
|
||||
include_directories("${CMAKE_SOURCE_DIR}/../include")
|
||||
if (BUILD_SHARED)
|
||||
link_libraries(libzmq ${OPTIONAL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
|
||||
else ()
|
||||
link_libraries(libzmq-static ${OPTIONAL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif ()
|
||||
include_directories("${CMAKE_SOURCE_DIR}/../include" "${CMAKE_BINARY_DIR}")
|
||||
|
||||
foreach(test ${tests})
|
||||
# target_sources not supported before CMake 3.1
|
||||
|
Loading…
x
Reference in New Issue
Block a user