Skip to content

Commit

Permalink
Re-organised the build of the external projects.
Browse files Browse the repository at this point in the history
Switched all of them to be built using FetchContent instead of
using git submodules.

Added an external for VecMem directly, so the project would not
need to rely on algebra-plugins to get access to that external.

Wrote a custom configuration for installing the dfe headers together
with the project. Such that it would become possible to export the
targets of this project eventually as well.

Updated all components to use the externals through their "exported names".
  • Loading branch information
krasznaa committed Oct 29, 2021
1 parent 08db24a commit c2aca21
Show file tree
Hide file tree
Showing 25 changed files with 387 additions and 92 deletions.
15 changes: 0 additions & 15 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,15 +0,0 @@
[submodule "extern/googletest"]
path = extern/googletest
url = https://github.com/google/googletest.git
[submodule "extern/benchmark"]
path = extern/benchmark
url = https://github.com/google/benchmark.git
[submodule "extern/dfelibs"]
path = extern/dfelibs
url = https://github.com/acts-project/dfelibs.git
[submodule "extern/matplotplusplus"]
path = extern/matplotplusplus
url = https://github.com/alandefreitas/matplotplusplus.git
[submodule "extern/algebra-plugins"]
path = extern/algebra-plugins
url = https://github.com/acts-project/algebra-plugins.git
151 changes: 109 additions & 42 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,58 +1,127 @@
cmake_minimum_required(VERSION 3.11)

project(detray VERSION 0.1 LANGUAGES CXX)

option(CMAKE_WARN_DEPRECATED "Not warning for deprecation in cmake" Off)
enable_testing()

include(CMakeDependentOption)
# Detray library, part of the ACTS project (R&D line)
#
# (c) 2021 CERN for the benefit of the ACTS project
#
# Mozilla Public License Version 2.0

# Set up the project.
cmake_minimum_required( VERSION 3.11 )
project( detray VERSION 0.1 LANGUAGES CXX )

# CMake include(s).
include( CMakeDependentOption )
include( GNUInstallDirs )

# Explicitly set the output directory for the binaries. Such that if this
# project is included by another project, the main project's configuration would
# win out.
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY
"${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}" CACHE PATH
"Directory for the built binaries" )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY
"${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}" CACHE PATH
"Directory for the built libraries" )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY
"${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}" CACHE PATH
"Directory for the built static libraries" )

option(DETRAY_ARRAY_PLUGIN "Build std::array math plugin" On)
option(DETRAY_VECMEM_ARRAY_PLUGIN "Build vecmem::array math plugin" On)
option(DETRAY_EIGEN_PLUGIN "Build Eigen math plugin" On)
option(DETRAY_SMATRIX_PLUGIN "Build ROOT/SMatrix math plugin" Off)
option(DETRAY_VC_ALGEBRA_PLUGIN "Build vc based simd algebra math plugin" Off)
option(DETRAY_IO_CSV "Build CSV IO module" On)
option(DETRAY_IO_JSON "Build JSON IO module" On)
option(DETRAY_DISPLAY "Build matplot++ based display module" Off)
option(DETRAY_BUILD_CUDA "Build the CUDA sources included in detray" Off)
option(DETRAY_USE_VECMEM "Build with vecmem" On)

if(DETRAY_CUSTOM_SCALARTYPE)
message(STATUS "Building with custom scalar type: " ${DETRAY_CUSTOM_SCALARTYPE})
set(ALGEBRA_PLUGIN_CUSTOM_SCALARTYPE ${DETRAY_CUSTOM_SCALARTYPE})
endif()

if (DETRAY_USE_VECMEM)
set(ALGEBRA_PLUGIN_USE_VECMEM ON)
option( DETRAY_BUILD_TESTING "Build the (unit) tests of Detray"
TRUE )
option( DETRAY_BENCHMARKS "Enable benchmark tests" TRUE )

# Set up VecMem.
option( DETRAY_SETUP_VECMEM
"Set up the VecMem target(s) explicitly" TRUE )
option( DETRAY_USE_SYSTEM_VECMEM
"Pick up an existing installation of VecMem from the build environment"
FALSE )
if( DETRAY_SETUP_VECMEM )
if( DETRAY_USE_SYSTEM_VECMEM )
find_package( vecmem REQUIRED )
else()
add_subdirectory( extern/vecmem )
endif()
endif()

