Skip to content

Commit

Permalink
Merge pull request #1361 from KrisThielemans/lib_C++_version
Browse files Browse the repository at this point in the history
Set C++ version for libraries
  • Loading branch information
KrisThielemans authored Feb 2, 2024
2 parents 5037f81 + 9cc0d1f commit 1f5b06f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
14 changes: 2 additions & 12 deletions src/cmake/SetC++Version.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# A macro to set the C++ version
# Based on https://stackoverflow.com/questions/10851247/how-to-activate-c-11-in-cmake

# Copyright (C) 2017, 2020 University College London
# Author Kris Thielemans
Expand All @@ -21,17 +20,8 @@ function(UseCXX VERSION)
endif()
endif()

if (CMAKE_VERSION VERSION_LESS "3.1")
message(WARNING "Your CMake version is older than v3.1. Attempting to set C++ version to ${VERSION} with compiler flags but this might fail. Please upgrade your CMake.")
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_EXTENSIONS)
set (CMAKE_CXX_FLAGS "-std=gnu++${VERSION} ${CMAKE_CXX_FLAGS}" PARENT_SCOPE)
else()
set (CMAKE_CXX_FLAGS "-std=c++${VERSION} ${CMAKE_CXX_FLAGS}" PARENT_SCOPE)
endif ()
else ()
set (CMAKE_CXX_STANDARD ${VERSION} PARENT_SCOPE)
set (CMAKE_CXX_STANDARD_REQUIRED ON PARENT_SCOPE)
endif ()
set (CMAKE_CXX_STANDARD ${VERSION} PARENT_SCOPE)
set (CMAKE_CXX_STANDARD_REQUIRED ON PARENT_SCOPE)

message(STATUS "Using C++ version ${VERSION}")
endfunction(UseCXX)
9 changes: 2 additions & 7 deletions src/cmake/stir_lib_target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@ target_include_directories(${dir} PUBLIC
$<BUILD_INTERFACE:${STIR_INCLUDE_DIR}>
$<INSTALL_INTERFACE:${STIR_INCLUDE_INSTALL_DIR}>)

# make sure that if you use STIR, the compiler will be set to at least C++11
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.8.0")
target_compile_features(${dir} PUBLIC cxx_std_11)
else()
# Older CMake didn't have cxx_std_11 yet, but using auto will presumably force it anyway
target_compile_features(${dir} PUBLIC cxx_auto_type)
endif()
# make sure that if you use STIR, the compiler will be set to what was set via UseCXX
target_compile_features(${dir} PUBLIC cxx_std_${CMAKE_CXX_STANDARD})
target_include_directories(${dir} PUBLIC ${Boost_INCLUDE_DIR})

SET_PROPERTY(TARGET ${dir} PROPERTY FOLDER "Libs")
Expand Down

0 comments on commit 1f5b06f

Please sign in to comment.