Skip to content

Commit

Permalink
Adds installation logic and updates cmake to use relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy Burke committed Jun 11, 2024
1 parent 368dbd9 commit 83f5206
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 46 deletions.
76 changes: 69 additions & 7 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 Down Expand Up @@ -35,6 +35,7 @@ cmake_dependent_option(
"Build tools python bindings" ON
"NOT ${subproject} OR DEFINED require.tools.python " OFF
)
option( tools.installation "Install njoy::tools" ON )

########################################################################
# Dependencies
Expand Down Expand Up @@ -69,11 +70,14 @@ endif()

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

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

target_include_directories( tools INTERFACE ${prefix} )

target_link_libraries( tools
INTERFACE
spdlog::spdlog
Expand All @@ -88,11 +92,10 @@ target_compile_definitions( tools INTERFACE -DNANORANGE_NO_STD_FORWARD_DECLARATI

if( tools.python )

FetchContent_MakeAvailable( pybind11 )

pybind11_add_module( tools.python
python/src/tools.python.cpp
)
add_library( njoy::tools.python ALIAS tools.python )

target_link_libraries( tools.python PRIVATE tools )
target_include_directories( tools.python PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/python/src )
Expand All @@ -116,3 +119,62 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
include( cmake/unit_testing.cmake )
endif()
endif()

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

if(tools.installation)
include(CMakePackageConfigHelpers)

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

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

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

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

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

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

if(NOT subproject)
set(CPACK_PACKAGE_VENDOR "Los Alamos National Laboratory")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
include(CPack)
endif()

if(tools.python)

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

endif()

endif()
55 changes: 34 additions & 21 deletions cmake/develop_dependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,40 +1,53 @@
cmake_minimum_required( VERSION 3.14 )
cmake_minimum_required( VERSION 3.27 )
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/.cmake)
include( FetchContent )

#######################################################################
# Declare project dependencies
#######################################################################

FetchContent_Declare( spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog
GIT_TAG v1.11.0
GIT_SHALLOW TRUE
)
set( SPDLOG_BUILD_PIC CACHE INTERNAL BOOL ON )

FetchContent_Declare( Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2
GIT_TAG v3.3.2
GIT_SHALLOW TRUE
)

FetchContent_Declare( pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11
GIT_TAG v2.10.4
FetchContent_Declare( FastFloat
GIT_REPOSITORY ../../fastfloat/fast_float
GIT_TAG v6.1.1
GIT_SHALLOW TRUE
)

FetchContent_Declare( fast_float
GIT_REPOSITORY https://github.com/fastfloat/fast_float
GIT_TAG v6.1.1
FetchContent_Declare( spdlog
GIT_REPOSITORY ../../gabime/spdlog
GIT_TAG v1.11.0
GIT_SHALLOW TRUE
)
set( SPDLOG_BUILD_PIC CACHE INTERNAL BOOL ON )
if (tools.installation)
set( SPDLOG_INSTALL CACHE INTERNAL BOOL ON )
else()
set( SPDLOG_INSTALL CACHE INTERNAL BOOL OFF )
endif()

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

FetchContent_MakeAvailable(
spdlog
fast_float
)
FastFloat
)

if (tools.tests)
FetchContent_Declare( Catch2
GIT_REPOSITORY ../../catchorg/catch2
GIT_TAG v3.3.2
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(Catch2)
endif()

if (tools.python)
FetchContent_Declare( pybind11
GIT_REPOSITORY ../../pybind/pybind11
GIT_TAG v2.10.4
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(pybind11)
endif()
45 changes: 29 additions & 16 deletions cmake/release_dependencies.cmake
Original file line number Diff line number Diff line change
@@ -1,36 +1,49 @@
cmake_minimum_required( VERSION 3.14 )
cmake_minimum_required( VERSION 3.27 )
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/.cmake)
include( FetchContent )

#######################################################################
# Declare project dependencies
#######################################################################

FetchContent_Declare( Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2
GIT_TAG 3f0283de7a9c43200033da996ff9093be3ac84dc # tag: v3.3.2
)

FetchContent_Declare( fast_float
GIT_REPOSITORY https://github.com/fastfloat/fast_float
FetchContent_Declare( FastFloat
GIT_REPOSITORY ../../fastfloat/fast_float
GIT_TAG f476bc713fda06fbd34dc621b466745a574b3d4c # tag: v6.1.1
)

FetchContent_Declare( pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11
GIT_TAG 5b0a6fc2017fcc176545afe3e09c9f9885283242 # tag: v2.10.4
)

FetchContent_Declare( spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog
GIT_REPOSITORY ../../gabime/spdlog
GIT_TAG ad0e89cbfb4d0c1ce4d097e134eb7be67baebb36 # tag: v1.11.0
)
set( SPDLOG_BUILD_PIC CACHE INTERNAL BOOL ON )

if (tools.installation)
set( SPDLOG_INSTALL CACHE INTERNAL BOOL ON )
else()
set( SPDLOG_INSTALL CACHE INTERNAL BOOL OFF )
endif()

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

FetchContent_MakeAvailable(
fast_float
FastFloat
spdlog
)

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

FetchContent_MakeAvailable(Catch2)
endif()

if (tools.python)
FetchContent_Declare( pybind11
GIT_REPOSITORY ../../pybind/pybind11
GIT_TAG 5b0a6fc2017fcc176545afe3e09c9f9885283242 # tag: v2.10.4
)
FetchContent_MakeAvailable(pybind11)
endif()
12 changes: 12 additions & 0 deletions cmake/tools-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
include(CMakeFindDependencyMacro)

if (NOT TARGET spdlog::spdlog)
find_dependency(spdlog)
endif()


if (NOT TARGET FastFloat::fast_float)
find_dependency(FastFloat)
endif()

include("${CMAKE_CURRENT_LIST_DIR}/tools-targets.cmake")
2 changes: 0 additions & 2 deletions cmake/unit_testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
message( STATUS "Adding tools unit testing" )
enable_testing()

FetchContent_MakeAvailable( Catch2 )

function( add_cpp_test name source )

set( test_name "tools.${name}.test" )
Expand Down

0 comments on commit 83f5206

Please sign in to comment.