if (DETRAY_ARRAY_PLUGIN)
set(ALGEBRA_PLUGIN_INCLUDE_ARRAY ON)
# Set up Algebra Plugins.
option( DETRAY_SETUP_ALGEBRA_PLUGINS
"Set up the Algebra Plugins target(s) explicitly" TRUE )
option( DETRAY_USE_SYSTEM_ALGEBRA_PLUGINS
"Pick up an existing installation of Algebra Plugins from the build environment"
FALSE )
if( DETRAY_SETUP_ALGEBRA_PLUGINS )
if( DETRAY_USE_SYSTEM_ALGEBRA_PLUGINS )
find_package( algebra-plugins REQUIRED )
else()
add_subdirectory( extern/algebra-plugins )
endif()
endif()

if (DETRAY_VECMEM_ARRAY_PLUGIN)
set(ALGEBRA_PLUGIN_INCLUDE_VECMEM ON)
# Set up dfelibs.
option( DETRAY_SETUP_DFELIBS
"Set up the dfelibs target(s) explicitly" TRUE )
option( DETRAY_USE_SYSTEM_DFELIBS
"Pick up an existing installation of dfelibs from the build environment"
FALSE )
if( DETRAY_SETUP_DFELIBS )
if( DETRAY_USE_SYSTEM_DFELIBS )
find_package( dfelibs REQUIRED )
else()
add_subdirectory( extern/dfelibs )
endif()
endif()

if (DETRAY_EIGEN_PLUGIN)
set(ALGEBRA_PLUGIN_INCLUDE_EIGEN ON)
find_package(Eigen3 REQUIRED)
include_directories(SYSTEM ${EIGEN3_INCLUDE_DIRS})
# Set up Matplot++.
option( DETRAY_SETUP_MATPLOTPP
"Set up the Matplot++ target(s) explicitly" FALSE )
option( DETRAY_USE_SYSTEM_MATPLOTPP
"Pick up an existing installation of Matplot++ from the build environment"
FALSE )
if( DETRAY_SETUP_MATPLOTPP )
if( DETRAY_USE_SYSTEM_MATPLOTPP )
find_package( Matplot++ REQUIRED )
else()
add_subdirectory( extern/matplotplusplus )
endif()
endif()

if (DETRAY_SMATRIX_PLUGIN)
set(ALGEBRA_PLUGIN_INCLUDE_SMATRIX ON)
find_package(ROOT REQUIRED COMPONENTS MathCore)
include_directories(SYSTEM ${ROOT_INCLUDE_DIRS})
# Set up GoogleTest.
option( DETRAY_SETUP_GOOGLETEST
"Set up the GoogleTest target(s) explicitly" TRUE )
option( DETRAY_USE_SYSTEM_GOOGLETEST
"Pick up an existing installation of GoogleTest from the build environment"
FALSE )
if( DETRAY_SETUP_GOOGLETEST )
if( DETRAY_USE_SYSTEM_GOOGLETEST )
find_package( GTest REQUIRED )
else()
add_subdirectory( extern/googletest )
endif()
endif()

if (DETRAY_VC_ALGEBRA_PLUGIN)
set(ALGEBRA_PLUGIN_INCLUDE_VC ON)
# Set up Google Benchmark.
option( DETRAY_SETUP_BENCHMARK
"Set up the Google Benchmark target(s) explicitly" TRUE )
option( DETRAY_USE_SYSTEM_BENCHMARK
"Pick up an existing installation of Google Benchmark from the build environment"
FALSE )
if( DETRAY_SETUP_BENCHMARK )
if( DETRAY_USE_SYSTEM_BENCHMARK )
find_package( benchmark REQUIRED )
else()
add_subdirectory( extern/benchmark )
endif()
endif()

