Skip to content

Commit

Permalink
Fight with object files again
Browse files Browse the repository at this point in the history
  • Loading branch information
ashao committed Jun 21, 2024
1 parent 0cbcebf commit e0c9839
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 42 deletions.
21 changes: 11 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_VISIBILITY_PRESET default)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)

if(CMAKE_BUILD_TYPE STREQUAL Coverage)
set(CMAKE_BUILD_TYPE Debug)
Expand All @@ -74,6 +75,12 @@ if (BUILD_FORTRAN)
endif()

## Include external libraries
## Note: These ExternalProjects need to be installed into the
## SmartRedis install directory since there are variants of the
## header files that are chosen based on various configuration
## options. Any extra artifacts should be removed in the
## POST_BUILD step

# Add hiredis as an external project
ExternalProject_Add(hiredis
GIT_REPOSITORY https://github.com/redis/hiredis.git
Expand All @@ -90,16 +97,11 @@ ExternalProject_Add(hiredis
ExternalProject_Get_Property(hiredis source_dir binary_dir)
set(hiredis_source_dir ${source_dir})
set(hiredis_binary_dir ${binary_dir})
file(GLOB hiredis_objs ${binary_dir}/CMakeFiles/hiredis.dir/*.o)

add_library(libhiredis UNKNOWN IMPORTED)
add_dependencies(libhiredis hiredis)

## Note: These ExternalProjects need to be installed into the
## SmartRedis install directory since there are variants of the
## header files that are chosen based on various configuration
## options. Any extra artifacts should be removed in the
## POST_BUILD step

# Set hiredis properties
set_target_properties(libhiredis PROPERTIES
IMPORTED_LOCATION ${hiredis_binary_dir}/libhiredis.a
Expand All @@ -123,6 +125,7 @@ ExternalProject_Add(redis++
ExternalProject_Get_Property(redis++ source_dir binary_dir)
set(redis++_source_dir ${source_dir})
set(redis++_binary_dir ${binary_dir})
file(GLOB redis++_objs ${binary_dir}/CMakeFiles/redis++_static.dir/src/sw/redis++/*.o)
cmake_print_variables(redis++_source_dir)

add_library(libredis++ UNKNOWN IMPORTED)
Expand Down Expand Up @@ -165,8 +168,6 @@ if (PEDANTIC)
endif()
endif()

find_package(Threads REQUIRED)

# Define source code that goes into the SmartRedis library
list(APPEND C_CPP_SRC
src/c/c_client.cpp
Expand Down Expand Up @@ -226,11 +227,11 @@ include_directories(SYSTEM $<BUILD_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>)
cmake_print_variables(BUILD_SHARED_LIBS)
set(CLIENT_SRC ${C_CPP_SRC})
add_library(smartredis ${CLIENT_SRC})
add_dependencies(smartredis hiredis redis++)
if(BUILD_SHARED_LIBS)
set_target_properties(smartredis PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
target_link_libraries(smartredis PRIVATE libhiredis libredis++ Threads::Threads)
add_dependencies(smartredis libhiredis libredis++)
target_link_libraries(smartredis PRIVATE ${hiredis_objs} ${redis++_objs} PUBLIC Threads::Threads)
target_include_directories(smartredis PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
Expand Down
52 changes: 24 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ NPROC := $(shell nproc 2>/dev/null || python -c "import multiprocessing as mp; p
INSTALL_PREFIX := $(CWD)/install
BUILD_FORTRAN := OFF
BUILD_PYTHON := OFF
BUILD_SHARED_LIBS := ON
BUILD_TYPE := Release
LINK_TYPE := shared
PEDANTIC := OFF

# Test dependencies
Expand All @@ -58,12 +58,12 @@ SR_TEST_NODES := 3
SR_TEST_REDISAI_VER := v1.2.7
SR_TEST_DEVICE := cpu
SR_TEST_PYTEST_FLAGS := -vv -s
ifeq ($(BUILD_SHARED_LIBS),ON)
SR_LINK_DIR = shared
ifeq ($(LINK_TYPE), shared)
BUILD_SHARED_LIBS=on
else
SR_LINK_DIR = static
BUILD_SHARED_LIBS=off
endif
SR_TEST_INSTALL_PREFIX = $(CWD)/install/$(BUILD_TYPE)/$(SR_LINK_DIR)
SR_TEST_INSTALL_PREFIX = $(CWD)/install/$(BUILD_TYPE)/$(SR_LINK_TYPE)
# Do not remove this block. It is used by the 'help' rule when
# constructing the help output.
# help:
Expand All @@ -85,7 +85,7 @@ help:
# help: make lib BUILD_TYPE=Debug Static BUILD_FORTRAN=ON
# help:
# help: BUILD_TYPE {Release, Debug, Coverage} -- optimization level for the build
# help: BUILD_SHARED_LIBS {OFF, ON} -- If OFF, build static libraries, otherwise shared libraries
# help: LINK_TYPE {shared, static} -- type of linking for the smartredis libraries
# help: PEDANTIC {OFF, ON} -- GNU only; enable pickiest compiler settings,
# help: currently fails due to warnings on newer GNU versions
# help: BUILD_FORTRAN {OFF, ON} -- Enable/disable build of Fortran library
Expand Down Expand Up @@ -128,7 +128,6 @@ lib-with-fortran: lib
# help: test-lib - Build SmartRedis clients into a dynamic library with least permissive compiler settings
.PHONY: test-lib
test-lib: PEDANTIC=ON
test-lib: INSTALL_PREFIX=$(SR_TEST_INSTALL_PREFIX)
test-lib: lib

# help: test-lib-with-fortran - Build SmartRedis clients into a dynamic library with least permissive compiler settings
Expand All @@ -149,84 +148,81 @@ test-deps-gpu: test-deps

# help: build-tests - build all tests (C, C++, Fortran)
.PHONY: build-tests
build-tests: INSTALL_PREFIX=$(SR_TEST_INSTALL_PREFIX)
build-tests: test-lib
@cmake -S tests -B build/$(BUILD_TYPE)/tests/$(SR_LINK_DIR) \
build-tests: catch2
@cmake -S tests -B build/$(BUILD_TYPE)/tests/$(SR_LINK_TYPE) \
-DBUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -DBUILD_FORTRAN=$(BUILD_FORTRAN) \
-Dsmartredis_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis \
-Dsmartredis-fortran_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis-fortran
@cmake --build build/$(BUILD_TYPE)/tests/$(SR_LINK_DIR) -- -j $(NPROC)
@cmake --build build/$(BUILD_TYPE)/tests/$(SR_LINK_TYPE) -- -j $(NPROC)


# help: build-test-cpp - build the C++ tests
.PHONY: build-test-cpp
build-test-cpp: INSTALL_PREFIX=$(SR_TEST_INSTALL_PREFIX)
build-test-cpp: test-lib
build-test-cpp: catch2
cmake -S tests/cpp -B build/$(BUILD_TYPE)/tests/$(SR_LINK_DIR)/cpp \
cmake -S tests/cpp -B build/$(BUILD_TYPE)/tests/$(SR_LINK_TYPE)/cpp \
-DBUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) \
-Dsmartredis_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis
cmake --build build/$(BUILD_TYPE)/tests/$(SR_LINK_DIR)/cpp -- -j $(NPROC)
cmake --build build/$(BUILD_TYPE)/tests/$(SR_LINK_TYPE)/cpp -- -j $(NPROC)

# help: build-unit-test-cpp - build the C++ unit tests
.PHONY: build-unit-test-cpp
build-unit-test-cpp: INSTALL_PREFIX=$(SR_TEST_INSTALL_PREFIX)
build-unit-test-cpp: test-lib
@cmake -S tests/cpp/unit-tests -B build/$(BUILD_TYPE)/tests/$(SR_LINK_DIR)/cpp/unit-tests \
build-unit-test-cpp: catch2
@cmake -S tests/cpp/unit-tests -B build/$(BUILD_TYPE)/tests/$(SR_LINK_TYPE)/cpp/unit-tests \
-DBUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) \
-Dsmartredis_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis
@cmake --build build/$(BUILD_TYPE)/tests/$(SR_LINK_DIR)/cpp/unit-tests -- -j $(NPROC)
@cmake --build build/$(BUILD_TYPE)/tests/$(SR_LINK_TYPE)/cpp/unit-tests -- -j $(NPROC)

# help: build-test-c - build the C tests
.PHONY: build-test-c
build-test-c: INSTALL_PREFIX=$(SR_TEST_INSTALL_PREFIX)
build-test-c: test-lib
@cmake -S tests/c -B build/$(BUILD_TYPE)/tests/$(SR_LINK_DIR)/c \
@cmake -S tests/c -B build/$(BUILD_TYPE)/tests/$(SR_LINK_TYPE)/c \
-DBUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) \
-Dsmartredis_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis
@cmake --build build/$(BUILD_TYPE)/tests/$(SR_LINK_DIR)/c -- -j $(NPROC)
@cmake --build build/$(BUILD_TYPE)/tests/$(SR_LINK_TYPE)/c -- -j $(NPROC)


# help: build-test-fortran - build the Fortran tests
.PHONY: build-test-fortran
build-test-fortran: INSTALL_PREFIX=$(SR_TEST_INSTALL_PREFIX)
build-test-fortran: BUILD_FORTRAN=ON
build-test-fortran: test-lib
@cmake -S tests/fortran -B build/$(BUILD_TYPE)/tests/$(SR_LINK_DIR)/fortran \
@cmake -S tests/fortran -B build/$(BUILD_TYPE)/tests/$(SR_LINK_TYPE)/fortran \
-DBUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) \
-Dsmartredis_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis \
-Dsmartredis-fortran_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis-fortran
@cmake --build build/$(BUILD_TYPE)/tests/$(SR_LINK_DIR)/fortran -- -j $(NPROC)
@cmake --build build/$(BUILD_TYPE)/tests/$(SR_LINK_TYPE)/fortran -- -j $(NPROC)


# help: build-examples - build all examples (serial, parallel)
.PHONY: build-examples
build-examples: lib
@cmake -S examples -B build/$(BUILD_TYPE)/examples/$(SR_LINK_DIR) -DBUILD_TYPE=$(BUILD_TYPE) \
@cmake -S examples -B build/$(BUILD_TYPE)/examples/$(SR_LINK_TYPE) -DBUILD_TYPE=$(BUILD_TYPE) \
-DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -DBUILD_FORTRAN=$(BUILD_FORTRAN) \
-Dsmartredis_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis \
-Dsmartredis-fortran_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis-fortran
@cmake --build build/$(BUILD_TYPE)/examples/$(SR_LINK_DIR) -- -j $(NPROC)
@cmake --build build/$(BUILD_TYPE)/examples/$(SR_LINK_TYPE) -- -j $(NPROC)


# help: build-example-serial - buld serial examples
.PHONY: build-example-serial
build-example-serial: lib
@cmake -S examples/serial -B build/$(BUILD_TYPE)/examples/$(SR_LINK_DIR)/serial \
@cmake -S examples/serial -B build/$(BUILD_TYPE)/examples/$(SR_LINK_TYPE)/serial \
-DBUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -DBUILD_FORTRAN=$(BUILD_FORTRAN) \
-Dsmartredis_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis \
-Dsmartredis-fortran_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis-fortran
@cmake --build build/$(BUILD_TYPE)/examples/$(SR_LINK_DIR)/serial
@cmake --build build/$(BUILD_TYPE)/examples/$(SR_LINK_TYPE)/serial


# help: build-example-parallel - build parallel examples (requires MPI)
.PHONY: build-example-parallel
build-example-parallel: lib
@cmake -S examples/parallel -B build/$(BUILD_TYPE)/examples/$(SR_LINK_DIR)/parallel \
@cmake -S examples/parallel -B build/$(BUILD_TYPE)/examples/$(SR_LINK_TYPE)/parallel \
-DBUILD_TYPE=$(BUILD_TYPE) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -DBUILD_FORTRAN=$(BUILD_FORTRAN) \
-Dsmartredis_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis \
-Dsmartredis-fortran_DIR=$(INSTALL_PREFIX)/share/cmake/smartredis-fortran
@cmake --build build/$(BUILD_TYPE)/examples/$(SR_LINK_DIR)/parallel
@cmake --build build/$(BUILD_TYPE)/examples/$(SR_LINK_TYPE)/parallel


# help: clean-deps - remove third-party deps
Expand Down
1 change: 1 addition & 0 deletions tests/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ enable_language(C)
set(CMAKE_CXX_STANDARD 17)
SET(CMAKE_C_STANDARD 99)
find_package(smartredis REQUIRED)
find_package(Threads REQUIRED)

# Define all the tests to be built
list(APPEND EXECUTABLES
Expand Down
1 change: 1 addition & 0 deletions tests/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ enable_language(CXX)
set(CMAKE_CXX_STANDARD 17)
SET(CMAKE_C_STANDARD 99)
find_package(smartredis REQUIRED)
find_package(Threads)

# Bring in the Catch2 unit-tests
add_subdirectory(unit-tests)
Expand Down
2 changes: 1 addition & 1 deletion tests/docker/c/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

FROM smartredis:local
FROM smartredis

# Copy source and build files into the container
COPY ./CMakeLists.txt /usr/local/src/DockerTest/
Expand Down
2 changes: 1 addition & 1 deletion tests/docker/cpp/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

FROM smartredis:local
FROM smartredis

# Copy source and build files into the container
COPY ./CMakeLists.txt /usr/local/src/DockerTest/
Expand Down
2 changes: 1 addition & 1 deletion tests/docker/fortran/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

FROM smartredis:local
FROM smartredis

# Install Fortran compiler
RUN apt-get update && \
Expand Down
3 changes: 2 additions & 1 deletion tests/fortran/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ set(CMAKE_CXX_STANDARD 17)
SET(CMAKE_C_STANDARD 99)
find_package(smartredis REQUIRED)
find_package(smartredis-fortran REQUIRED)
find_package(Threads REQUIRED)

# Stuff the test_utils into a library to enable parallel builds
add_library(test-utils STATIC test_utils.F90)
Expand Down Expand Up @@ -68,7 +69,7 @@ foreach(EXECUTABLE ${EXECUTABLES})
OUTPUT_NAME ${EXECUTABLE}
)
target_link_libraries(${EXECUTABLE}_fortran_test
smartredis smartredis-fortran test-utils
smartredis smartredis-fortran test-utils Threads::Threads
)
target_include_directories(${EXECUTABLE}_fortran_test PRIVATE ${smartredis_INCLUDE_DIR} ${smartredis-fortran_INCLUDE_DIR})
endforeach()

0 comments on commit e0c9839

Please sign in to comment.