mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-27 15:41:05 +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
|
gather.cpp
|
||||||
zap_client.cpp)
|
zap_client.cpp)
|
||||||
|
|
||||||
set (rc-sources version.rc)
|
|
||||||
|
|
||||||
if (MINGW)
|
if (MINGW)
|
||||||
# Generate the right type when using -m32 or -m64
|
# Generate the right type when using -m32 or -m64
|
||||||
macro (set_rc_arch rc_target)
|
macro (set_rc_arch rc_target)
|
||||||
@ -643,10 +641,7 @@ foreach (source ${cxx-sources})
|
|||||||
list (APPEND sources ${CMAKE_CURRENT_SOURCE_DIR}/src/${source})
|
list (APPEND sources ${CMAKE_CURRENT_SOURCE_DIR}/src/${source})
|
||||||
endforeach ()
|
endforeach ()
|
||||||
|
|
||||||
foreach (source ${rc-sources})
|
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/src/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
|
||||||
list (APPEND sources ${CMAKE_CURRENT_BINARY_DIR}/${source})
|
|
||||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/src/${source}.in ${CMAKE_CURRENT_BINARY_DIR}/${source})
|
|
||||||
endforeach ()
|
|
||||||
|
|
||||||
# Delete any src/platform.hpp left by configure
|
# Delete any src/platform.hpp left by configure
|
||||||
file (REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/src/platform.hpp)
|
file (REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/src/platform.hpp)
|
||||||
@ -751,12 +746,16 @@ if (BUILD_STATIC)
|
|||||||
list(APPEND target_outputs "libzmq-static")
|
list(APPEND target_outputs "libzmq-static")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# avoid building everything twice for shared + static
|
||||||
|
add_library (objects OBJECT ${sources})
|
||||||
|
set_property(TARGET objects PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
# Suppress linker warnings caused by #ifdef omission
|
# Suppress linker warnings caused by #ifdef omission
|
||||||
# of file content.
|
# of file content.
|
||||||
set( CMAKE_STATIC_LINKER_FLAGS /ignore:4221 )
|
set( CMAKE_STATIC_LINKER_FLAGS /ignore:4221 )
|
||||||
if (BUILD_SHARED)
|
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})
|
target_link_libraries (libzmq ${OPTIONAL_LIBRARIES})
|
||||||
set_target_properties (libzmq PROPERTIES
|
set_target_properties (libzmq PROPERTIES
|
||||||
PUBLIC_HEADER "${public_headers}"
|
PUBLIC_HEADER "${public_headers}"
|
||||||
@ -769,7 +768,7 @@ if (MSVC)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (BUILD_STATIC)
|
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
|
set_target_properties (libzmq-static PROPERTIES
|
||||||
PUBLIC_HEADER "${public_headers}"
|
PUBLIC_HEADER "${public_headers}"
|
||||||
RELEASE_POSTFIX "${MSVC_TOOLSET}-mt-s-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
|
RELEASE_POSTFIX "${MSVC_TOOLSET}-mt-s-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
|
||||||
@ -780,7 +779,7 @@ if (MSVC)
|
|||||||
endif()
|
endif()
|
||||||
else ()
|
else ()
|
||||||
if (BUILD_SHARED)
|
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})
|
target_link_libraries (libzmq ${OPTIONAL_LIBRARIES})
|
||||||
# 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 (libzmq PROPERTIES
|
set_target_properties (libzmq PROPERTIES
|
||||||
@ -806,7 +805,7 @@ else ()
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (BUILD_STATIC)
|
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
|
set_target_properties (libzmq-static PROPERTIES
|
||||||
PUBLIC_HEADER "${public_headers}"
|
PUBLIC_HEADER "${public_headers}"
|
||||||
COMPILE_DEFINITIONS "ZMQ_STATIC"
|
COMPILE_DEFINITIONS "ZMQ_STATIC"
|
||||||
@ -815,7 +814,7 @@ else ()
|
|||||||
endif()
|
endif()
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
foreach (target ${target_outputs})
|
foreach (target ${target_outputs} objects)
|
||||||
target_include_directories (${target}
|
target_include_directories (${target}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
|
@ -145,8 +145,12 @@ if(WIN32)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# add library and include dirs for all targets
|
# add library and include dirs for all targets
|
||||||
link_libraries(libzmq ${OPTIONAL_LIBRARIES})
|
if (BUILD_SHARED)
|
||||||
include_directories("${CMAKE_SOURCE_DIR}/../include")
|
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})
|
foreach(test ${tests})
|
||||||
# target_sources not supported before CMake 3.1
|
# target_sources not supported before CMake 3.1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user