Skip to content

Commit

Permalink
Merge pull request #38 from Pressio/37-simplify-cmake
Browse files Browse the repository at this point in the history
#37: Simplify CMake
  • Loading branch information
fnrizzi authored Feb 27, 2025
2 parents bf75c94 + 05be89d commit 5074f92
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 72 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci-baseline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ jobs:
-D CMAKE_C_COMPILER=$CC \
-D CMAKE_CXX_COMPILER=$CXX \
-D CMAKE_CXX_FLAGS='-Wall -Werror' \
-D CMAKE_INSTALL_PREFIX:PATH=../install \
-D CMAKE_VERBOSE_MAKEFILE:BOOL=ON \
${{ matrix.cmake_extra_args }} \
-D PRESSIO_OPS_ENABLE_TESTS:BOOL=ON \
Expand All @@ -72,7 +71,7 @@ jobs:
- name: Build
run: |
cmake --build builddir --target install
cmake --build builddir
- name: Run tests
working-directory: builddir/tests
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/ci-kokkos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ jobs:
-D CMAKE_C_COMPILER=$CC \
-D CMAKE_CXX_COMPILER=$CXX \
-D CMAKE_CXX_FLAGS='-Wall -Werror' \
-D CMAKE_INSTALL_PREFIX:PATH=../install \
-D CMAKE_VERBOSE_MAKEFILE:BOOL=ON \
-D PRESSIO_ENABLE_TPL_KOKKOS:BOOL=ON \
-D Kokkos_ROOT=/kokkos/install \
Expand All @@ -56,7 +55,7 @@ jobs:
- name: Build
run: |
cmake --build builddir --target install
cmake --build builddir
- name: Run tests
working-directory: builddir/tests
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/ci-trilinos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@ jobs:
-D PRESSIO_ENABLE_TPL_KOKKOS:BOOL=ON \
-D EIGEN_INCLUDE_DIR=/eigen/eigen-${{ env.eigen_version }} \
-D Trilinos_DIR=${{ env.trilinos_dir }}/lib/cmake/Trilinos \
-D CMAKE_INSTALL_PREFIX:PATH=../install \
-D CMAKE_CXX_FLAGS='-Wall'
- name: Build
run: cmake --build builddir -j $num_cpus --target install
run: cmake --build builddir -j $num_cpus

- name: Test
working-directory: builddir
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.vscode
generated_docs
build
install
57 changes: 2 additions & 55 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,63 +1,10 @@
cmake_minimum_required(VERSION 3.18.0 FATAL_ERROR)
project(pressio C CXX)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(colors)


# versioning
#=====================================================================
# adapted from Eigen
file(READ "${PROJECT_SOURCE_DIR}/include/pressio/ops_macros.hpp" _pressio_ops_macros)
string(REGEX MATCH "define[ \t]+PRESSIO_MAJOR_VERSION[ \t]+([0-9]+)" _major_version_match "${_pressio_ops_macros}")
set(PRESSIO_MAJOR_VERSION "${CMAKE_MATCH_1}")

string(REGEX MATCH "define[ \t]+PRESSIO_MINOR_VERSION[ \t]+([0-9]+)" _minor_version_match "${_pressio_ops_macros}")
set(PRESSIO_MINOR_VERSION "${CMAKE_MATCH_1}")

string(REGEX MATCH "define[ \t]+PRESSIO_PATCH_VERSION[ \t]+([0-9]+)" _patch_version_match "${_pressio_ops_macros}")
set(PRESSIO_PATCH_VERSION "${CMAKE_MATCH_1}")

set(PRESSIO_VERSION_NUMBER ${PRESSIO_MAJOR_VERSION}.${PRESSIO_MINOR_VERSION}.${PRESSIO_PATCH_VERSION})
message("${Magenta}>> PRESSIO-OPS: version = ${PRESSIO_VERSION_NUMBER} ${ColourReset}")


