Skip to content

Commit

Permalink
simplify logic, set standard at beginning
Browse files Browse the repository at this point in the history
use a macro for bob_set_cxx_standard to avoid passing PARENT_SCOPE to set calls
  • Loading branch information
cwsmith committed Oct 22, 2024
1 parent ede50a6 commit 9ff9c0e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
20 changes: 7 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ include(cmake/xsdk.cmake)

option(USE_XSDK_DEFAULTS "enable the XDSK v0.3.0 default configuration" NO)

#requre c++11 without extensions
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSION OFF)
if(NOT ENABLE_CGNS)
set(CMAKE_CXX_STANDARD 11)
endif()
bob_set_cxx_standard(11)

xsdk_begin_package()
bob_begin_package()
Expand All @@ -27,20 +22,22 @@ if(USE_XSDK_DEFAULTS)
xsdk_compiler_flags()
endif()

# require c++14
option(ENABLE_CGNS "Enable the CGNS reader: requires c++14 extensions" OFF)
message(STATUS "ENABLE_CGNS: ${ENABLE_CGNS}")
if(ENABLE_CGNS)
message(STATUS "enabling cxx14")
bob_set_cxx_standard(14)
endif()

# Set some default compiler flags that should always be used
if(NOT USE_XSDK_DEFAULTS)
bob_set_shared_libs()
bob_begin_cxx_flags()
bob_end_cxx_flags()
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}")
if(ENABLE_CGNS) #takes precedence over SCOREC_ENABLE_CXX11
message(STATUS "enabling cxx14")
if(ENABLE_CGNS)
bob_cxx14_flags()
elseif(SCOREC_ENABLE_CXX11)
else()
bob_cxx11_flags()
endif()
endif()
Expand Down Expand Up @@ -193,9 +190,6 @@ add_library(core INTERFACE)
target_link_libraries(core INTERFACE ${SCOREC_EXPORTED_TARGETS})
if(ENABLE_CGNS)
target_link_libraries(core INTERFACE ${CMAKE_DL_LIBS}) #HDF5 uses dlopen
target_compile_features(core INTERFACE cxx_std_14)
else()
target_compile_features(core INTERFACE cxx_std_11)
endif()
scorec_export_library(core)

Expand Down
7 changes: 3 additions & 4 deletions cmake/bob.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function(bob_begin_cxx_flags)
endfunction(bob_begin_cxx_flags)

# The following is from the book,"Professional CMake: 19th edition"
function(bob_setCxxStandard standard)
macro(bob_set_cxx_standard standard)
# Require C++<standard>, but let a parent project ask for something higher
if(DEFINED CMAKE_CXX_STANDARD)
if(CMAKE_CXX_STANDARD EQUAL 98 OR CMAKE_CXX_STANDARD LESS ${standard})
Expand All @@ -87,16 +87,16 @@ function(bob_setCxxStandard standard)
else()
set(CMAKE_CXX_STANDARD ${standard})
endif()
message(STATUS "CMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}")
# Always enforce the language constraint
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# We don't need compiler extensions, but let a parent ask for them
if(NOT DEFINED CMAKE_CXX_EXTENSIONS)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
endfunction()
endmacro()

function(bob_cxx11_flags)
bob_setCxxStandard(11)
set(FLAGS "${CMAKE_CXX_FLAGS}")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (${PROJECT_NAME}_CXX_WARNINGS)
Expand All @@ -107,7 +107,6 @@ function(bob_cxx11_flags)
endfunction(bob_cxx11_flags)

function(bob_cxx14_flags)
bob_setCxxStandard(14)
set(FLAGS "${CMAKE_CXX_FLAGS}")
set(FLAGS "${FLAGS} -Wall -Wextra -Wpedantic -Werror -Wno-extra-semi -Werror=unused-parameter -Wno-error=deprecated-declarations")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
Expand Down

0 comments on commit 9ff9c0e

Please sign in to comment.