Skip to content

Commit

Permalink
Merge pull request #82 from njoy/update/cmake
Browse files Browse the repository at this point in the history
Update/cmake
  • Loading branch information
whaeck authored Sep 30, 2024
2 parents 78c42ad + e31104e commit 9ab57dc
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 148 deletions.
168 changes: 102 additions & 66 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Preamble
########################################################################

cmake_minimum_required( VERSION 3.14 )
cmake_minimum_required( VERSION 3.27 )

set( subproject OFF )
if( DEFINED PROJECT_NAME )
Expand All @@ -27,53 +27,43 @@ set( CMAKE_CXX_STANDARD_REQUIRED YES )

cmake_dependent_option(
scion.tests
"Build the scion unit tests and integrate with ctest" ON
"BUILD_TESTING AND NOT ${subproject}" OFF
"Build the scion unit tests and integrate with ctest" ON
"BUILD_TESTING AND NOT ${subproject}" OFF
)

cmake_dependent_option(
scion.python
"Build scion python bindings" ON
"NOT ${subproject} OR DEFINED require.scion.python " OFF
)

option( scion.installation "Install ACEtk" ON )

########################################################################
# Dependencies
########################################################################

set( REPOSITORIES "release"
CACHE STRING
"Options for where to fetch repositories: develop, release, local"
)

message( STATUS "Using ${REPOSITORIES} repositories" )

if( REPOSITORIES STREQUAL "develop" )
include( cmake/develop_dependencies.cmake )

elseif( REPOSITORIES STREQUAL "release" )
include( cmake/release_dependencies.cmake )

elseif( REPOSITORIES STREQUAL "local" )
include( cmake/local_dependencies.cmake )

endif()

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/.cmake)
include( cmake/dependencies.cmake )

########################################################################
# Project targets
########################################################################

