Skip to content

Commit 56da889

Browse files
committed
Improve library linking
* Use private links for libraries that are specific to one module * Separate linking of Boost::python and Boost::iostreams * Remove explicit links to private libraries in exported cmake config
1 parent bdc56ab commit 56da889

File tree

5 files changed

+9
-19
lines changed

5 files changed

+9
-19
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ endif()
6666

6767
target_compile_features(spt3g INTERFACE cxx_std_17)
6868
target_include_directories(spt3g INTERFACE ${Boost_INCLUDE_DIR})
69-
target_link_libraries(spt3g INTERFACE Threads::Threads ${Boost_LIBRARIES})
69+
target_link_libraries(spt3g INTERFACE Threads::Threads Boost::python)
7070
target_include_directories(spt3g INTERFACE $<INSTALL_INTERFACE:${SPT3G_INCLUDE_INSTALL_DIR}>)
7171

7272
# Python bindings

cmake/Spt3gConfig.cmake.in

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,7 @@ set(Boost_USE_STATIC_LIBS @Boost_USE_STATIC_LIBS@)
4242
set(Boost_USE_MULTITHREADED @Boost_USE_MULTITHREADED@)
4343
set(Boost_USE_STATIC_RUNTIME @Boost_USE_STATIC_RUNTIME@)
4444
set(Boost_PYTHON_VERSION @Boost_PYTHON_VERSION@)
45-
find_dependency(Boost COMPONENTS iostreams python REQUIRED)
46-
47-
if(@FLAC_FOUND@)
48-
find_dependency(FLAC MODULE)
49-
endif()
50-
if(@NetCDF_FOUND@)
51-
find_dependency(NetCDF MODULE)
52-
endif()
53-
if(@OpenMP_FOUND@)
54-
find_dependency(OpenMP)
55-
endif()
45+
find_dependency(Boost COMPONENTS python REQUIRED)
5646

5747
include(FindPackageHandleStandardArgs)
5848
find_package_handle_standard_args(Spt3g

core/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ add_spt3g_library(core SHARED
2222
target_link_libraries(core PUBLIC spt3g)
2323

2424
find_package(Filesystem REQUIRED)
25-
target_link_libraries(core PUBLIC std::filesystem)
25+
target_link_libraries(core PRIVATE std::filesystem)
2626

2727
# add python bindings
2828
add_spt3g_module(core src/python.cxx)
@@ -37,10 +37,12 @@ target_include_directories(core PUBLIC
3737
find_package(FLAC MODULE)
3838
if(FLAC_FOUND)
3939
target_compile_definitions(core PRIVATE -DG3_HAS_FLAC)
40-
target_link_libraries(core PUBLIC FLAC::FLAC)
41-
set(FLAC_FOUND ${FLAC_FOUND} PARENT_SCOPE)
40+
target_link_libraries(core PRIVATE FLAC::FLAC)
4241
endif()
4342

43+
# Link Boost IOStreams
44+
target_link_libraries(core PRIVATE Boost::iostreams)
45+
4446
# Link against BZIP2 library
4547
if(NOT DEFINED WITH_BZIP2)
4648
set(WITH_BZIP2 TRUE CACHE BOOL "Enable bzip2 file compression")

dfmux/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ target_link_libraries(dfmux PUBLIC core)
1717
add_spt3g_module(dfmux src/python.cxx)
1818

1919
if (NetCDF_FOUND AND HDF5_FOUND)
20-
target_link_libraries(dfmux PUBLIC NetCDF::NetCDF)
20+
target_link_libraries(dfmux PRIVATE NetCDF::NetCDF)
2121
add_spt3g_program(bin/ledgerman.py ledgerman)
22-
set(NetCDF_FOUND ${NetCDF_FOUND} PARENT_SCOPE)
2322
endif()
2423

2524
link_python_dir()

maps/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ target_link_libraries(maps PUBLIC core calibration)
2222

2323
find_package(OpenMP)
2424
if(OpenMP_FOUND)
25-
target_link_libraries(maps PUBLIC OpenMP::OpenMP_CXX)
26-
set(OpenMP_FOUND ${OpenMP_FOUND} PARENT_SCOPE)
25+
target_link_libraries(maps PRIVATE OpenMP::OpenMP_CXX)
2726
endif()
2827

2928
add_spt3g_module(maps src/python.cxx)

0 commit comments

Comments
 (0)