@@ -38,49 +38,68 @@ add_library(${PROJECT_NAME}::${PROJECT_NAME}-compile-options ALIAS ${PROJECT_NAM
38
38
#
39
39
# Compiler Flags and Conditions
40
40
#
41
+
42
+ # MSVC Compiler Options
41
43
if (MSVC )
42
- # MSVC-specific options
44
+ # Set MSVC-specific compilation flags
43
45
target_compile_options (${PROJECT_NAME} -compile-options INTERFACE
44
- /W4
45
- /permissive-
46
- /Zc:__cplusplus
47
- /EHsc
46
+ /W4 # Enable high warning level
47
+ /permissive- # Enforce standard C++ conformance
48
+ /Zc:__cplusplus # Properly define __cplusplus macro for the compiler version
49
+ /EHsc # Enable standard exception handling
48
50
)
49
- # Only define NOMINMAX on Windows platforms
51
+
52
+ # Define NOMINMAX on Windows platforms to avoid macro conflicts with std::min/std::max
50
53
if (WIN32 )
51
54
target_compile_definitions (${PROJECT_NAME} -compile-options INTERFACE NOMINMAX )
52
55
endif ()
53
56
57
+ # Treat warnings as errors if CCMATH_STRICT_WARNINGS is set
54
58
if (CCMATH_STRICT_WARNINGS )
55
- target_compile_options (${PROJECT_NAME} -compile-options INTERFACE /WX )
59
+ target_compile_options (${PROJECT_NAME} -compile-options INTERFACE /WX ) # Warnings as errors
56
60
endif ()
57
61
58
- elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
59
- OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
60
- OR CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM" )
62
+ # Clang, GCC, and IntelLLVM Compiler Options
63
+ elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|IntelLLVM" )
61
64
62
- # Generic clang/gcc/intel options
63
- # Consider making some of these suppressions configurable if requested by users.
65
+
66
+ # Generic options for Clang, GCC, and IntelLLVM
64
67
target_compile_options (${PROJECT_NAME} -compile-options INTERFACE
65
- -Wall
66
- -Wextra
67
- -Wconversion
68
- -Wpedantic
69
- #-Wwrite-strings
70
- -fpermissive # TODO: Figure out how to best remove this
71
- -g3
72
- # Define NOMINMAX only on Windows to avoid conflicts with min/max macros
68
+ -Wall # Enable common warnings
69
+ -Wextra # Enable additional warnings
70
+ -Wconversion # Warn on implicit type conversions
71
+ -Wpedantic # Enforce strict standard compliance
72
+ # Define NOMINMAX on Windows to avoid macro conflicts with min/max
73
73
$< $< BOOL:${WIN32} > :-DNOMINMAX>
74
74
)
75
75
76
- if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" ) # TODO: Check if intel llvm has this flag
76
+ # Add Clang-specific options
77
+ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
77
78
target_compile_options (${PROJECT_NAME} -compile-options INTERFACE
78
- -Wpedantic-macros
79
+ -Wpedantic-macros # Warn about non-standard macro usage
79
80
)
80
81
endif ()
81
82
83
+ # Treat specific warnings as errors if CCMATH_STRICT_WARNINGS is set
82
84
if (CCMATH_STRICT_WARNINGS )
83
- target_compile_options (${PROJECT_NAME} -compile-options INTERFACE -Werror=return-type )
85
+ target_compile_options (${PROJECT_NAME} -compile-options INTERFACE
86
+ -Werror=return-type # Treat missing return type warnings as errors
87
+ )
88
+ endif ()
89
+
90
+ # Add aggressive debug options for developers if CCMATH_DEV_AGGRESSIVE_DEBUG is set
91
+ if (CCMATH_DEV_AGGRESIVE_DEBUG )
92
+ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|IntelLLVM" )
93
+
94
+ target_compile_options (${PROJECT_NAME} -compile-options INTERFACE
95
+ -Wwrite-strings # Warn about writeable string literals
96
+ -g3 # Maximum debug information
97
+ )
98
+ elseif (MSVC )
99
+ target_compile_options (${PROJECT_NAME} -compile-options INTERFACE
100
+ /Zi # Generate full debugging information
101
+ )
102
+ endif ()
84
103
endif ()
85
104
86
105
# TODO: Decide if we plan to delete this or not
0 commit comments