Last active
September 27, 2024 02:56
-
-
Save scivision/c613f48d2417cabcb8522627a931dfec to your computer and use it in GitHub Desktop.
CMake add_compile_option() SHELL: to allow spaces in options, including generator expressions. Useful for Intel oneAPI.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.15) | |
project(opt LANGUAGES Fortran) | |
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | |
# https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2024-2/warn.html | |
# SHELL: allows using | |
# * spaces in compiler options (especially important for Intel oneAPI | |
# * repeated option prefix, that might otherwise get deduplicated incorrectly | |
# https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html#compiler-language-id-and-frontend-variant | |
# https://cmake.org/cmake/help/latest/command/add_compile_options.html#option-de-duplication | |
add_executable(double_opt implicit.f90) | |
if(WIN32) | |
target_compile_options(double_opt PRIVATE "$<$<Fortran_COMPILER_ID:Intel,IntelLLVM>:SHELL:/warn:all;SHELL:/warn:errors>") | |
else() | |
target_compile_options(double_opt PRIVATE "$<$<Fortran_COMPILER_ID:Intel,IntelLLVM>:SHELL:-warn all;SHELL:-warn errors>") | |
endif() | |
add_executable(single_opt implicit.f90) | |
# simpler way to express same options | |
if(WIN32) | |
target_compile_options(single_opt PRIVATE "$<$<Fortran_COMPILER_ID:Intel,IntelLLVM>:SHELL:/warn:all,errors>") | |
else() | |
target_compile_options(single_opt PRIVATE "$<$<Fortran_COMPILER_ID:Intel,IntelLLVM>:SHELL:-warn all,errors>") | |
endif() | |
# auto-ignore build directory | |
file(GENERATE OUTPUT .gitignore CONTENT "*") | |
message(STATUS "See file ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json for final compiler options") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program main | |
x = 1.0 | |
end program |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment