Skip to content

Commit b6542b0

Browse files
authored
CMake set release flags properly (#2138)
TYPE: bug fix KEYWORDS: cmake, flags, optimization SOURCE: internal DESCRIPTION OF CHANGES: Problem: To feed initial flags into the cmake build, a toolchain file is used. However, for particular build configurations, namely release and debug, despite the configuration being "Release" and "Debug", respectively, the corresponding `CMAKE_<LANG>_FLAGS_<CONFIG>_INIT` has the configuration name capitalized. Additionally, these initial flags supplement the starting flags and do not override any inherited flags that CMake automatically appends. This can cause issues with certain compilers where subsequent flags that normally should supersede previously listed options are ignored. As an example, using nvfortran/pgi the following will cause forced optimization, which is not viable for some files within WRF : https://forums.developer.nvidia.com/t/nvfortran-reducing-optimation-level-by-multiple-on-does-not-work/191825 https://forums.developer.nvidia.com/t/how-to-override-pgccs-optimization-flag/136275 Finally, certain files do not have optimization overridden even if it were to work correctly Solution: Ensure correct variable name in toolchain file to provide initial starting flags, and wipe CMake-injected release flags to avoid significant deviation from provided optimization flags. Add proper directory scope to files that need these reduced optimizations. TESTS CONDUCTED: 1. Tested with CMake build on Derecho selecting nvhpc/pgi compiler stanzas RELEASE NOTE: Override CMake-injected optimization flags in favor of the flags set by the build system and provided stanza information.
1 parent 4889c3c commit b6542b0

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ if ( DEFINED CMAKE_TOOLCHAIN_FILE )
1414
# include( ${WRF_CONFIG} )
1515
endif()
1616

17+
# Import default flags now, get rid of any imported release flag
18+
# we will handle that ourselves with WRF_FCOPTIM/WRF_FCNOOPT
19+
set( CMAKE_Fortran_FLAGS_RELEASE "" CACHE STRING "" FORCE )
20+
set( CMAKE_C_FLAGS_RELEASE "" CACHE STRING "" FORCE )
21+
1722
# list( APPEND CMAKE_MODULE_PATH )
1823
list( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/ ${PROJECT_SOURCE_DIR}/cmake/modules )
1924

cmake/template/arch_config.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ set( CMAKE_Fortran_FLAGS_INIT "{SFC_FLAGS} {FCBASEOPTS} {BYTESWAPIO}" )
1515
set( CMAKE_C_FLAGS_INIT "{SCC_FLAGS} {CFLAGS_LOCAL}" )
1616

1717
# https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_FLAGS_CONFIG_INIT.html
18-
set( CMAKE_Fortran_FLAGS_Debug_INIT "{FCDEBUG}" )
19-
set( CMAKE_Fortran_FLAGS_Release_INIT "" )
20-
set( CMAKE_C_FLAGS_Debug_INIT "" )
21-
set( CMAKE_C_FLAGS_Release_INIT "" )
18+
set( CMAKE_Fortran_FLAGS_DEBUG_INIT "{FCDEBUG}" )
19+
set( CMAKE_Fortran_FLAGS_RELEASE_INIT "" )
20+
set( CMAKE_C_FLAGS_DEBUG_INIT "" )
21+
set( CMAKE_C_FLAGS_RELEASE_INIT "" )
2222

2323
# Project specifics now
2424
set( WRF_MPI_Fortran_FLAGS "{DM_FC_FLAGS}" )

frame/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ target_sources(
156156
# Disable optimizations on these files always
157157
set_source_files_properties(
158158
${nl_dyn_source}
159+
module_comm_nesting_dm.F
160+
DIRECTORY ${PROJECT_SOURCE_DIR}
159161
PROPERTIES
160162
COMPILE_OPTIONS_OPTIMIZATION
161163
$<$<COMPILE_LANGUAGE:Fortran>:${WRF_FCNOOPT}>

0 commit comments

Comments
 (0)