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

Feature/update cmake #63

Merged
merged 5 commits into from
Oct 16, 2023
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
58 changes: 38 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
########################################################################
# Preamble
########################################################################

cmake_minimum_required( VERSION 3.14 )
project( scion LANGUAGES CXX )

set( subproject OFF )
if( DEFINED PROJECT_NAME )
set( subproject ON )
endif()

project( scion
VERSION 0.1.0
LANGUAGES CXX
)

include( CTest )
include( CMakeDependentOption )
include( GNUInstallDirs )

########################################################################
# Project-wide setup
Expand All @@ -11,18 +25,16 @@ project( scion LANGUAGES CXX )
set( CMAKE_CXX_STANDARD 17 )
set( CMAKE_CXX_STANDARD_REQUIRED YES )

option( scion.tests "Build the scion unit tests" OFF )
option( scion.python "Build scion python bindings" ON )
option( strict_compile
"Treat all warnings as errors." ON
)

# Compile flags
set( common_flags "-Wall" "-Wextra" "-Wpedantic" )
set( strict_flags "-Werror" )
set( release_flags "-O3" )
set( debug_flags "-O0" "-g" )

cmake_dependent_option(
scion.tests
"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}" OFF
)

########################################################################
# Dependencies
Expand Down Expand Up @@ -55,21 +67,27 @@ endif()
# scion : library
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

include_directories( src/ )

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

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# scion : python bindings
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

if( scion.python )

FetchContent_MakeAvailable( pybind11 )

pybind11_add_module( scion.python
python/src/scion.python.cpp
python/src/interpolation.python.cpp
Expand Down Expand Up @@ -110,7 +128,7 @@ if( scion.python )
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)
set_target_properties( scion.python PROPERTIES POSITION_INDEPENDENT_CODE ON )

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

Expand Down
5 changes: 1 addition & 4 deletions cmake/develop_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ include( FetchContent )

FetchContent_Declare( eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG 3.4.0
GIT_TAG d0bfdc1658ca0b4c659fd3702c351d2c2cdc876c # 3.4.1 branch on July 26, 2023
GIT_SHALLOW TRUE
)
set( BUILD_TESTING CACHE BOOL OFF )

FetchContent_Declare( spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog
Expand Down Expand Up @@ -38,6 +37,4 @@ FetchContent_Declare( pybind11
FetchContent_MakeAvailable(
eigen
spdlog
Catch2
pybind11
)
5 changes: 1 addition & 4 deletions cmake/release_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ FetchContent_Declare( Catch2

FetchContent_Declare( eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG 3147391d946bb4b6c68edd901f2add6ac1f31f8c # tag: 3.4.0
GIT_TAG d0bfdc1658ca0b4c659fd3702c351d2c2cdc876c # 3.4.1 branch on July 26, 2023
)
set( BUILD_TESTING CACHE BOOL OFF )

FetchContent_Declare( pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11
Expand All @@ -32,8 +31,6 @@ set( SPDLOG_BUILD_PIC CACHE INTERNAL BOOL ON )
#######################################################################

FetchContent_MakeAvailable(
Catch2
eigen
pybind11
spdlog
)
9 changes: 8 additions & 1 deletion cmake/unit_testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
# Setup
#######################################################################

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

FetchContent_MakeAvailable( Catch2 )

function( add_cpp_test name source )

set( test_name "scion.${name}.test" )
Expand All @@ -13,6 +15,11 @@ function( add_cpp_test name source )
target_link_libraries( ${test_name} PRIVATE scion )
target_link_libraries( ${test_name} PRIVATE Catch2::Catch2WithMain )

file( GLOB resources "resources/*" )
foreach( resource ${resources} )
file( COPY "${resource}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}" )
endforeach()

endfunction()

#######################################################################
Expand Down