# c++ standard
#=====================================================================
if (NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()

message("${Magenta}>> CMAKE_CXX_STANDARD is set to ${CMAKE_CXX_STANDARD} ${ColourReset}")

if(CMAKE_CXX_STANDARD STREQUAL "17"
OR CMAKE_CXX_STANDARD STREQUAL "20")
if(NOT "cxx_std_${CMAKE_CXX_STANDARD}" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
message(FATAL_ERROR "Compiler does not support C++${CMAKE_CXX_STANDARD}. This is required.")
endif()
endif()

# install headers
#=====================================================================
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

install(
DIRECTORY include/pressio
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
project(pressioops C CXX)

# tests
#=====================================================================
option(PRESSIO_OPS_ENABLE_TESTS "Enable testing for pressio-ops" OFF)
if(PRESSIO_OPS_ENABLE_TESTS)
add_library(pressioops INTERFACE)

target_include_directories(
pressioops INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

enable_testing()
add_subdirectory(tests)
endif()
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.. role:: raw-html-m2r(raw)
:format: html

Installation and Dependencies
Configuration and Dependencies
=============================

Installation
Configuration
------------

.. tip::
Expand Down
4 changes: 2 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Each component (level) of the stack depends on the ones below it.
Get Started
-----------

* `Install <installation.html>`_: (currently) header-only, should be trivial
* `Configuration <configuration.html>`_: (currently) header-only, should be trivial


License and Citation
Expand All @@ -102,7 +102,7 @@ open an issue on `github <https://github.com/Pressio/pressio>`_.
:maxdepth: 1
:hidden:

installation
configuration

.. toctree::
:caption: API
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include(CMakePrintHelpers)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(macrosForCreatingUnitTests)
include(options)
include(colors)

# ---------------------------------
# 1. find or get gtest
Expand Down
File renamed without changes.
9 changes: 6 additions & 3 deletions tests/cmake/macrosForCreatingUnitTests.cmake
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@

macro(add_serial_utest TESTNAME)
add_executable(${TESTNAME} ${ARGN} ${GTESTMAINSDIR}/gTestMain_serial.cc)
target_link_libraries(${TESTNAME} pressioops gtest_main)
target_include_directories(${TESTNAME} PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_link_libraries(${TESTNAME} gtest_main)
add_test(NAME ${TESTNAME} COMMAND ${TESTNAME})
endmacro()
#=====================================================================

macro(add_serial_utest_kokkos TESTNAME)
add_executable(${TESTNAME} ${ARGN} ${GTESTMAINSDIR}/gTestMain_kokkos.cc)
target_link_libraries(${TESTNAME} ${KOKKOS_LIBS} pressioops gtest_main)
target_include_directories(${TESTNAME} PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_link_libraries(${TESTNAME} ${KOKKOS_LIBS} gtest_main)
add_test(NAME ${TESTNAME} COMMAND ${TESTNAME})
endmacro()
#=====================================================================

macro(add_utest_mpi TESTNAME gMAIN nRANKS)
set(testNameFinal ${TESTNAME}_np${nRANKS})
add_executable(${testNameFinal} ${ARGN} ${GTESTMAINSDIR}/${gMAIN}.cc)
target_link_libraries(${testNameFinal} ${MPI_CXX_LIBRARIES} pressioops gtest_main)
target_include_directories(${testNameFinal} PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_link_libraries(${testNameFinal} ${MPI_CXX_LIBRARIES} gtest_main)
add_test(
NAME ${testNameFinal}
COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${nRANKS}
Expand Down
21 changes: 18 additions & 3 deletions tests/cmake/options.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@

option(PRESSIO_ENABLE_CXX17 "Enable C++17" OFF)
# minimum required is 17
add_definitions(-DPRESSIO_ENABLE_CXX17)
# c++ standard
#=====================================================================
if (NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()

message("${Magenta}>> CMAKE_CXX_STANDARD is set to ${CMAKE_CXX_STANDARD} ${ColourReset}")

if(CMAKE_CXX_STANDARD STREQUAL "17"
OR CMAKE_CXX_STANDARD STREQUAL "20")
if(NOT "cxx_std_${CMAKE_CXX_STANDARD}" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
message(FATAL_ERROR "Compiler does not support C++${CMAKE_CXX_STANDARD}. This is required.")
endif()
endif()

# tpls
#=====================================================================
option(PRESSIO_ENABLE_TPL_EIGEN "Enable Eigen TPL" OFF)
option(PRESSIO_ENABLE_TPL_TRILINOS "Enable Trilinos TPL" OFF)
option(PRESSIO_ENABLE_TPL_KOKKOS "Enable Kokkos TPL" OFF)
Expand Down

0 comments on commit 5074f92

Please sign in to comment.