Skip to content

Commit

Permalink
Problem: mingw static/shared builds have different preprocessor defines
Browse files Browse the repository at this point in the history
Solution: remove objects optimisation in library build (similar to #2860)
and set PUBLIC compile definitions on all static builds instead of MSVC
only.
  • Loading branch information
tonytheodore committed Mar 12, 2018
1 parent 794d7a3 commit c7876c0
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -911,20 +911,27 @@ if (MSVC)
DEBUG_POSTFIX "${MSVC_TOOLSET}-mt-sgd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}"
COMPILE_FLAGS "/DZMQ_STATIC"
OUTPUT_NAME "libzmq")

target_compile_definitions(libzmq-static
PUBLIC ZMQ_STATIC
)

endif()
else ()
# avoid building everything twice for shared + static
# only on *nix, as Windows needs different preprocessor defines in static builds
add_library (objects OBJECT ${sources})
set_property(TARGET objects PROPERTY POSITION_INDEPENDENT_CODE ON)
if (NOT MINGW)
add_library (objects OBJECT ${sources})
set_property(TARGET objects PROPERTY POSITION_INDEPENDENT_CODE ON)
target_include_directories (objects
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>
)
endif ()

if (BUILD_SHARED)
add_library (libzmq SHARED $<TARGET_OBJECTS:objects> ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig} ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
if (MINGW)
add_library (libzmq SHARED ${sources} ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig} ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
else ()
add_library (libzmq SHARED $<TARGET_OBJECTS:objects> ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig} ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
endif ()
# NOTE: the SOVERSION and VERSION MUST be the same as the one generated by libtool! It is NOT the same as the version of the package.
set_target_properties (libzmq PROPERTIES
COMPILE_DEFINITIONS "DLL_EXPORT"
Expand All @@ -949,19 +956,22 @@ else ()
endif()

if (BUILD_STATIC)
add_library (libzmq-static STATIC $<TARGET_OBJECTS:objects> ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig} ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
if (MINGW)
add_library (libzmq-static STATIC ${sources} ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig} ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
else ()
add_library (libzmq-static STATIC $<TARGET_OBJECTS:objects> ${public_headers} ${html-docs} ${readme-docs} ${zmq-pkgconfig} ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
endif ()
set_target_properties (libzmq-static PROPERTIES
PUBLIC_HEADER "${public_headers}"
COMPILE_DEFINITIONS "ZMQ_STATIC"
OUTPUT_NAME "zmq"
PREFIX "lib")
endif()

target_include_directories (objects
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>
endif ()

if (BUILD_STATIC)
target_compile_definitions(libzmq-static
PUBLIC ZMQ_STATIC
)
endif ()

Expand Down

0 comments on commit c7876c0

Please sign in to comment.