Skip to content

Commit 4889c3c

Browse files
authored
CMake Correctly set generated property on autogen source code (#2132)
TYPE: bug fix KEYWORDS: autogeneration, compilation, cmake SOURCE: internal DESCRIPTION OF CHANGES: Problem: Currently the CMake build system minimum version is limited by the automated scoping of generated property on certain source files. This in combination of `CMP0118` requires usage of CMake >3.20 Solution: Set the generated property at the correct scope for source file usage. Lower the minimum required version to reflect this change. Note that CMake 3.18.6 is not used as there are features from 3.19 in use that, while could be implemented by hand, would take more effort to remove than the gained benefit. TESTS CONDUCTED: 1. Combined with #2125, #2130, and #2131 this was tested on the latest patch of each unique minor release of CMake since v3.19.8. The full list of tested versions is as follows: v3.19.8 v3.20.6 v3.21.7 v3.22.6 v3.23.5 v3.24.4 v3.25.3 v3.26.6 v3.27.9 v3.28.6 v3.29.8 v3.30.5 v3.31.0 RELEASE NOTE: Set the generated property on autogen source code explicitly in CMake and allow for lowered minimum CMake version of v3.19
1 parent 0ccba14 commit 4889c3c

File tree

5 files changed

+14
-17
lines changed

5 files changed

+14
-17
lines changed

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
cmake_minimum_required( VERSION 3.20 )
2-
cmake_policy( SET CMP0118 NEW )
1+
cmake_minimum_required( VERSION 3.19 )
32

43
project( WRF )
54

cmake/c_preproc.cmake

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,13 @@ macro( wrf_c_preproc_fortran )
6060
# # It keeps getting better lol
6161
# # https://gitlab.kitware.com/cmake/cmake/-/issues/18399
6262
# # We could use cmake 3.20+ and CMP0118, but this allows usage from 3.18.6+
63-
# TL;DR - This doesn't work despite all documentation stating otherwise, need to use CMP0118
64-
# set_source_files_properties(
65-
# ${WRF_PP_F_OUTPUT_FILE}
66-
# ${WRF_PP_F_TARGET_DIRECTORY}
67-
# PROPERTIES
68-
# GENERATED TRUE
69-
# )
7063
set_source_files_properties(
7164
${WRF_PP_F_OUTPUT_FILE}
7265
DIRECTORY ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
7366
${WRF_PP_F_TARGET_DIRECTORY}
7467
PROPERTIES
7568
Fortran_PREPROCESS OFF
69+
GENERATED TRUE
7670
)
7771
# message( STATUS "File ${WRF_PP_F_SOURCE_FILE} will be preprocessed into ${WRF_PP_F_OUTPUT_FILE}" )
7872

cmake/m4_preproc.cmake

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,13 @@ macro( wrf_m4_preproc_fortran )
5454
# # It keeps getting better lol
5555
# # https://gitlab.kitware.com/cmake/cmake/-/issues/18399
5656
# # We could use cmake 3.20+ and CMP0118, but this allows usage from 3.18.6+
57-
# TL;DR - This doesn't work despite all documentation stating otherwise, need to use CMP0118
58-
# set_source_files_properties(
59-
# ${WRF_PP_M4_OUTPUT_FILE}
60-
# ${WRF_PP_M4_TARGET_DIRECTORY}
61-
# PROPERTIES
62-
# GENERATED TRUE
63-
# )
6457
set_source_files_properties(
6558
${WRF_PP_M4_OUTPUT_FILE}
6659
DIRECTORY ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
6760
${WRF_PP_M4_TARGET_DIRECTORY}
6861
PROPERTIES
6962
Fortran_PREPROCESS OFF
63+
GENERATED TRUE
7064
)
7165
# message( STATUS "File ${WRF_PP_M4_SOURCE_FILE} will be preprocessed into ${WRF_PP_M4_OUTPUT_FILE}" )
7266

frame/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ endif()
102102
target_sources(
103103
${PROJECT_NAME}_Core
104104
PRIVATE
105-
${WRF_INCLUDE_FILES}
105+
module_internal_header_util.F
106+
106107

107108
module_configure.F
108109
module_driver_constants.F

tools/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ add_custom_target(
165165
${allocs_source}
166166
)
167167

168+
set_source_files_properties(
169+
${CMAKE_BINARY_DIR}/frame/module_state_description.F
170+
${dealloc_source}
171+
${allocs_source}
172+
DIRECTORY ${PROJECT_SOURCE_DIR}
173+
PROPERTIES
174+
GENERATED TRUE
175+
)
176+
168177
target_sources(
169178
${PROJECT_NAME}_Core
170179
PRIVATE

0 commit comments

Comments
 (0)