From 3e72d97ca7d9fa4d130833d84108d08b92e97467 Mon Sep 17 00:00:00 2001 From: warptangent Date: Fri, 12 Feb 2016 11:32:37 -0800 Subject: [PATCH 1/4] cmake: Fix overly broad use of dynamic link settings Remove LINK_SEARCH_START_STATIC and LINK_SEARCH_END_STATIC. This is more appropriate when the compiler flag -static is used. This had been causing CMake to omit the linker flags necesssary to distinguish static and dynamic library linking. CMake had assumed static linking for the target, causing it to omit explicit static link flags. That is problematic without the -static compile flag being set. With a library located in system directories, like libboost_date_time, the full static path (.a), though found correctly by CMake, was treated by the linker as a dynamic library. This is because target_link_libraries() transforms the full path to -l if it's in a system directory. Without -static or explicit linker flags, the dynamic library (.so) is linked. Removing the above two properties removes the assumption of static. So -Wl;-Bstatic is inserted where needed. This causes -l to properly refer to the static library instead of dynamic. --- src/CMakeLists.txt | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 036908f3..0ac4a0aa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -63,15 +63,6 @@ function (bitmonero_add_executable name) set_property(TARGET "${name}" PROPERTY RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") - - if (STATIC) - set_property(TARGET "${name}" - PROPERTY - LINK_SEARCH_START_STATIC 1) - set_property(TARGET "${name}" - PROPERTY - LINK_SEARCH_END_STATIC 1) - endif () endfunction () function (bitmonero_add_library name) From 7205210b0f6c3648361a9a0b2c17f1b6e7163ad9 Mon Sep 17 00:00:00 2001 From: warptangent Date: Fri, 12 Feb 2016 12:36:55 -0800 Subject: [PATCH 2/4] cmake: Fix unbound config compile settings This allows the OpenSSL function checks to compile in unbound's CMake configuration. Otherwise, the functions SHA256() and EVP_sha512() won't be called from libunbound as possible algorithms. They had not been compiling because static OpenSSL libraries were being used, along with lack of -ldl. The static library preference is unnecessary for the checks, so use default suffixes ordering for CMAKE_FIND_LIBRARY_SUFFIXES when building unbound. Related files: configure_checks.cmake external/unbound/validator/val_secalgo.c secalgo_ds_digest(), setup_key_digest() --- CMakeLists.txt | 2 ++ external/CMakeLists.txt | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ff4f8853..fa3b07a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -177,6 +177,8 @@ if(MINGW) list(REMOVE_ITEM CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES ${DEFLIB}) endif() +set(ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) + if(STATIC) if(MSVC) set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .dll.a .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index d13f67b9..70763caf 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -76,7 +76,11 @@ endif() find_package(Unbound) if(NOT UNBOUND_INCLUDE_DIR OR STATIC) + # We want unbound config tests to be independent of changes made to this setting. + set(CURRENT_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) + set(CMAKE_FIND_LIBRARY_SUFFIXES ${ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) add_subdirectory(unbound) + set(CMAKE_FIND_LIBRARY_SUFFIXES ${CURRENT_CMAKE_FIND_LIBRARY_SUFFIXES}) set(UNBOUND_STATIC true PARENT_SCOPE) set(UNBOUND_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/unbound/libunbound" PARENT_SCOPE) From c2f2437586aec814ba9a85951dd618373eb501f6 Mon Sep 17 00:00:00 2001 From: warptangent Date: Fri, 12 Feb 2016 13:25:39 -0800 Subject: [PATCH 3/4] cmake: Remove unused variable DL is empty and unused elsewhere. The intention at one point may have been to use CMAKE_DL_LIBS, but that would more likely apply in some situations involving static linking. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fa3b07a3..05c747ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -439,7 +439,7 @@ elseif(APPLE OR FREEBSD OR OPENBSD) set(EXTRA_LIBRARIES "") elseif(NOT MSVC) find_library(RT rt) - set(EXTRA_LIBRARIES ${RT} ${DL}) + set(EXTRA_LIBRARIES ${RT}) endif() include(version.cmake) From 9832d18dcaf664750758f5f0afb73097cfdfa9c8 Mon Sep 17 00:00:00 2001 From: warptangent Date: Fri, 12 Feb 2016 16:52:52 -0800 Subject: [PATCH 4/4] cmake: Include OpenSSL libraries in static linking --- CMakeLists.txt | 2 -- external/CMakeLists.txt | 9 +++++---- external/unbound/CMakeLists.txt | 6 ++++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 05c747ae..3e95f48f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -177,8 +177,6 @@ if(MINGW) list(REMOVE_ITEM CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES ${DEFLIB}) endif() -set(ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) - if(STATIC) if(MSVC) set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .dll.a .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 70763caf..33e843e6 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -76,11 +76,12 @@ endif() find_package(Unbound) if(NOT UNBOUND_INCLUDE_DIR OR STATIC) - # We want unbound config tests to be independent of changes made to this setting. - set(CURRENT_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) - set(CMAKE_FIND_LIBRARY_SUFFIXES ${ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) + # NOTE: If STATIC is true, CMAKE_FIND_LIBRARY_SUFFIXES has been reordered. + # unbound has config tests which used OpenSSL libraries, so -ldl may need to + # be set in this case. + # The unbound CMakeLists.txt can set it, since it's also needed for the + # static OpenSSL libraries set up there after with target_link_libraries. add_subdirectory(unbound) - set(CMAKE_FIND_LIBRARY_SUFFIXES ${CURRENT_CMAKE_FIND_LIBRARY_SUFFIXES}) set(UNBOUND_STATIC true PARENT_SCOPE) set(UNBOUND_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/unbound/libunbound" PARENT_SCOPE) diff --git a/external/unbound/CMakeLists.txt b/external/unbound/CMakeLists.txt index 839b21c7..0dd5d6bc 100644 --- a/external/unbound/CMakeLists.txt +++ b/external/unbound/CMakeLists.txt @@ -40,6 +40,12 @@ if (APPLE) endif() find_package(OpenSSL REQUIRED) +if(STATIC) + if(UNIX) + set(OPENSSL_LIBRARIES "${OPENSSL_LIBRARIES};${CMAKE_DL_LIBS}") + endif() +endif() + find_package(Threads) include(configure_checks.cmake)