Skip to content

Commit f5b3b26

Browse files
authored
fix(cmake): honor BUILD_SHARED_LIBS through default linkage targets (#9962)
## Summary `BUILD_SHARED_LIBS` now consistently picks static or shared libs. If the top-level Vortex static lib is linked against, but `BUILD_SHARED_LIBS` is passed, deps are still linked as shared libs. Validated with `ldd build/validation-cpu/cpp/tests/vortex_cxx_test; ldd build/validation-cpu/ffi/test/vortex_ffi_test; git --no-optional-locks status --short --branch`: ``` libvortex_cxx.so => /home/ubuntu/vortex/build/validation-cpu/cpp/libvortex_cxx.so (0x0000f9ed73920000) libCatch2Maind.so.3.8.1 => /home/ubuntu/vortex/build/validation-cpu/_deps/catch-build/src/libCatch2Maind.so.3.8.1 (0x0000f9ed738f0000) libnanoarrow_shared.so => /home/ubuntu/vortex/build/validation-cpu/_deps/nanoarrow-build/libnanoarrow_shared.so (0x0000f9ed738b0000) libvortex_ffi.so => /home/ubuntu/vortex/build/validation-cpu/ffi/libvortex_ffi.so (0x0000f9ed67970000) libCatch2d.so.3.8.1 => /home/ubuntu/vortex/build/validation-cpu/_deps/catch-build/src/libCatch2d.so.3.8.1 (0x0000f9ed676a0000) libstdc++.so.6 => /lib/aarch64-linux-gnu/libstdc++.so.6 (0x0000f9ed673f0000) libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000f9ed67340000) libgcc_s.so.1 => /lib/aarch64-linux-gnu/libgcc_s.so.1 (0x0000f9ed67300000) libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000f9ed67140000) /lib/ld-linux-aarch64.so.1 (0x0000f9ed73a40000) linux-vdso.so.1 (0x0000f3741ab80000) libvortex_ffi.so => /home/ubuntu/vortex/build/validation-cpu/ffi/libvortex_ffi.so (0x0000f3740ebb0000) libCatch2Maind.so.3.8.1 => /home/ubuntu/vortex/build/validation-cpu/_deps/catch-build/src/libCatch2Maind.so.3.8.1 (0x0000f3740eb80000) libnanoarrow_shared.so => /home/ubuntu/vortex/build/validation-cpu/_deps/nanoarrow-build/libnanoarrow_shared.so (0x0000f3740eb40000) libCatch2d.so.3.8.1 => /home/ubuntu/vortex/build/validation-cpu/_deps/catch-build/src/libCatch2d.so.3.8.1 (0x0000f3740e870000) libstdc++.so.6 => /lib/aarch64-linux-gnu/libstdc++.so.6 (0x0000f3740e5c0000) libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000f3740e510000) libgcc_s.so.1 => /lib/aarch64-linux-gnu/libgcc_s.so.1 (0x0000f3740e4d0000) libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000f3740e310000) /lib/ld-linux-aarch64.so.1 (0x0000f3741ab90000) ``` Signed-off-by: Alexander Droste <[email protected]>
1 parent a3bf8f7 commit f5b3b26

9 files changed

Lines changed: 38 additions & 25 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
# lang/cpp adds the C++ wrapper. Both also support standalone configuration.
66
#
77
# add_subdirectory(path/to/vortex vortex)
8-
# target_link_libraries(my_c_target PRIVATE Vortex::ffi_static)
9-
# target_link_libraries(my_cpp_target PRIVATE Vortex::cpp_static)
8+
# target_link_libraries(my_c_target PRIVATE Vortex::ffi)
9+
# target_link_libraries(my_cpp_target PRIVATE Vortex::cpp)
1010
#
11-
# Use Vortex::ffi_shared and Vortex::cpp_shared for shared linkage.
11+
# BUILD_SHARED_LIBS selects linkage; explicit _static and _shared targets also exist.
1212
#
1313
# See lang/cpp/README.md for build options and embedding requirements,
1414
# and vortex-ffi/README.md for C API development.

‎lang/cpp/CMakeLists.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ add_library(Vortex::cpp_shared ALIAS vortex_cxx_shared)
7272

7373
if(BUILD_SHARED_LIBS)
7474
set_target_properties(vortex_cxx_static PROPERTIES EXCLUDE_FROM_ALL TRUE)
75-
set(_vortex_cpp_target Vortex::cpp_shared)
75+
add_library(Vortex::cpp ALIAS vortex_cxx_shared)
7676
else()
7777
set_target_properties(vortex_cxx_shared PROPERTIES EXCLUDE_FROM_ALL TRUE)
78-
set(_vortex_cpp_target Vortex::cpp_static)
78+
add_library(Vortex::cpp ALIAS vortex_cxx_static)
7979
endif()
8080

8181
foreach(_target IN ITEMS vortex_cxx_static vortex_cxx_shared)

‎lang/cpp/README.md‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ Vendor or fetch a pinned, complete checkout:
2525

2626
```cmake
2727
add_subdirectory(path/to/vortex vortex)
28-
target_link_libraries(my_cpp_target PRIVATE Vortex::cpp_shared)
29-
target_link_libraries(my_c_target PRIVATE Vortex::ffi_shared)
28+
target_link_libraries(my_cpp_target PRIVATE Vortex::cpp)
29+
target_link_libraries(my_c_target PRIVATE Vortex::ffi)
3030
```
3131

3232
Vortex leaves parent build settings unchanged. Its archives are position-independent.
3333

34-
For static linkage, use `Vortex::ffi_static` and `Vortex::cpp_static`.
34+
`Vortex::cpp` and `Vortex::ffi` follow `BUILD_SHARED_LIBS` when Vortex is configured:
35+
`OFF` selects static linkage; `ON` selects shared linkage. Set it before adding Vortex.
36+
The explicit `Vortex::cpp_static`, `Vortex::cpp_shared`, `Vortex::ffi_static`, and
37+
`Vortex::ffi_shared` targets remain available regardless of the option.
3538

3639
## Build options
3740

@@ -40,7 +43,7 @@ options. Defaults below are for standalone builds.
4043

4144
| Option | Default | Purpose |
4245
| --------------------------- | -------- | ----------------------------------------------------------- |
43-
| `BUILD_SHARED_LIBS` | `OFF` | Build shared Vortex libraries. |
46+
| `BUILD_SHARED_LIBS` | `OFF` | Select shared linkage for default targets. |
4447
| `VORTEX_BUILD_TESTS` | `OFF` | C API and C++23 wrapper tests. |
4548
| `VORTEX_BUILD_EXAMPLES` | `OFF` | C/C++ examples. |
4649
| `VORTEX_WARNINGS_AS_ERRORS` | `ON` | Warnings as errors for Vortex targets only. |
@@ -51,7 +54,15 @@ options. Defaults below are for standalone builds.
5154
| `VORTEX_DEBUG_INFO` | `2` | C/C++ and Rust debug info: `0` none, `1` limited, `2` full. |
5255
| `VORTEX_ENABLE_CUDA` | `OFF` | Linux-only [CUDA build](#cuda). |
5356

54-
As a standard CMake option, `BUILD_SHARED_LIBS` also affects dependencies such as Catch2.
57+
Tests and examples use the selected Vortex linkage and Nanoarrow's corresponding
58+
`nanoarrow::nanoarrow` target. Catch2 also follows `BUILD_SHARED_LIBS`; header-only
59+
dependencies have no linkage choice. Dependencies already configured by a parent keep
60+
their existing configuration, so set the option consistently before fetching dependencies.
61+
62+
The Rust implementation is always built as a position-independent static archive,
63+
embedded into the shared FFI library when shared linkage is selected. `BUILD_SHARED_LIBS=OFF`
64+
does not request a fully static executable or change system/CUDA runtime linkage.
65+
5566
Embedded builds default `VORTEX_WARNINGS_AS_ERRORS` to `OFF`. Parents must call
5667
`enable_testing()` to register tests.
5768

‎lang/cpp/examples/CMakeLists.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ foreach(_name reader writer dtype scan scan_to_arrow)
1212
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
1313
# Drop the inherited per-config override so the local output directory takes effect.
1414
set_property(TARGET cpp_${_name} PROPERTY RUNTIME_OUTPUT_DIRECTORY_${_config_upper})
15-
target_link_libraries(cpp_${_name} PRIVATE ${_vortex_cpp_target})
15+
target_link_libraries(cpp_${_name} PRIVATE Vortex::cpp)
1616
endforeach()
17-
target_link_libraries(cpp_scan_to_arrow PRIVATE nanoarrow_shared)
17+
target_link_libraries(cpp_scan_to_arrow PRIVATE nanoarrow::nanoarrow)

‎lang/cpp/tests/CMakeLists.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ add_executable(vortex_cxx_test ${TEST_FILES})
1515
target_compile_features(vortex_cxx_test PRIVATE cxx_std_23)
1616
target_include_directories(vortex_cxx_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
1717
target_link_libraries(vortex_cxx_test PRIVATE
18-
${_vortex_cpp_target}
18+
Vortex::cpp
1919
Catch2::Catch2WithMain
2020
magic_enum::magic_enum
21-
nanoarrow_shared)
21+
nanoarrow::nanoarrow)
2222

2323
catch_discover_tests(vortex_cxx_test)

‎vortex-ffi/CMakeLists.txt‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ include(cmake/Configure.cmake)
5656

5757
add_library(Vortex::ffi_static ALIAS vortex_ffi_static)
5858
add_library(Vortex::ffi_shared ALIAS vortex_ffi_shared)
59-
set(_vortex_ffi_target Vortex::ffi_static)
6059
if(BUILD_SHARED_LIBS)
61-
set(_vortex_ffi_target Vortex::ffi_shared)
60+
add_library(Vortex::ffi ALIAS vortex_ffi_shared)
61+
else()
62+
add_library(Vortex::ffi ALIAS vortex_ffi_static)
6263
endif()
6364

6465
# Test and example dependencies are fetched at configure time and never installed.

‎vortex-ffi/README.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ Add a complete Vortex checkout. CMake builds the Rust archive for you:
66

77
```cmake
88
add_subdirectory(path/to/vortex vortex)
9-
target_link_libraries(my_target PRIVATE Vortex::ffi_shared)
9+
target_link_libraries(my_target PRIVATE Vortex::ffi)
1010
```
1111

12-
The target supplies the library and headers. For static linkage, use `Vortex::ffi_static`.
13-
Both targets are available regardless of `BUILD_SHARED_LIBS`. You can also add `vortex-ffi`
14-
directly. See the [CMake build guide](../lang/cpp/README.md) for requirements, options, and
15-
deployment limits.
12+
The target supplies the library and headers, selecting static or shared linkage according
13+
to `BUILD_SHARED_LIBS` (`OFF` by default). Set the option before adding Vortex. To select
14+
linkage explicitly, use `Vortex::ffi_static` or `Vortex::ffi_shared`; both remain available
15+
regardless of the option. You can also add `vortex-ffi` directly. See the
16+
[CMake build guide](../lang/cpp/README.md) for requirements, options, and deployment limits.
1617

1718
### Examples and tests
1819

‎vortex-ffi/examples/CMakeLists.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ foreach(_name scan scan_to_arrow dtype write_sample)
1717
if(VORTEX_WARNINGS_AS_ERRORS)
1818
target_compile_options(ffi_${_name} PRIVATE -Werror)
1919
endif()
20-
target_link_libraries(ffi_${_name} PRIVATE ${_vortex_ffi_target})
20+
target_link_libraries(ffi_${_name} PRIVATE Vortex::ffi)
2121
endforeach()
22-
target_link_libraries(ffi_scan_to_arrow PRIVATE nanoarrow_shared)
22+
target_link_libraries(ffi_scan_to_arrow PRIVATE nanoarrow::nanoarrow)

‎vortex-ffi/test/CMakeLists.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ if(VORTEX_WARNINGS_AS_ERRORS)
2525
target_compile_options(vortex_ffi_test PRIVATE -Werror)
2626
endif()
2727
target_link_libraries(vortex_ffi_test PRIVATE
28-
${_vortex_ffi_target}
28+
Vortex::ffi
2929
Catch2::Catch2WithMain
30-
nanoarrow_shared)
30+
nanoarrow::nanoarrow)
3131

3232
catch_discover_tests(vortex_ffi_test)

0 commit comments

Comments
 (0)