Skip to content

Commit

Permalink
Export CMake libraries with aliases
Browse files Browse the repository at this point in the history
PR #675 (bdwgc).

This allows bdwgc to be included in a cmake build using
`add_subdirectory`, `FetchContent`, or similar.  It then relies on the
CMake CMP0028 policy to ensure the library is found in any
`target_link_libraries` usage.

Without the alias, `target_link_libraries` will not be able to find
`gc`, `gccpp`, etc.

* CMakeLists.txt (add_library): Specify alias for gc.
* CMakeLists.txt [enable_cplusplus] (add_library): Specify alias for
gccpp.
* CMakeLists.txt [enable_cplusplus && enable_throw_bad_alloc_library]
(add_library): Specify alias for gctba.
* CMakeLists.txt [build_cord] (add_library): Specify alias for cord.
  • Loading branch information
jeaye authored and ivmai committed Nov 1, 2024
1 parent 9a30cfa commit 1b04347
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ if (EMSCRIPTEN AND enable_emscripten_asyncify)
endif()

add_library(gc ${SRC})
add_library(bdwgc::gc ALIAS gc)
target_link_libraries(gc
PRIVATE ${ATOMIC_OPS_LIBS_CMAKE} ${THREADDLLIBS_LIST})
target_include_directories(gc INTERFACE
Expand All @@ -676,6 +677,7 @@ if (enable_cplusplus)
else()
add_library(gccpp gc_badalc.cc gc_cpp.cc)
endif()
add_library(bdwgc::gccpp ALIAS gccpp)
target_link_libraries(gccpp PRIVATE gc)
target_include_directories(gccpp INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
Expand All @@ -687,6 +689,7 @@ if (enable_cplusplus)
else()
add_library(gctba gc_badalc.cc)
endif()
add_library(bdwgc::gctba ALIAS gctba)
target_link_libraries(gctba PRIVATE gc)
target_include_directories(gctba INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
Expand All @@ -697,6 +700,7 @@ endif()
if (build_cord)
set(CORD_SRC cord/cordbscs.c cord/cordprnt.c cord/cordxtra.c)
add_library(cord ${CORD_SRC})
add_library(bdwgc::cord ALIAS cord)
target_link_libraries(cord PRIVATE gc)
target_include_directories(cord INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
Expand Down

0 comments on commit 1b04347

Please sign in to comment.