Skip to content

Commit cc00f41

Browse files
build: Add spdlog build dependency
spdlog is included and built from source, using the third_party/spdlog submodule. When Gloo is built as a static library, spdlog is used in its header-only library form. When Gloo is built as a shared library, spdlog is built statically and included. A key goal is to make spdlog a dependency internal to Gloo only. Gloo users should not have to install spdlog themselves. This commit does not add any usages of spdlog in Gloo, just the build infrastructure to use it.
1 parent 9d19fab commit cc00f41

File tree

6 files changed

+35
-10
lines changed

6 files changed

+35
-10
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ endif()
9898
set(GLOO_INSTALL ON CACHE BOOL "")
9999
mark_as_advanced(GLOO_INSTALL)
100100

101+
# Compile definitions for Gloo
102+
set(GLOO_COMPILE_DEFS)
103+
101104
# Build shared or static libraries (override from parent project)
102105
if(BUILD_SHARED_LIBS)
103106
set(GLOO_STATIC_OR_SHARED SHARED CACHE STRING "")

cmake/Dependencies.cmake

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ set(gloo_DEPENDENCY_LIBS "")
22
set(gloo_cuda_DEPENDENCY_LIBS "")
33
set(gloo_hip_DEPENDENCY_LIBS "")
44

5+
# Dependency libraries for all Gloo targets (e.g. tests, benchmarks, etc.)
6+
set(gloo_ALL_TARGETS_DEPENDENCY_LIBS "")
7+
58
# Configure path to modules (for find_package)
69
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/Modules/")
710

