Skip to content

Commit

Permalink
Extend static build support to unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
billschereriii committed Jul 27, 2023
1 parent 029d69f commit ea2cc40
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 18 deletions.
2 changes: 1 addition & 1 deletion examples/parallel/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/parallel/fortran/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/serial/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/serial/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/serial/fortran/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 26 additions & 1 deletion tests/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -76,6 +101,6 @@ foreach(EXECUTABLE ${EXECUTABLES})
OUTPUT_NAME ${EXECUTABLE}
)
target_link_libraries(${EXECUTABLE}_c_test
${SR_LIB}
${SMARTREDIS_LIBRARIES}
)
endforeach()
17 changes: 14 additions & 3 deletions tests/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -97,6 +108,6 @@ foreach(EXECUTABLE ${EXECUTABLES})
OUTPUT_NAME ${EXECUTABLE}
)
target_link_libraries(${EXECUTABLE}_cpp_test
${SR_LIB}
${SMARTREDIS_LIBRARIES}
)
endforeach()
8 changes: 4 additions & 4 deletions tests/cpp/unit-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ 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)

# Define include directories for header files
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)
Expand Down
51 changes: 46 additions & 5 deletions tests/fortran/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ea2cc40

Please sign in to comment.