string( CONCAT prefix
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/src>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# scion : library
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

add_library( scion INTERFACE )
add_library( njoy::scion ALIAS scion )
target_include_directories( scion
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

target_include_directories( scion INTERFACE ${prefix} )

target_link_libraries( scion
INTERFACE
eigen
Expand All @@ -86,62 +76,108 @@ target_link_libraries( scion

if( scion.python )

FetchContent_MakeAvailable( pybind11 )

pybind11_add_module( scion.python
python/src/scion.python.cpp
python/src/interpolation.python.cpp
python/src/interpolation/interpolation.python.cpp
python/src/interpolation/InterpolationType.python.cpp
python/src/integration.python.cpp
python/src/integration/integration.python.cpp
python/src/integration/GaussLegendre.python.cpp
python/src/integration/GaussLobatto.python.cpp
python/src/linearisation.python.cpp
python/src/linearisation/MidpointSplit.python.cpp
python/src/linearisation/ToleranceConvergence.python.cpp
python/src/linearisation/Lineariser.python.cpp
python/src/math.python.cpp
python/src/math/clenshaw.python.cpp
python/src/math/compare.python.cpp
python/src/math/horner.python.cpp
python/src/math/newton.python.cpp
python/src/math/chebyshev.python.cpp
python/src/math/legendre.python.cpp
python/src/math/IntervalDomain.python.cpp
python/src/math/OpenDomain.python.cpp
python/src/math/LinearLinearTable.python.cpp
python/src/math/HistogramTable.python.cpp
python/src/math/LogLogTable.python.cpp
python/src/math/LogLinearTable.python.cpp
python/src/math/LinearLogTable.python.cpp
python/src/math/InterpolationTable.python.cpp
python/src/math/ChebyshevSeries.python.cpp
python/src/math/ChebyshevApproximation.python.cpp
python/src/math/LegendreSeries.python.cpp
python/src/math/PolynomialSeries.python.cpp
python/src/math/AnalyticalIntegrator.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/scion.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/interpolation.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/interpolation/interpolation.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/interpolation/InterpolationType.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/integration.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/integration/integration.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/integration/GaussLegendre.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/integration/GaussLobatto.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/linearisation.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/linearisation/MidpointSplit.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/linearisation/ToleranceConvergence.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/linearisation/Lineariser.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/math.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/math/clenshaw.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/math/compare.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/math/horner.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/math/newton.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/math/chebyshev.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/math/legendre.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/math/IntervalDomain.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/math/OpenDomain.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/math/LinearLinearTable.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/math/HistogramTable.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/math/LogLogTable.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/math/LogLinearTable.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/math/LinearLogTable.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/math/InterpolationTable.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/math/ChebyshevSeries.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/math/ChebyshevApproximation.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/math/LegendreSeries.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/math/PolynomialSeries.python.cpp
${CMAKE_CURRENT_SOURCE_DIR}/python/src/math/AnalyticalIntegrator.python.cpp
)

target_link_libraries( scion.python PRIVATE scion )
target_include_directories( scion.python PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/python/src )
target_compile_options( scion.python PRIVATE "-fvisibility=hidden" )
target_compile_options( scion.python PRIVATE -fvisibility=hidden )
set_target_properties( scion.python PROPERTIES OUTPUT_NAME scion )
set_target_properties( scion.python PROPERTIES COMPILE_DEFINITIONS "PYBIND11" )
set_target_properties( scion.python PROPERTIES POSITION_INDEPENDENT_CODE ON )

message( STATUS "Building scion's python API" )

list( APPEND SCION_PYTHONPATH ${CMAKE_CURRENT_BINARY_DIR} )
set( scion_PYTHONPATH "${CMAKE_CURRENT_BINARY_DIR}" )

if( scion.tests )
include( cmake/unit_testing_python.cmake )
endif()

endif()

if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
if( scion.tests )
include( cmake/unit_testing.cmake )
endif()
if( scion.tests )
include( cmake/unit_testing.cmake )
endif()

#######################################################################
# Installation
#######################################################################

if(scion.installation)
include(CMakePackageConfigHelpers)

install(TARGETS scion EXPORT scion-targets
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
)

install(EXPORT scion-targets
FILE "scion-targets.cmake"
NAMESPACE njoy::
DESTINATION share/cmake/scion
)

install(DIRECTORY src/
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING PATTERN "*.hpp"
PATTERN "*test*" EXCLUDE
)

string(TOLOWER scion lowercasePackageName)

write_basic_package_version_file("${lowercasePackageName}-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion)

configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/${lowercasePackageName}-config.cmake.in
${PROJECT_BINARY_DIR}/${lowercasePackageName}-config.cmake
INSTALL_DESTINATION share/cmake/scion
)

install(FILES
"${PROJECT_BINARY_DIR}/${lowercasePackageName}-config.cmake"
"${PROJECT_BINARY_DIR}/${lowercasePackageName}-config-version.cmake"
DESTINATION share/cmake/scion
)

if(NOT subproject)
set(CPACK_PACKAGE_VENDOR "Los Alamos National Laboratory")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
include(CPack)
endif()
endif()
42 changes: 42 additions & 0 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
cmake_minimum_required( VERSION 3.27 )
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/.cmake)
include( FetchContent )

FetchContent_Declare( tools
GIT_REPOSITORY ../../njoy/tools
GIT_TAG 392164c044dea641b7a42dc1a2e89da464289770 # tag: v0.4.0
)

FetchContent_Declare( eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG d0bfdc1658ca0b4c659fd3702c351d2c2cdc876c # 3.4.1 branch on July 26, 2023
)

#######################################################################
# Load dependencies
#######################################################################

if(scion.python)
FetchContent_Declare( pybind11
GIT_REPOSITORY ../../pybind/pybind11
GIT_TAG 5b0a6fc2017fcc176545afe3e09c9f9885283242 # tag: v2.10.4
)
FetchContent_MakeAvailable(
pybind11
)
endif()

if(scion.tests)
FetchContent_Declare( Catch2
GIT_REPOSITORY ../../catchorg/Catch2
GIT_TAG 3f0283de7a9c43200033da996ff9093be3ac84dc # tag: v3.3.2
)
FetchContent_MakeAvailable(
Catch2
)
endif()

FetchContent_MakeAvailable(
tools
eigen
)
38 changes: 0 additions & 38 deletions cmake/develop_dependencies.cmake

This file was deleted.

42 changes: 0 additions & 42 deletions cmake/release_dependencies.cmake

This file was deleted.

7 changes: 7 additions & 0 deletions cmake/scion-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include(CMakeFindDependencyMacro)

if (NOT TARGET njoy::tools)
find_dependency(tools)
endif()

include("${CMAKE_CURRENT_LIST_DIR}/scion-targets.cmake")
4 changes: 3 additions & 1 deletion cmake/unit_testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Setup
#######################################################################

message( STATUS "Adding scion unit testing" )
enable_testing()

FetchContent_MakeAvailable( Catch2 )
Expand All @@ -12,6 +11,7 @@ function( add_cpp_test name source )
set( test_name "scion.${name}.test" )
add_executable( ${test_name} ${source} )
add_test( NAME ${test_name} COMMAND ${test_name} )
set_target_properties( ${test_name} PROPERTIES COMPILE_DEFINITIONS "PYBIND11" )
target_link_libraries( ${test_name} PRIVATE scion )
target_link_libraries( ${test_name} PRIVATE Catch2::Catch2WithMain )

Expand All @@ -26,6 +26,8 @@ endfunction()
# Unit testing directories
#######################################################################

message( STATUS "Adding scion C++ unit testing" )

add_subdirectory( src/utility/IteratorView/test )

add_subdirectory( src/scion/verification/ranges/test )
Expand Down
2 changes: 1 addition & 1 deletion cmake/unit_testing_python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function( add_python_test name source )
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/python )
set_tests_properties( ${test_name}
PROPERTIES ENVIRONMENT
PYTHONPATH=${SCION_PYTHONPATH}:$ENV{PYTHONPATH})
PYTHONPATH=${scion_PYTHONPATH}:$ENV{PYTHONPATH})

endfunction()

Expand Down

0 comments on commit 9ab57dc

Please sign in to comment.