option(DETRAY_UNIT_TESTS "Enable unit tests" On)
option(DETRAY_BENCHMARKS "Enable benchmark tests" On)
cmake_dependent_option(DETRAY_BENCHMARKS_MULTITHREAD "Enable multithreaded benchmarks" Off "DETRAY_BENCHMARKS" Off)
if(DETRAY_BENCHMARKS_MULTITHREAD)
message(STATUS "Using multithreaded benchmarks")
Expand All @@ -63,13 +132,6 @@ endif()

set(CMAKE_CXX_STANDARD 17)

set(CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/include)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_INSTALL_PREFIX}/lib)
set(CMAKE_INSTALL_LIBDIR ${CMAKE_INSTALL_PREFIX}/lib)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")

# Set GPU-related options
if(DETRAY_BUILD_CUDA)
set( CMAKE_CUDA_STANDARD 17 CACHE STRING "The (CUDA) C++ standard to use" )
Expand All @@ -78,10 +140,15 @@ endif()

add_subdirectory(apps)
add_subdirectory(core)
add_subdirectory(extern)
add_subdirectory(plugins)
add_subdirectory(io)
add_subdirectory(tests)

# Set up the test(s).
include( CTest )
if( BUILD_TESTING AND DETRAY_BUILD_TESTING )
add_subdirectory( tests )
endif()

if (DETRAY_DISPLAY)
add_subdirectory(display)
endif()
2 changes: 1 addition & 1 deletion display/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ target_include_directories(detray_display
$<INSTALL_INTERFACE:include>
)

target_link_libraries(detray_display INTERFACE detray::core matplot)
target_link_libraries(detray_display INTERFACE detray::core Matplot++::matplot)

