Skip to content

Commit

Permalink
Switch back to C++20 and use modern set_compile_features to set minim…
Browse files Browse the repository at this point in the history
…um C++ standard (#844)

* [cmake] Replace global CMAKE_CXX_STAND property by compile feature

* Update CMakeLists.txt

* Switch back to C++20.

* Also remove from Python.

---------

Co-authored-by: Simon Praetorius <[email protected]>
Co-authored-by: Jack S. Hale <[email protected]>
  • Loading branch information
3 people authored Jul 10, 2024
1 parent 98e3203 commit 64ad423
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 40 deletions.
23 changes: 5 additions & 18 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@ endif()

include(FeatureSummary)

# Set the C++ standard
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
# Only newer CMake passes non-standard Intel C++23 flag.
# see https://github.com/FEniCS/basix/pull/838
# When Intel C++23 support meets ISO standard this can be removed.
cmake_minimum_required(3.26)
endif()

# Options
option(BUILD_SHARED_LIBS "Build Basix with shared libraries." ON)
add_feature_info(BUILD_SHARED_LIBS BUILD_SHARED_LIBS "Build Basix with shared libraries.")
Expand All @@ -51,8 +39,11 @@ endif()
# Source files
add_library(basix)

# Set the C++ standard
target_compile_features(basix PUBLIC cxx_std_20)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/basix/version.h.in basix/version.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(basix PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

set(HEADERS_basix
${CMAKE_CURRENT_SOURCE_DIR}/basix/cell.h
Expand Down Expand Up @@ -115,10 +106,6 @@ target_include_directories(basix PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}>")

# TODO: remove after issue https://github.com/FEniCS/basix/issues/842 is resolved
target_compile_definitions(basix PRIVATE MDSPAN_USE_PAREN_OPERATOR=1)
target_compile_definitions(basix PRIVATE MDSPAN_USE_BRACKET_OPERATOR=0)

target_link_libraries(basix PRIVATE BLAS::BLAS)
target_link_libraries(basix PRIVATE LAPACK::LAPACK)

Expand All @@ -131,7 +118,7 @@ endif()

if (MSVC)
# M_PI etc. are not not in the standard-compliant MSVC headers.
add_compile_definitions(_USE_MATH_DEFINES)
target_compile_definitions(basix PUBLIC _USE_MATH_DEFINES)
endif()


Expand Down
6 changes: 1 addition & 5 deletions demo/cpp/demo_create_and_tabulate/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.16)
project(demo_create_and_tabulate LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

Expand All @@ -21,10 +21,6 @@ find_package(Basix REQUIRED CONFIG HINTS ${BASIX_PY_DIR})

add_executable(${PROJECT_NAME} main.cpp)

# TODO: remove after issue https://github.com/FEniCS/basix/issues/842 is resolved
target_compile_definitions(${PROJECT_NAME} PRIVATE MDSPAN_USE_PAREN_OPERATOR=1)
target_compile_definitions(${PROJECT_NAME} PRIVATE MDSPAN_USE_BRACKET_OPERATOR=0)

if (BASIX_PY_DIR AND IS_DIRECTORY ${BASIX_PY_DIR}/../fenics_basix.libs)
set_target_properties(${PROJECT_NAME} PROPERTIES BUILD_RPATH ${BASIX_PY_DIR}/../fenics_basix.libs)
set_target_properties(${PROJECT_NAME} PROPERTIES INSTALL_RPATH ${BASIX_PY_DIR}/../fenics_basix.libs)
Expand Down
6 changes: 1 addition & 5 deletions demo/cpp/demo_dof_transformations/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.16)
project(demo_dof_transformations LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

Expand All @@ -21,10 +21,6 @@ find_package(Basix REQUIRED CONFIG HINTS ${BASIX_PY_DIR})

add_executable(${PROJECT_NAME} main.cpp)

# TODO: remove after issue https://github.com/FEniCS/basix/issues/842 is resolved
target_compile_definitions(${PROJECT_NAME} PRIVATE MDSPAN_USE_PAREN_OPERATOR=1)
target_compile_definitions(${PROJECT_NAME} PRIVATE MDSPAN_USE_BRACKET_OPERATOR=0)

if (BASIX_PY_DIR AND IS_DIRECTORY ${BASIX_PY_DIR}/../fenics_basix.libs)
set_target_properties(${PROJECT_NAME} PROPERTIES BUILD_RPATH ${BASIX_PY_DIR}/../fenics_basix.libs)
set_target_properties(${PROJECT_NAME} PROPERTIES INSTALL_RPATH ${BASIX_PY_DIR}/../fenics_basix.libs)
Expand Down
13 changes: 1 addition & 12 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@ endif()

project(basix_nanobind VERSION "0.9.0.0" LANGUAGES CXX)

# Set C++ standard
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
# Only newer CMake passes non-standard Intel C++23 flag.
# see https://github.com/FEniCS/basix/pull/838
# When Intel C++23 support meets ISO standard this can be removed.
cmake_minimum_required(3.26)
endif()

if (WIN32)
# Windows requires all symbols to be manually exported.
# This flag exports all symbols automatically, as in Unix.
Expand All @@ -43,6 +31,7 @@ find_package(nanobind CONFIG REQUIRED)

# Create the binding library
nanobind_add_module(_basixcpp wrapper.cpp)
target_compile_definitions(_basixcpp PRIVATE cxx_std_20)
target_link_libraries(_basixcpp PRIVATE Basix::basix)

# Add strict compiler flags
Expand Down

0 comments on commit 64ad423

Please sign in to comment.