@@ -104,7 +107,7 @@ if(USE_MPI)
104107
message(STATUS "MPI libraries: " ${MPI_CXX_LIBRARIES})
105108
include_directories(SYSTEM ${MPI_CXX_INCLUDE_PATH})
106109
list(APPEND gloo_DEPENDENCY_LIBS ${MPI_CXX_LIBRARIES})
107-
add_definitions(-DGLOO_USE_MPI=1)
110+
list(APPEND GLOO_COMPILE_DEFS "GLOO_USE_MPI=1")
108111
else()
109112
message(WARNING "Not compiling with MPI support. Suppress this warning with -DUSE_MPI=OFF.")
110113
set(USE_MPI OFF)
@@ -199,3 +202,19 @@ if(BUILD_TEST)
199202
target_link_libraries(gtest INTERFACE ${GTEST_LIBRARIES})
200203
endif()
201204
endif()
205+
206+
set(SPDLOG_BUILD_SHARED OFF CACHE BOOL "" FORCE)
207+
set(SPDLOG_BUILD_PIC ON CACHE BOOL "" FORCE)
208+
set(SPDLOG_FMT_EXTERNAL OFF CACHE BOOL "" FORCE)
209+
210+
set(_save_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
211+
set(BUILD_SHARED_LIBS OFF)
212+
add_subdirectory(third_party/spdlog EXCLUDE_FROM_ALL)
213+
set(BUILD_SHARED_LIBS ${_save_BUILD_SHARED_LIBS})
214+
215+
if(GLOO_STATIC_OR_SHARED STREQUAL "STATIC")
216+
list(APPEND gloo_ALL_TARGETS_DEPENDENCY_LIBS $<BUILD_INTERFACE:spdlog::spdlog_header_only>)
217+
else()
218+
list(APPEND gloo_ALL_TARGETS_DEPENDENCY_LIBS spdlog::spdlog)
219+
list(APPEND GLOO_COMPILE_DEFS SPDLOG_COMPILED_LIB)
220+
endif()

gloo/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,12 @@ if(USE_CUDA)
147147
cuda_add_library(gloo_cuda ${GLOO_CUDA_SRCS} ${GLOO_STATIC_OR_SHARED})
148148
endif()
149149
target_link_libraries(gloo_cuda gloo ${gloo_cuda_DEPENDENCY_LIBS})
150+
set_property(TARGET gloo_cuda APPEND PROPERTY LINK_LIBRARIES ${gloo_ALL_TARGETS_DEPENDENCY_LIBS})
150151
endif()
151152
if(USE_ROCM)
152153
gloo_hip_add_library(gloo_hip ${GLOO_HIP_SRCS})
153154
target_link_libraries(gloo_hip gloo)
155+
set_property(TARGET gloo_hip APPEND PROPERTY LINK_LIBRARIES ${gloo_ALL_TARGETS_DEPENDENCY_LIBS})
154156
endif()
155157
if(USE_LIBUV)
156158
target_link_libraries(gloo PRIVATE uv_a)
@@ -165,7 +167,8 @@ elseif(USE_TCP_OPENSSL_LOAD)
165167
target_link_libraries(gloo PRIVATE dl)
166168
endif()
167169

168-
target_link_libraries(gloo PRIVATE ${gloo_DEPENDENCY_LIBS})
170+
target_link_libraries(gloo PRIVATE ${gloo_DEPENDENCY_LIBS} ${gloo_ALL_TARGETS_DEPENDENCY_LIBS})
171+
target_compile_definitions(gloo PRIVATE ${GLOO_COMPILE_DEFS})
169172

170173
# Add Interface include directories that are relocatable.
171174
target_include_directories(gloo INTERFACE $<INSTALL_INTERFACE:include>)

gloo/benchmark/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set(GLOO_BENCHMARK_SRCS
55
)
66

77
add_executable(benchmark ${GLOO_BENCHMARK_SRCS})
8-
target_link_libraries(benchmark gloo)
8+
target_link_libraries(benchmark gloo ${gloo_ALL_TARGETS_DEPENDENCY_LIBS})
99

1010
if(GLOO_INSTALL)
1111
install(TARGETS benchmark DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)

gloo/examples/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
if(MSVC)
22
add_executable(example_reduce example_reduce.cc)
3-
target_link_libraries(example_reduce gloo)
3+
target_link_libraries(example_reduce gloo ${gloo_ALL_TARGETS_DEPENDENCY_LIBS})
44
add_executable(example_allreduce example_allreduce.cc)
5-
target_link_libraries(example_allreduce gloo)
5+
target_link_libraries(example_allreduce gloo ${gloo_ALL_TARGETS_DEPENDENCY_LIBS})
66

77
if(USE_LIBUV)
88
add_custom_command(TARGET example_reduce POST_BUILD
@@ -12,7 +12,7 @@ if(MSVC)
1212
endif()
1313
else()
1414
add_executable(example1 example1.cc)
15-
target_link_libraries(example1 gloo)
15+
target_link_libraries(example1 gloo ${gloo_ALL_TARGETS_DEPENDENCY_LIBS})
1616
add_executable(looks_like_mpi looks_like_mpi.cc)
17-
target_link_libraries(looks_like_mpi gloo)
17+
target_link_libraries(looks_like_mpi gloo ${gloo_ALL_TARGETS_DEPENDENCY_LIBS})
1818
endif()

gloo/test/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ set(GLOO_TEST_SRCS
1717
"${CMAKE_CURRENT_SOURCE_DIR}/remote_key_test.cc"
1818
"${CMAKE_CURRENT_SOURCE_DIR}/send_recv_test.cc"
1919
)
20-
set(GLOO_TEST_LIBRARIES)
20+
set(GLOO_TEST_LIBRARIES ${gloo_ALL_TARGETS_DEPENDENCY_LIBS})
2121

2222
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
2323
list(APPEND GLOO_TEST_SRCS
@@ -64,7 +64,7 @@ if(USE_CUDA)
6464
else()
6565
cuda_add_executable(gloo_test_cuda ${GLOO_TEST_CUDA_SRCS})
6666
endif()
67-
target_link_libraries(gloo_test_cuda gloo_cuda gtest OpenSSL::SSL OpenSSL::Crypto ${GLOO_CUDA_LIBRARIES})
67+
target_link_libraries(gloo_test_cuda gloo_cuda gtest ${GLOO_TEST_LIBRARIES} ${GLOO_CUDA_LIBRARIES})
6868
endif()
6969
endif()
7070

@@ -79,5 +79,5 @@ if(USE_ROCM)
7979
)
8080

8181
gloo_hip_add_executable(gloo_test_hip ${GLOO_TEST_HIP_SRCS})
82-
target_link_libraries(gloo_test_hip gloo_hip gtest OpenSSL::SSL OpenSSL::Crypto)
82+
target_link_libraries(gloo_test_hip gloo_hip gtest ${GLOO_TEST_LIBRARIES})
8383
endif()

0 commit comments

Comments
 (0)