Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cmake checks for non-bundled random123 #1907

Merged
merged 2 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,26 @@ install(FILES mechanisms/generate_catalogue DESTINATION ${ARB_INSTALL_DATADIR} P
# External libraries in `ext` sub-directory: json, tinyopt and randon123.
# Creates interface libraries `ext-json`, `ext-tinyopt` and `ext-random123`

cmake_dependent_option(ARB_USE_BUNDLED_FMT "Use bundled FMT lib." ON "ARB_USE_BUNDLED_LIBS" OFF)

cmake_dependent_option(ARB_USE_BUNDLED_JSON "Use bundled Niels Lohmann's json library." ON "ARB_USE_BUNDLED_LIBS" OFF)
if(NOT ARB_USE_BUNDLED_JSON)
find_package(nlohmann_json)
set(json_library_name nlohmann_json::nlohmann_json)
else()
unset(nlohmann_json_DIR CACHE)
endif()

cmake_dependent_option(ARB_USE_BUNDLED_RANDOM123 "Use bundled Random123 lib." ON "ARB_USE_BUNDLED_LIBS" OFF)
add_library(ext-random123 INTERFACE)
if(NOT ARB_USE_BUNDLED_RANDOM123)
find_package(Random123 REQUIRED)
target_include_directories(ext-random123 INTERFACE ${RANDOM123_INCLUDE_DIR})
endif()

add_subdirectory(ext)

cmake_dependent_option(ARB_USE_BUNDLED_FMT "Use bundled FMT lib." ON "ARB_USE_BUNDLED_LIBS" OFF)
install(TARGETS ext-random123 EXPORT arbor-targets)

# Keep track of packages we need to add to the generated CMake config
# file for arbor.
Expand Down
23 changes: 23 additions & 0 deletions cmake/FindRandom123.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

# CMake find_package() Module for Random123 header-only C++ library
# https://github.com/DEShawResearch/random123
#
# Example usage:
#
# find_package(Random123)
#
# If successful the following variables will be defined
# RANDOM123_FOUND
# RANDOM123_INCLUDE_DIR

find_path(RANDOM123_INCLUDE_DIR Random123/threefry.h)

if(RANDOM123_INCLUDE_DIR)
set(RANDOM123_FOUND TRUE)
message(STATUS "Found Random123: ${RANDOM123_INCLUDE_DIR}")
endif()

if(RANDOM123_FIND_REQUIRED AND NOT RANDOM123_FOUND)
message(FATAL_ERROR "Required package Random123 not found")
endif()

17 changes: 11 additions & 6 deletions ext/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@ if(ARB_USE_BUNDLED_JSON)
set(json_library_name ext-json PARENT_SCOPE)
endif()

# Random123 (DE Shaw Research) counter-based random number generators (header-only)

if(ARB_USE_BUNDLED_RANDOM123)
check_git_submodule(random123 random123)
if(NOT random123_avail)
message(FATAL_ERROR "Required Random123 submodule is not available.")
endif()
target_include_directories(ext-random123 INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/random123/include)
message(STATUS "Using Random123 submodule: ${CMAKE_CURRENT_SOURCE_DIR}>/random123")
endif()

# tinyopt command line parsing libary (header-only).

add_library(ext-tinyopt INTERFACE)
target_include_directories(ext-tinyopt INTERFACE tinyopt/include)

# Random123 (DE Shaw Research) counter-based random number generators (header-only)

add_library(ext-random123 INTERFACE)
target_include_directories(ext-random123 INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>/random123/include)
install(TARGETS ext-random123 EXPORT arbor-targets)

# Google benchmark for microbenchmarks:

check_git_submodule(gbench google-benchmark)
Expand Down