diff options
author | Gereon Kremer <nafur42@gmail.com> | 2021-10-07 03:59:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-07 10:59:50 +0000 |
commit | 8773b8921d705d458b90566cb41e97ee596aeeb1 (patch) | |
tree | fed670f246a4d3619ba73065de7fb76a815cb65b /cmake | |
parent | 65431e88f8e0c48c90bc540b95c63b67d8387219 (diff) |
Fix/Improve static and shared builds with CLN or Poly (#7306)
We already created two dependency targets `GMP_SHARED` and `GMP_STATIC`, as we could not use `libgmp.a` for shared linking (as it is built without `-fPIC`). This PR fixes our handling of CLN and Poly: they would always link with `GMP_STATIC`, leading to having both `GMP_SHARED` and `GMP_STATIC` in the linker command line in certain situations. We now also have `*_SHARED` and `*_STATIC` for both CLN and Poly.
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/FindCLN.cmake | 34 | ||||
-rw-r--r-- | cmake/FindPoly.cmake | 72 |
2 files changed, 80 insertions, 26 deletions
diff --git a/cmake/FindCLN.cmake b/cmake/FindCLN.cmake index f2a6d853e..11bf8ed98 100644 --- a/cmake/FindCLN.cmake +++ b/cmake/FindCLN.cmake @@ -33,6 +33,15 @@ if(CLN_INCLUDE_DIR AND CLN_LIBRARIES) check_system_version("CLN") endif() +if(ENABLE_STATIC_LIBRARY AND CLN_FOUND_SYSTEM) + force_static_library() + find_library(CLN_STATIC_LIBRARIES NAMES cln) + if(NOT CLN_STATIC_LIBRARIES) + set(CLN_FOUND_SYSTEM FALSE) + endif() + reset_force_static_library() +endif() + if(NOT CLN_FOUND_SYSTEM) check_ep_downloaded("CLN-EP") if(NOT CLN-EP_DOWNLOADED) @@ -62,28 +71,36 @@ if(NOT CLN_FOUND_SYSTEM) ${CMAKE_COMMAND} -E chdir <SOURCE_DIR> ./autogen.sh COMMAND ${CMAKE_COMMAND} -E chdir <SOURCE_DIR> autoreconf -iv - COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR> --disable-shared + COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR> --enable-shared --enable-static --with-pic BUILD_BYPRODUCTS <INSTALL_DIR>/lib/libcln.a + <INSTALL_DIR>/lib/libcln${CMAKE_SHARED_LIBRARY_SUFFIX} ) add_dependencies(CLN-EP GMP_SHARED) set(CLN_INCLUDE_DIR "${DEPS_BASE}/include/") - set(CLN_LIBRARIES "${DEPS_BASE}/lib/libcln.a") + set(CLN_LIBRARIES "${DEPS_BASE}/lib/libcln${CMAKE_SHARED_LIBRARY_SUFFIX}") + set(CLN_STATIC_LIBRARIES "${DEPS_BASE}/lib/libcln.a") endif() set(CLN_FOUND TRUE) -add_library(CLN STATIC IMPORTED GLOBAL) -set_target_properties(CLN PROPERTIES +add_library(CLN_SHARED SHARED IMPORTED GLOBAL) +set_target_properties(CLN_SHARED PROPERTIES IMPORTED_LOCATION "${CLN_LIBRARIES}" INTERFACE_INCLUDE_DIRECTORIES "${CLN_INCLUDE_DIR}" ) +target_link_libraries(CLN_SHARED INTERFACE GMP_SHARED) + + if(ENABLE_STATIC_LIBRARY) - target_link_libraries(CLN INTERFACE GMP_STATIC) -else() - target_link_libraries(CLN INTERFACE GMP_SHARED) + add_library(CLN_STATIC STATIC IMPORTED GLOBAL) + set_target_properties(CLN_STATIC PROPERTIES + IMPORTED_LOCATION "${CLN_STATIC_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES "${CLN_INCLUDE_DIR}" + ) + target_link_libraries(CLN_STATIC INTERFACE GMP_STATIC) endif() mark_as_advanced(AUTORECONF) @@ -96,5 +113,6 @@ if(CLN_FOUND_SYSTEM) message(STATUS "Found CLN ${CLN_VERSION}: ${CLN_LIBRARIES}") else() message(STATUS "Building CLN ${CLN_VERSION}: ${CLN_LIBRARIES}") - add_dependencies(CLN CLN-EP) + add_dependencies(CLN_SHARED CLN-EP) + add_dependencies(CLN_STATIC CLN-EP) endif() diff --git a/cmake/FindPoly.cmake b/cmake/FindPoly.cmake index 6ddb918a9..ae236c6d9 100644 --- a/cmake/FindPoly.cmake +++ b/cmake/FindPoly.cmake @@ -37,6 +37,16 @@ if(Poly_INCLUDE_DIR check_system_version("Poly") endif() +if(ENABLE_STATIC_LIBRARY AND Poly_FOUND_SYSTEM) + force_static_library() + find_library(Poly_STATIC_LIBRARIES NAMES poly) + find_library(PolyXX_STATIC_LIBRARIES NAMES polyxx) + if(NOT Poly_STATIC_LIBRARIES OR NOT PolyXX_STATIC_LIBRARIES) + set(Poly_FOUND_SYSTEM FALSE) + endif() + reset_force_static_library() +endif() + if(NOT Poly_FOUND_SYSTEM) check_ep_downloaded("Poly-EP") if(NOT Poly-EP_DOWNLOADED) @@ -95,6 +105,8 @@ if(NOT Poly_FOUND_SYSTEM) <INSTALL_DIR>/lib/libpicpolyxx.a BUILD_BYPRODUCTS <INSTALL_DIR>/lib/libpicpoly.a <INSTALL_DIR>/lib/libpicpolyxx.a + <INSTALL_DIR>/lib/libpoly${CMAKE_SHARED_LIBRARY_SUFFIX} + <INSTALL_DIR>/lib/libpolyxx${CMAKE_SHARED_LIBRARY_SUFFIX} ) ExternalProject_Add_Step( Poly-EP cleanup @@ -104,29 +116,43 @@ if(NOT Poly_FOUND_SYSTEM) add_dependencies(Poly-EP GMP_SHARED) set(Poly_INCLUDE_DIR "${DEPS_BASE}/include/") - set(Poly_LIBRARIES "${DEPS_BASE}/lib/libpicpoly.a") - set(PolyXX_LIBRARIES "${DEPS_BASE}/lib/libpicpolyxx.a") + set(Poly_LIBRARIES "${DEPS_BASE}/lib/libpoly${CMAKE_SHARED_LIBRARY_SUFFIX}") + set(PolyXX_LIBRARIES "${DEPS_BASE}/lib/libpolyxx${CMAKE_SHARED_LIBRARY_SUFFIX}") + set(Poly_STATIC_LIBRARIES "${DEPS_BASE}/lib/libpicpoly.a") + set(PolyXX_STATIC_LIBRARIES "${DEPS_BASE}/lib/libpicpolyxx.a") endif() set(Poly_FOUND TRUE) -add_library(Poly STATIC IMPORTED GLOBAL) -set_target_properties(Poly PROPERTIES IMPORTED_LOCATION "${Poly_LIBRARIES}") -set_target_properties( - Poly PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${Poly_INCLUDE_DIR}" +add_library(Poly_SHARED SHARED IMPORTED GLOBAL) +set_target_properties(Poly_SHARED PROPERTIES + IMPORTED_LOCATION "${Poly_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES "${Poly_INCLUDE_DIR}" ) -if(ENABLE_STATIC_LIBRARY) - target_link_libraries(Poly INTERFACE GMP_STATIC) -else() - target_link_libraries(Poly INTERFACE GMP_SHARED) -endif() +target_link_libraries(Poly_SHARED INTERFACE GMP_SHARED) -add_library(Polyxx STATIC IMPORTED GLOBAL) -set_target_properties(Polyxx PROPERTIES IMPORTED_LOCATION "${PolyXX_LIBRARIES}") -set_target_properties( - Polyxx PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${Poly_INCLUDE_DIR}" +add_library(Polyxx_SHARED SHARED IMPORTED GLOBAL) +set_target_properties(Polyxx_SHARED PROPERTIES + IMPORTED_LOCATION "${PolyXX_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES "${Poly_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES Poly_SHARED ) -set_target_properties(Polyxx PROPERTIES INTERFACE_LINK_LIBRARIES Poly) + +if(ENABLE_STATIC_LIBRARY) + add_library(Poly_STATIC STATIC IMPORTED GLOBAL) + set_target_properties(Poly_STATIC PROPERTIES + IMPORTED_LOCATION "${Poly_STATIC_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES "${Poly_INCLUDE_DIR}" + ) + target_link_libraries(Poly_STATIC INTERFACE GMP_STATIC) + + add_library(Polyxx_STATIC STATIC IMPORTED GLOBAL) + set_target_properties(Polyxx_STATIC PROPERTIES + IMPORTED_LOCATION "${PolyXX_STATIC_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES "${Poly_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES Poly_STATIC + ) +endif() mark_as_advanced(Poly_FOUND) mark_as_advanced(Poly_FOUND_SYSTEM) @@ -138,6 +164,16 @@ if(Poly_FOUND_SYSTEM) message(STATUS "Found Poly ${Poly_VERSION}: ${Poly_LIBRARIES}") else() message(STATUS "Building Poly ${Poly_VERSION}: ${Poly_LIBRARIES}") - add_dependencies(Poly Poly-EP) - add_dependencies(Polyxx Poly-EP) + add_dependencies(Poly_SHARED Poly-EP) + add_dependencies(Polyxx_SHARED Poly-EP) + + install(FILES + $<TARGET_SONAME_FILE:Poly_SHARED> $<TARGET_SONAME_FILE:Polyxx_SHARED> + DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) + + if(ENABLE_STATIC_LIBRARY) + add_dependencies(Poly_STATIC Poly-EP) + add_dependencies(Polyxx_STATIC Poly-EP) + endif() endif() |