diff --git a/examples/parallel/cpp/CMakeLists.txt b/examples/parallel/cpp/CMakeLists.txt index 16fc59945..17bee87b0 100644 --- a/examples/parallel/cpp/CMakeLists.txt +++ b/examples/parallel/cpp/CMakeLists.txt @@ -50,7 +50,7 @@ find_library(SR_LIB ${SMARTREDIS_LIB} ${SMARTREDIS_LINK_MODE} ) -# Extras for static builds +# Select libraries for build if (STATIC_BUILD) # Static builds have an extra dependency on the Pthreads library find_package(Threads REQUIRED) diff --git a/examples/parallel/fortran/CMakeLists.txt b/examples/parallel/fortran/CMakeLists.txt index 8501cf420..26706dbbe 100644 --- a/examples/parallel/fortran/CMakeLists.txt +++ b/examples/parallel/fortran/CMakeLists.txt @@ -69,7 +69,7 @@ set_target_properties(smartredis-fortran PROPERTIES IMPORTED_LOCATION ${SR_FTN_LIB} ) -# Extras for static builds +# Select libraries for build if (STATIC_BUILD) # The CMake "preferred" approach only seems to work with the GNU # compiler. We will streamline this in the future diff --git a/examples/serial/c/CMakeLists.txt b/examples/serial/c/CMakeLists.txt index 26aa71946..116f5355a 100644 --- a/examples/serial/c/CMakeLists.txt +++ b/examples/serial/c/CMakeLists.txt @@ -55,7 +55,7 @@ set_target_properties(smartredis-main PROPERTIES IMPORTED_LOCATION ${SR_LIB} ) -# Extras for static builds +# Select libraries for build if (STATIC_BUILD) # Mark that SmartRedis requires the C++ linker set_target_properties(smartredis-main PROPERTIES diff --git a/examples/serial/cpp/CMakeLists.txt b/examples/serial/cpp/CMakeLists.txt index ed62d3fb4..b0c8f46c1 100644 --- a/examples/serial/cpp/CMakeLists.txt +++ b/examples/serial/cpp/CMakeLists.txt @@ -50,7 +50,7 @@ find_library(SR_LIB ${SMARTREDIS_LIB} ${SMARTREDIS_LINK_MODE} ) -# Extras for static builds +# Select libraries for build if (STATIC_BUILD) # Static builds have an extra dependency on the Pthreads library find_package(Threads REQUIRED) diff --git a/examples/serial/fortran/CMakeLists.txt b/examples/serial/fortran/CMakeLists.txt index 1b079f280..5ffece669 100644 --- a/examples/serial/fortran/CMakeLists.txt +++ b/examples/serial/fortran/CMakeLists.txt @@ -66,7 +66,7 @@ set_target_properties(smartredis-fortran PROPERTIES IMPORTED_LOCATION ${SR_FTN_LIB} ) -# Extras for static builds +# Select libraries for build if (STATIC_BUILD) # The CMake "preferred" approach only seems to work with the GNU # compiler. We will streamline this in the future diff --git a/tests/c/CMakeLists.txt b/tests/c/CMakeLists.txt index 0491543e6..dc5b6de29 100644 --- a/tests/c/CMakeLists.txt +++ b/tests/c/CMakeLists.txt @@ -44,11 +44,36 @@ if(NOT DEFINED SMARTREDIS_INSTALL_PATH) endif() # Locate dependencies +add_library(smartredis-main ${SMARTREDIS_LINK_MODE} IMPORTED) find_library(SR_LIB ${SMARTREDIS_LIB} PATHS ${SMARTREDIS_INSTALL_PATH}/lib NO_DEFAULT_PATH REQUIRED ${SMARTREDIS_LINK_MODE} ) +set_target_properties(smartredis-main PROPERTIES + IMPORTED_LOCATION ${SR_LIB} +) + +# Select libraries for build +if (STATIC_BUILD) + # Mark that SmartRedis requires the C++ linker + set_target_properties(smartredis-main PROPERTIES + IMPORTED_LOCATION ${SR_LIB} + IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" + ) + + # Static builds have an extra dependency on the Pthreads library + find_package(Threads REQUIRED) + set(SMARTREDIS_LIBRARIES + smartredis-main + Threads::Threads + ) +else() + # Shared builds only need the SmartRedis library + set(SMARTREDIS_LIBRARIES + smartredis-main + ) +endif() # Define include directories for header files include_directories(SYSTEM @@ -76,6 +101,6 @@ foreach(EXECUTABLE ${EXECUTABLES}) OUTPUT_NAME ${EXECUTABLE} ) target_link_libraries(${EXECUTABLE}_c_test - ${SR_LIB} + ${SMARTREDIS_LIBRARIES} ) endforeach() diff --git a/tests/cpp/CMakeLists.txt b/tests/cpp/CMakeLists.txt index b10954bff..590ecb832 100644 --- a/tests/cpp/CMakeLists.txt +++ b/tests/cpp/CMakeLists.txt @@ -53,14 +53,25 @@ find_library(SR_LIB ${SMARTREDIS_LIB} ${SMARTREDIS_LINK_MODE} ) +# Select libraries for build +if (STATIC_BUILD) + # Static builds have an extra dependency on the Pthreads library + find_package(Threads REQUIRED) + set(SMARTREDIS_LIBRARIES + ${SR_LIB} + Threads::Threads + ) +else() + # Shared builds only need the SmartRedis library + set(SMARTREDIS_LIBRARIES ${SR_LIB}) +endif() + # Define include directories for header files include_directories(SYSTEM /usr/local/include ${SMARTREDIS_INSTALL_PATH}/include ) - - # Define all the tests to be built list(APPEND EXECUTABLES client_test_dataset @@ -97,6 +108,6 @@ foreach(EXECUTABLE ${EXECUTABLES}) OUTPUT_NAME ${EXECUTABLE} ) target_link_libraries(${EXECUTABLE}_cpp_test - ${SR_LIB} + ${SMARTREDIS_LIBRARIES} ) endforeach() diff --git a/tests/cpp/unit-tests/CMakeLists.txt b/tests/cpp/unit-tests/CMakeLists.txt index d0e5ab8c7..516dd50bc 100644 --- a/tests/cpp/unit-tests/CMakeLists.txt +++ b/tests/cpp/unit-tests/CMakeLists.txt @@ -47,9 +47,9 @@ endif() # Locate dependencies find_library(SR_LIB ${SMARTREDIS_LIB} - PATHS ${SMARTREDIS_INSTALL_PATH}/lib NO_DEFAULT_PATH - REQUIRED - ${SMARTREDIS_LINK_MODE} + PATHS ${SMARTREDIS_INSTALL_PATH}/lib NO_DEFAULT_PATH + REQUIRED + ${SMARTREDIS_LINK_MODE} ) find_package(Threads REQUIRED) @@ -57,7 +57,7 @@ find_package(Threads REQUIRED) include_directories(SYSTEM /usr/local/include ${SMARTREDIS_INSTALL_PATH}/include - ) +) # Identify source files to be built into the CPP Catch2 unit tests file(GLOB UNIT_TESTS CONFIGURE_DEPENDS ./*.cpp) diff --git a/tests/fortran/CMakeLists.txt b/tests/fortran/CMakeLists.txt index 40eca9dc3..9c4709dba 100644 --- a/tests/fortran/CMakeLists.txt +++ b/tests/fortran/CMakeLists.txt @@ -44,21 +44,62 @@ 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 REQUIRED ${SMARTREDIS_LINK_MODE} ) +set_target_properties(smartredis-main PROPERTIES + IMPORTED_LOCATION ${SR_LIB} +) +# . 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(SMARTREDIS_LIBRARIES - ${SR_LIB} - ${SR_FTN_LIB} +set_target_properties(smartredis-fortran PROPERTIES + IMPORTED_LOCATION ${SR_FTN_LIB} ) +# Select libraries for build +if (STATIC_BUILD) + # 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" + ) + 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 + smartredis-main + Threads::Threads + ) +else() + # Shared builds only need the SmartRedis libraries + set(SMARTREDIS_LIBRARIES + smartredis-fortran + smartredis-main + ) +endif() + # Define include directories for header files include_directories(SYSTEM /usr/local/include