Skip to content

Commit

Permalink
Add option to disable random_device for header-only build
Browse files Browse the repository at this point in the history
  • Loading branch information
zjyhjqs committed Nov 10, 2024
1 parent 5957c91 commit d31c6c2
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,24 @@ cmake_minimum_required(VERSION 3.5...3.16)

project(boost_random VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)

add_library(boost_random
src/random_device.cpp
)
option(Boost_RANDOM_ENABLE_RANDOM_DEVICE "Build boost::random_device" ON)

if(Boost_RANDOM_ENABLE_RANDOM_DEVICE)
add_library(boost_random
src/random_device.cpp
)
set(_populate PUBLIC)
else()
add_library(boost_random INTERFACE)
set(_populate INTERFACE)
endif()

add_library(Boost::random ALIAS boost_random)

target_include_directories(boost_random PUBLIC include)
target_include_directories(boost_random ${_populate} include)

target_link_libraries(boost_random
PUBLIC
${_populate}
Boost::array
Boost::assert
Boost::config
Expand All @@ -32,18 +40,20 @@ target_link_libraries(boost_random
Boost::utility
)

target_compile_features(boost_random PUBLIC cxx_std_11)
target_compile_features(boost_random ${_populate} cxx_std_11)

target_compile_definitions(boost_random
PUBLIC BOOST_RANDOM_NO_LIB
${_populate} BOOST_RANDOM_NO_LIB
# Source files already define BOOST_RANDOM_SOURCE
# PRIVATE BOOST_RANDOM_SOURCE
)

if(BUILD_SHARED_LIBS)
target_compile_definitions(boost_random PUBLIC BOOST_RANDOM_DYN_LINK)
else()
target_compile_definitions(boost_random PUBLIC BOOST_RANDOM_STATIC_LINK)
if(Boost_RANDOM_ENABLE_RANDOM_DEVICE)
if(BUILD_SHARED_LIBS)
target_compile_definitions(boost_random PUBLIC BOOST_RANDOM_DYN_LINK)
else()
target_compile_definitions(boost_random PUBLIC BOOST_RANDOM_STATIC_LINK)
endif()
endif()

if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
Expand Down

0 comments on commit d31c6c2

Please sign in to comment.