Skip to content

Commit 2ab514f

Browse files
committed
fix: build unit tests with shared library
1 parent 68eeb2c commit 2ab514f

2 files changed

Lines changed: 36 additions & 7 deletions

File tree

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@ option(ICEBERG_BUILD_REST "Build rest catalog client" ON)
4545
option(ICEBERG_ENABLE_ASAN "Enable Address Sanitizer" OFF)
4646
option(ICEBERG_ENABLE_UBSAN "Enable Undefined Behavior Sanitizer" OFF)
4747

48+
if(ICEBERG_BUILD_SHARED)
49+
set(ICEBERG_TEST_LINKAGE_DEFAULT "shared")
50+
else()
51+
set(ICEBERG_TEST_LINKAGE_DEFAULT "static")
52+
endif()
53+
set(ICEBERG_TEST_LINKAGE ${ICEBERG_TEST_LINKAGE_DEFAULT} CACHE STRING "Linkage of Iceberg libraries with unit tests executables")
54+
if(ICEBERG_BUILD_TESTS)
55+
if(ICEBERG_TEST_LINKAGE STREQUAL "shared" AND NOT ICEBERG_BUILD_SHARED)
56+
message(FATAL_ERROR "If using ICEBERG_TEST_LINKAGE=shared, must also pass ICEBERG_BUILD_SHARED=on")
57+
endif()
58+
if(ICEBERG_TEST_LINKAGE STREQUAL "static" AND NOT ICEBERG_BUILD_STATIC)
59+
message(FATAL_ERROR "If using ICEBERG_TEST_LINKAGE=static, must also pass ICEBERG_BUILD_STATIC=on")
60+
endif()
61+
endif()
62+
4863
include(GNUInstallDirs)
4964
include(FetchContent)
5065

src/iceberg/test/CMakeLists.txt

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,20 @@ function(add_iceberg_test test_name)
5252

5353
target_sources(${test_name} PRIVATE ${ARG_SOURCES})
5454

55-
if(ARG_USE_BUNDLE)
56-
target_link_libraries(${test_name} PRIVATE iceberg_bundle_static GTest::gtest_main
57-
GTest::gmock)
55+
target_link_libraries(${test_name} PRIVATE GTest::gtest_main GTest::gmock)
56+
57+
if("${ICEBERG_TEST_LINKAGE}" STREQUAL "shared")
58+
if (ARG_USE_BUNDLE)
59+
target_link_libraries(${test_name} PRIVATE iceberg_bundle_shared)
60+
else()
61+
target_link_libraries(${test_name} PRIVATE iceberg_shared)
62+
endif()
5863
else()
59-
target_link_libraries(${test_name} PRIVATE iceberg_static GTest::gtest_main
60-
GTest::gmock)
64+
if (ARG_USE_BUNDLE)
65+
target_link_libraries(${test_name} PRIVATE iceberg_bundle_static)
66+
else()
67+
target_link_libraries(${test_name} PRIVATE iceberg_static)
68+
endif()
6169
endif()
6270

6371
add_test(NAME ${test_name} COMMAND ${test_name})
@@ -160,8 +168,14 @@ if(ICEBERG_BUILD_BUNDLE)
160168
endif()
161169

162170
if(ICEBERG_BUILD_REST)
163-
add_iceberg_test(rest_catalog_test SOURCES rest_catalog_test.cc
171+
add_iceberg_test(rest_catalog_test
172+
SOURCES
173+
rest_catalog_test.cc
164174
rest_json_internal_test.cc)
165-
target_link_libraries(rest_catalog_test PRIVATE iceberg_rest_static)
175+
if("${ICEBERG_TEST_LINKAGE}" STREQUAL "shared")
176+
target_link_libraries(rest_catalog_test PRIVATE iceberg_rest_shared)
177+
else()
178+
target_link_libraries(rest_catalog_test PRIVATE iceberg_rest_static)
179+
endif()
166180
target_include_directories(rest_catalog_test PRIVATE ${cpp-httplib_SOURCE_DIR})
167181
endif()

0 commit comments

Comments
 (0)