forked from NOAA-EMC/WW4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
172 lines (151 loc) · 7.2 KB
/
Copy pathCMakeLists.txt
File metadata and controls
172 lines (151 loc) · 7.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#+ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +
#| WAVEWATCH IV, open source, code management by NOAA / NWS |
#+ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +
#
#@file CMakeLists.txt
#@brief CMake build configuration for WAVEWATCH IV (WW4) Utilities.
#@details This file defines the project structure, dependencies (GTest),
#and build targets for the WW4_Utils library and its tests.
#
#@copyright © 2026 National Weather Service, National Oceanic and Atmospheric
#Administration. WAVEWATCH IV (TM) and WW4 (TM) are trademarks
#of the National Weather Service.
#NWS often uses Generative AI (GenAI) for code development and refactoring. Whenever GenAI is used, NWS requires a full human review of code before it is added to its repositories.
#@author Main Author(s) : Aldgisl (AI Persona), Hendrik L. Tolman
#@author Contributors : Jules (Agentic AI), Kit Stokes
#@date Initial : 2026-03-20
#@date Last update : 2026-06-08
cmake_minimum_required(VERSION 3.25)
# Optional local configuration file generated by the setup tool.
include(${CMAKE_SOURCE_DIR}/ww4_local_config.cmake OPTIONAL)
project(WW4_Utils VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Set default output directory for executables
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# Options for strict warnings and sanitizers
option(WW4_STRICT_WARNINGS "Enable strict compiler warnings and treat as errors" OFF)
option(WW4_USE_SANITIZERS "Enable address and undefined behavior sanitizers" OFF)
# Define common compile options for WW4 targets
set(WW4_COMMON_COMPILE_OPTIONS "")
set(WW4_COMMON_LINK_OPTIONS "")
if(MSVC)
if(WW4_STRICT_WARNINGS)
list(APPEND WW4_COMMON_COMPILE_OPTIONS /W4 /WX)
endif()
else()
list(APPEND WW4_COMMON_COMPILE_OPTIONS -Wall -Wextra -Wpedantic)
if(WW4_STRICT_WARNINGS)
list(APPEND WW4_COMMON_COMPILE_OPTIONS -Werror)
# Suppress unknown warning option and conversion errors for LLVM-based compilers (Clang, IntelLLVM)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
list(APPEND WW4_COMMON_COMPILE_OPTIONS -Wno-unknown-warning-option -Wno-character-conversion)
# Suppress Intel LLVM driver warning about unsupported options (e.g., -Winline)
if(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
list(APPEND WW4_COMMON_COMPILE_OPTIONS -diag-disable=10430)
endif()
endif()
endif()
if(WW4_USE_SANITIZERS)
list(APPEND WW4_COMMON_COMPILE_OPTIONS -fsanitize=address,undefined)
list(APPEND WW4_COMMON_LINK_OPTIONS -fsanitize=address,undefined)
endif()
endif()
# Google Test
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
SYSTEM
)
# yaml-cpp for configuration parsing
FetchContent_Declare(
yaml-cpp
URL https://github.com/jbeder/yaml-cpp/archive/refs/tags/0.8.0.zip
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
SYSTEM
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest yaml-cpp)
# Suppress warnings from GTest itself for Clang/IntelLLVM during compilation
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
set(GTEST_SUPPRESS_FLAGS -Wno-unknown-warning-option -Wno-character-conversion)
if(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
list(APPEND GTEST_SUPPRESS_FLAGS -diag-disable=10430)
endif()
foreach(target gtest gtest_main gmock gmock_main)
if(TARGET ${target})
target_compile_options(${target} INTERFACE ${GTEST_SUPPRESS_FLAGS})
target_compile_options(${target} PRIVATE ${GTEST_SUPPRESS_FLAGS})
endif()
endforeach()
endif()
# Library
add_library(
ww4_utils
src/ww4_utils/time_management.cpp
src/ww4_utils/memory_utils.cpp
src/ww4_utils/ww4_std_out.cpp
src/ww4_utils/ww4_logfile.cpp
src/ww4_utils/ww4_standalone_config.cpp
src/ww4_utils/ww4_run_config.cpp
src/ww4_utils/ww4_input_utils.cpp
src/ww4_utils/ww4_output_utils.cpp
src/ww4_utils/ww4_service.cpp
)
target_include_directories(ww4_utils PUBLIC src)
target_link_libraries(ww4_utils PRIVATE yaml-cpp)
target_compile_options(ww4_utils PRIVATE ${WW4_COMMON_COMPILE_OPTIONS})
target_link_options(ww4_utils PRIVATE ${WW4_COMMON_LINK_OPTIONS})
add_library(
ww4_core
src/ww4_core/w4core_init.cpp
src/ww4_core/w4core_wave.cpp
src/ww4_core/w4core_finalize.cpp
)
target_include_directories(ww4_core PUBLIC src)
target_link_libraries(ww4_core PUBLIC ww4_utils)
target_compile_options(ww4_core PRIVATE ${WW4_COMMON_COMPILE_OPTIONS})
target_link_options(ww4_core PRIVATE ${WW4_COMMON_LINK_OPTIONS})
# Executables
add_executable(ww4_standalone src/ww4_progs/ww4_standalone.cpp)
target_link_libraries(ww4_standalone PRIVATE ww4_core ww4_utils)
target_compile_options(ww4_standalone PRIVATE ${WW4_COMMON_COMPILE_OPTIONS})
target_link_options(ww4_standalone PRIVATE ${WW4_COMMON_LINK_OPTIONS})
# Place the main program in the exe directory
set_target_properties(
ww4_standalone
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/exe
)
# Tests
enable_testing()
include(GoogleTest)
# Helper function to define tests
function(ww4_add_test test_name source_file dependency_lib)
add_executable(${test_name} ${source_file})
target_link_libraries(${test_name} PRIVATE ${dependency_lib} GTest::gtest_main)
target_compile_options(${test_name} PRIVATE ${WW4_COMMON_COMPILE_OPTIONS})
target_link_options(${test_name} PRIVATE ${WW4_COMMON_LINK_OPTIONS})
gtest_discover_tests(${test_name})
endfunction()
# Utils tests
ww4_add_test(test_time_management tests/ww4_utils/L1_test_time_management.cpp ww4_utils)
ww4_add_test(test_memory_utils tests/ww4_utils/L1_test_memory_utils.cpp ww4_utils)
ww4_add_test(test_ww4_std_out tests/ww4_utils/L1_test_ww4_std_out.cpp ww4_utils)
ww4_add_test(test_ww4_logfile tests/ww4_utils/L1_test_ww4_logfile.cpp ww4_utils)
ww4_add_test(test_ww4_standalone_config tests/ww4_utils/L1_test_ww4_standalone_config.cpp ww4_utils)
ww4_add_test(test_ww4_run_config tests/ww4_utils/L1_test_ww4_run_config.cpp ww4_utils)
ww4_add_test(test_ww4_output_utils tests/ww4_utils/L1_test_ww4_output_utils.cpp ww4_utils)
ww4_add_test(test_ww4_service tests/ww4_utils/L1_test_ww4_service.cpp ww4_utils)
ww4_add_test(test_ww4_constants tests/ww4_utils/L1_test_ww4_constants.cpp ww4_utils)
# Core tests
ww4_add_test(test_w4core_time tests/ww4_core/L2_test_w4core_time.cpp ww4_core)
ww4_add_test(test_w4core_wave_output tests/ww4_core/L2_test_w4core_wave_output.cpp ww4_core)
ww4_add_test(test_w4core_zero_step tests/ww4_core/L2_test_w4core_zero_step.cpp ww4_core)
ww4_add_test(test_w4core_hom_input tests/ww4_core/L2_test_w4core_hom_input.cpp ww4_core)
ww4_add_test(test_w4core_input_cycling tests/ww4_core/L2_test_w4core_input_cycling.cpp ww4_core)
ww4_add_test(test_interpolation_output tests/ww4_core/L2_test_interpolation_output.cpp ww4_core)
ww4_add_test(test_w4core_screen_output tests/ww4_core/L2_test_w4core_screen_output.cpp ww4_core)