diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e8917575..b4700300f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,6 +139,7 @@ if (STATIC_BUILD) target_link_libraries(smartredis PUBLIC ${EXT_CLIENT_LIBRARIES} PRIVATE Threads::Threads) # Merge SmartRedis static library with dependencies + # . Create a sacrificial dummy file so we have source to make a target against set(DUMMY_FILE ${CMAKE_BINARY_DIR}/merge-dummy.cpp) file( WRITE ${DUMMY_FILE} @@ -146,6 +147,8 @@ if (STATIC_BUILD) ) add_library(${SMARTREDIS_LIB} STATIC ${DUMMY_FILE}) set(STATIC_LIB_COMPONENTS ${SR_LIB_INSTALL_PATH}/${TEMP_LIB_FULLNAME} ${EXT_CLIENT_LIBRARIES}) + + # . Archive the static libraries together into a thin library add_custom_command( TARGET smartredis POST_BUILD @@ -157,8 +160,7 @@ if (STATIC_BUILD) # Install static library install(TARGETS ${SMARTREDIS_LIB} LIBRARY DESTINATION lib) - -else () +else () # Shared library build add_library(smartredis ${SMARTREDIS_LINK_MODE} ${CLIENT_SRC}) set_target_properties(smartredis PROPERTIES SUFFIX ${SMARTREDIS_LINK_LIBRARY_SUFFIX} diff --git a/doc/changelog.rst b/doc/changelog.rst index 334d8ef44..b4a34d4e3 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -8,6 +8,7 @@ To be released at some future point in time Description +- Enable static builds of SmartRedis - Improve robustness of test runs - Fix installation link - Update supported languages documentation @@ -17,6 +18,7 @@ Description Detailed Notes +- Static builds of SmartRedis can now work with Linux platforms. Fortran is only tested with GNU and Intel compilers (PR386_) - Preserve the shell output of test runs while making sure that server shutdown happens unconditionally (PR381_) - Fix incorrect link to installation documentation (PR380_) - Update language support matrix in documentation to reflect updates from the last release (PR379_) @@ -25,6 +27,7 @@ Detailed Notes - Deleted obsolete build and testing files that are no longer needed with the new build and test system (PR366_) - Reuse existing redis connection when mapping the Redis cluster (PR364_) +.. _PR386: https://github.com/CrayLabs/SmartRedis/pull/386 .. _PR381: https://github.com/CrayLabs/SmartRedis/pull/381 .. _PR380: https://github.com/CrayLabs/SmartRedis/pull/380 .. _PR379: https://github.com/CrayLabs/SmartRedis/pull/379 diff --git a/examples/parallel/fortran/CMakeLists.txt b/examples/parallel/fortran/CMakeLists.txt index 1c7e561cc..8501cf420 100644 --- a/examples/parallel/fortran/CMakeLists.txt +++ b/examples/parallel/fortran/CMakeLists.txt @@ -71,12 +71,9 @@ set_target_properties(smartredis-fortran PROPERTIES # Extras for static builds if (STATIC_BUILD) - if (CMAKE_Fortran_COMPILER_ID MATCHES "^Intel") - # For Intel, don't set languages so that CMake will use the Fortran linker (default) - - # Add the stdc++ linker flag - set(CMAKE_EXE_LINKER_FLAGS "-lstdc++ ${CMAKE_EXE_LINKER_FLAGS}") - else() # Solution tested with GNU + # The CMake "preferred" approach only seems to work with the GNU + # compiler. We will streamline this in the future + if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") # Mark that SmartRedis requires the C++ linker set_target_properties(smartredis-main PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" @@ -84,9 +81,15 @@ if (STATIC_BUILD) set_target_properties(smartredis-fortran PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "FORTRAN" ) + else() # Tested with PGI, Intel + # For other compilers, don't set languages so that CMake will use the Fortran linker (default) + + # Add the stdc++ linker flag + set(CMAKE_EXE_LINKER_FLAGS "-lstdc++ ${CMAKE_EXE_LINKER_FLAGS}") endif() # Static builds have an extra dependency on the Pthreads library + # The order of libraries here is crucial to get dependencies covered find_package(Threads REQUIRED) set(SMARTREDIS_LIBRARIES smartredis-fortran diff --git a/examples/serial/fortran/CMakeLists.txt b/examples/serial/fortran/CMakeLists.txt index 11ee75f37..1b079f280 100644 --- a/examples/serial/fortran/CMakeLists.txt +++ b/examples/serial/fortran/CMakeLists.txt @@ -45,6 +45,7 @@ if(NOT DEFINED SMARTREDIS_INSTALL_PATH) endif() # Locate dependencies +# . Main SmartRedis Library (C++ based) add_library(smartredis-main ${SMARTREDIS_LINK_MODE} IMPORTED) find_library(SR_LIB ${SMARTREDIS_LIB} PATHS ${SMARTREDIS_INSTALL_PATH}/lib NO_DEFAULT_PATH @@ -54,15 +55,11 @@ find_library(SR_LIB ${SMARTREDIS_LIB} set_target_properties(smartredis-main PROPERTIES IMPORTED_LOCATION ${SR_LIB} ) -#find_library(SR_LIB ${SMARTREDIS_LIB} -# PATHS ${SMARTREDIS_INSTALL_PATH}/lib NO_DEFAULT_PATH -# REQUIRED -# ${SMARTREDIS_LINK_MODE} -#) +# . SmartRedis Fortran Library (C++ based) add_library(smartredis-fortran ${SMARTREDIS_LINK_MODE} IMPORTED) find_library(SR_FTN_LIB ${SMARTREDIS_FORTRAN_LIB} - PATHS ${SMARTREDIS_INSTALL_PATH}/lib NO_DEFAULT_PATH - REQUIRED + PATHS ${SMARTREDIS_INSTALL_PATH}/lib NO_DEFAULT_PATH + REQUIRED ${SMARTREDIS_LINK_MODE} ) set_target_properties(smartredis-fortran PROPERTIES @@ -71,12 +68,9 @@ set_target_properties(smartredis-fortran PROPERTIES # Extras for static builds if (STATIC_BUILD) - if (CMAKE_Fortran_COMPILER_ID MATCHES "^Intel") - # For Intel, don't set languages so that CMake will use the Fortran linker (default) - - # Add the stdc++ linker flag - set(CMAKE_EXE_LINKER_FLAGS "-lstdc++ ${CMAKE_EXE_LINKER_FLAGS}") - else() # Solution tested with GNU + # The CMake "preferred" approach only seems to work with the GNU + # compiler. We will streamline this in the future + if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") # Mark that SmartRedis requires the C++ linker set_target_properties(smartredis-main PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" @@ -84,9 +78,15 @@ if (STATIC_BUILD) set_target_properties(smartredis-fortran PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "FORTRAN" ) + else() # Tested with PGI, Intel + # For other compilers, don't set languages so that CMake will use the Fortran linker (default) + + # Add the stdc++ linker flag + set(CMAKE_EXE_LINKER_FLAGS "-lstdc++ ${CMAKE_EXE_LINKER_FLAGS}") endif() # Static builds have an extra dependency on the Pthreads library + # The order of libraries here is crucial to get dependencies covered find_package(Threads REQUIRED) set(SMARTREDIS_LIBRARIES smartredis-fortran diff --git a/smartredis_defs.cmake b/smartredis_defs.cmake index 6472ea84e..3825db814 100644 --- a/smartredis_defs.cmake +++ b/smartredis_defs.cmake @@ -64,9 +64,9 @@ if(srlink_lowercase STREQUAL "static") set(SMARTREDIS_LINK_SUFFIX "-static") set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(STATIC_BUILD TRUE) -# if(APPLE) -# message(FATAL_ERROR "Static builds are not supported on MacOS") -# endif(APPLE) + if(APPLE) + message(FATAL_ERROR "Static builds are not supported on MacOS") + endif(APPLE) elseif(srlink_lowercase STREQUAL "shared") set(SMARTREDIS_LINK_MODE SHARED) set(SMARTREDIS_LINK_LIBRARY_SUFFIX .so)