install(
DIRECTORY include/style
Expand Down
18 changes: 0 additions & 18 deletions extern/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion extern/algebra-plugins
Submodule algebra-plugins deleted from 8e093e
43 changes: 43 additions & 0 deletions extern/algebra-plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Detray library, part of the ACTS project (R&D line)
#
# (c) 2021 CERN for the benefit of the ACTS project
#
# Mozilla Public License Version 2.0

# CMake include(s).
cmake_minimum_required( VERSION 3.14 )
include( FetchContent )

# Tell the user what's happening.
message( STATUS "Building Algebra Plugins as part of the Detray project" )

# Declare where to get Algebra Plugins from.
FetchContent_Declare( AlgebraPlugins
GIT_REPOSITORY "https://github.com/krasznaa/algebra-plugins.git"
GIT_TAG "e6245fcab63a2f26581fabaf9a31f78a6dd7d3d3" )

# Options used in the build of Algebra Plugins.
set( ALGEBRA_PLUGIN_BUILD_TESTING FALSE CACHE BOOL
"Turn off the build of the Algebra Plugins unit tests" )
set( ALGEBRA_PLUGIN_INCLUDE_ARRAY TRUE CACHE BOOL
"Turn on the build of algebra::array" )
set( ALGEBRA_PLUGIN_INCLUDE_EIGEN TRUE CACHE BOOL
"Turn on the build of algebra::eigen" )
set( ALGEBRA_PLUGIN_INCLUDE_VC TRUE CACHE BOOL
"Turn on the build of algebra::vc_array" )
set( ALGEBRA_PLUGIN_INCLUDE_VECMEM TRUE CACHE BOOL
"Turn on the build of algebra::vecmem_array" )

set( ALGEBRA_PLUGIN_SETUP_EIGEN3 TRUE CACHE BOOL
"Have Algebra Plugins set up Eigen3 for itself" )
set( ALGEBRA_PLUGIN_SETUP_VC TRUE CACHE BOOL
"Have Algebra Plugins set up Vc for itself" )
set( ALGEBRA_PLUGIN_USE_SYSTEM_VC FALSE CACHE BOOL
"Have Algebra Plugins build Vc itself" )
set( ALGEBRA_PLUGIN_SETUP_VECMEM FALSE CACHE BOOL
"Do not set up VecMem in Algebra Plugins" )
set( ALGEBRA_PLUGIN_SETUP_GOOGLETEST FALSE CACHE BOOL
"Do not set up GoogleTest in Algebra Plugins" )

# Get it into the current directory.
FetchContent_MakeAvailable( AlgebraPlugins )
4 changes: 4 additions & 0 deletions extern/algebra-plugins/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Build Recipe for Algebra Plugins

This directory holds a build recipe for the
[algebra-plugins](https://github.com/acts-project/algebra-plugins) project.
1 change: 0 additions & 1 deletion extern/benchmark
Submodule benchmark deleted from bf585a
30 changes: 30 additions & 0 deletions extern/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Detray library, part of the ACTS project (R&D line)
#
# (c) 2021 CERN for the benefit of the ACTS project
#
# Mozilla Public License Version 2.0

# CMake include(s).
cmake_minimum_required( VERSION 3.11 )
include( FetchContent )

# Tell the user what's happening.
message( STATUS "Building Google Benchmark as part of the Detray project" )

# Declare where to get Google Benchmark from.
FetchContent_Declare( Benchmark
URL "https://github.com/google/benchmark/archive/refs/tags/v1.6.0.tar.gz"
URL_MD5 "a7cb118b00430e22cb16774a28fce7ec" )

# Options used in the build of Google Benchmark.
set( BENCHMARK_ENABLE_TESTING OFF CACHE BOOL
"Turn off the tests in Google Benchmark" )

# Get it into the current directory.
FetchContent_Populate( Benchmark )
add_subdirectory( "${benchmark_SOURCE_DIR}" "${benchmark_BINARY_DIR}"
EXCLUDE_FROM_ALL )

# Set up an alias for the Google Benchmark target with the same name that it
# has when we find it pre-installed.
add_library( benchmark::benchmark ALIAS benchmark )
10 changes: 10 additions & 0 deletions extern/benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Google Benchmark Build Instructions

This subdirectory holds instructions for building
[benchmark](https://github.com/google/benchmark) as part of this project.
This is meant to come in handy for building the project's benchmarks in
environments which do not provide Google Branchmark themselves.

Note that since Google Benchmark is only needed for the tests of this project,
which are not installed together with the project, Google Benchmark is not
installed together with the project either.
1 change: 0 additions & 1 deletion extern/dfelibs
Submodule dfelibs deleted from 28c0ee
54 changes: 54 additions & 0 deletions extern/dfelibs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Detray library, part of the ACTS project (R&D line)
#
# (c) 2021 CERN for the benefit of the ACTS project
#
# Mozilla Public License Version 2.0

# CMake include(s).
cmake_minimum_required( VERSION 3.11 )
include( FetchContent )

# Tell the user what's happening.
message( STATUS "Building dfelibs as part of the Detray project" )

# Declare where to get dfelibs from.
FetchContent_Declare( dfelibs
URL "https://github.com/msmk0/dfelibs/archive/refs/tags/v20200416.tar.gz"
URL_MD5 "d762f22a92d6a1aa6f88b3d48d426bad" )

# Get it into the current directory.
FetchContent_Populate( dfelibs )

# Set up a proper target and installation for the dfelibs headers. One that
# could be used correctly in the exported target(s) of Detray.
add_library( dfelibs INTERFACE )
target_include_directories( dfelibs INTERFACE
$<BUILD_INTERFACE:${dfelibs_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> )
add_library( dfelibs::dfelibs ALIAS dfelibs )
install( DIRECTORY "${dfelibs_SOURCE_DIR}/dfe"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" )
install( TARGETS dfelibs
EXPORT dfelibs-exports )

include( CMakePackageConfigHelpers )
set( CMAKE_INSTALL_CMAKEDIR
"${CMAKE_INSTALL_LIBDIR}/cmake/dfelibs-20200416" )
install( EXPORT dfelibs-exports
NAMESPACE "dfelibs::"
FILE "dfelibs-config-targets.cmake"
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" )
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/dfelibs-config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/dfelibs-config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_CMAKEDIR
NO_CHECK_REQUIRED_COMPONENTS_MACRO )
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/dfelibs-config-version.cmake"
VERSION "20200416"
COMPATIBILITY "AnyNewerVersion" )
install( FILES
"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/dfelibs-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/dfelibs-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" )
4 changes: 4 additions & 0 deletions extern/dfelibs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Build Recipe for dfelibs

This directory holds a simple build recipe for the
[dfelibs](https://github.com/msmk0/dfelibs) project.
Loading

0 comments on commit c2aca21

Please sign in to comment.