Unverified Commit 9f83a598 authored by Jim Klimov's avatar Jim Klimov Committed by GitHub

Merge pull request #2844 from bluca/cmake_double_build

Problems: CMake rebuilds everything twice, warnings with Tweetnacl, no autoconf option to disable Werror
parents b3bf5171 574d72b0
...@@ -86,8 +86,8 @@ matrix: ...@@ -86,8 +86,8 @@ matrix:
sudo: required sudo: required
before_install: before_install:
- if [ $TRAVIS_OS_NAME == "osx" -a $BUILD_TYPE == "android" ] ; then brew install binutils ; fi - if [ $TRAVIS_OS_NAME == "osx" -a $BUILD_TYPE == "android" ] ; then brew update; brew install binutils ; fi
- if [ $TRAVIS_OS_NAME == "osx" -a $CURVE == "libsodium" ] ; then brew install libsodium ; fi - if [ $TRAVIS_OS_NAME == "osx" -a $CURVE == "libsodium" ] ; then brew update; brew install libsodium ; fi
before_script: before_script:
# ZMQ stress tests need more open socket (files) than the usual default # ZMQ stress tests need more open socket (files) than the usual default
......
...@@ -575,8 +575,6 @@ set (cxx-sources ...@@ -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}) ...@@ -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) ...@@ -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) ...@@ -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) ...@@ -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 () ...@@ -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 () ...@@ -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>
......
...@@ -79,6 +79,9 @@ ...@@ -79,6 +79,9 @@
* Add new autoconf --disable-libunwind option to stop building with libunwind * Add new autoconf --disable-libunwind option to stop building with libunwind
even if it is available. even if it is available.
* Add new autoconf --disable-Werror option to avoid building with the Werror
flag.
* Use pkg-config as the first method for finding and building with external * Use pkg-config as the first method for finding and building with external
optional dependencies such as libnorm, libpgm and gssapi. optional dependencies such as libnorm, libpgm and gssapi.
......
...@@ -144,8 +144,11 @@ else ...@@ -144,8 +144,11 @@ else
AC_MSG_RESULT([no]) AC_MSG_RESULT([no])
fi fi
# By default compiling with -Werror except OSX. # By default compiling with -Werror except OSX and on Solaris when building
libzmq_werror="yes" # with libsodium.
AC_ARG_ENABLE([Werror],
[AS_HELP_STRING([--disable-Werror], [disable Werror compiler flag [default=enabled]])],
[libzmq_werror=$enableval], [libzmq_werror=yes])
# By default use DSO visibility # By default use DSO visibility
libzmq_dso_visibility="yes" libzmq_dso_visibility="yes"
......
...@@ -145,8 +145,12 @@ if(WIN32) ...@@ -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
...@@ -195,7 +199,8 @@ if(ZMQ_HAVE_CURVE) ...@@ -195,7 +199,8 @@ if(ZMQ_HAVE_CURVE)
endif() endif()
#add additional required flags #add additional required flags
if(ZMQ_HAVE_CURVE) #ZMQ_USE_TWEETNACL will already be defined when not using sodium
if(ZMQ_HAVE_CURVE AND NOT ZMQ_USE_TWEETNACL)
target_compile_definitions(test_security_curve PRIVATE "-DZMQ_USE_TWEETNACL") target_compile_definitions(test_security_curve PRIVATE "-DZMQ_USE_TWEETNACL")
endif() endif()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment