Skip to content

Commit

Permalink
Add option for native optimizations in CMakeLists.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
gassmoeller authored and tukss committed Jun 21, 2024
1 parent 8953127 commit af39361
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ add_dependencies(rayleigh run_param_header)

target_include_directories(rayleigh PRIVATE ${PROJECT_SOURCE_DIR}/src/Include ${CMAKE_CURRENT_BINARY_DIR})

set(RAYLEIGH_CPU_OPTIMIZATIONS "none" CACHE PATH "Specify a CPU architecture to build for. Currently only 'native' or 'none' are supported.")

if (RAYLEIGH_CPU_OPTIMIZATIONS STREQUAL "native")
if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
target_compile_options(rayleigh PRIVATE -march=native)
message(STATUS "enabling native optimizations")
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
target_compile_options(rayleigh PRIVATE -xHost)
else()
message(FATAL_ERROR "For your compiler no native optimizations are automatically detected. Please specify compiler flags manually and set 'CPU_OPTIMIZATIONS' to 'none'")
endif()
elseif (RAYLEIGH_CPU_OPTIMIZATIONS STREQUAL "none")
# do nothing, respect manually set compiler flags
else()
message(FATAL_ERROR "Only 'native' and 'none' are supported for parameter 'CPU_OPTIMIZATIONS'")
endif()

if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
target_compile_definitions(rayleigh PRIVATE GNU_COMPILER)
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
Expand Down

0 comments on commit af39361

Please sign in to comment.