Skip to content

Commit 0061e6a

Browse files
committed
Improve compiler flags
Signed-off-by: Ian <[email protected]>
1 parent 1f597e4 commit 0061e6a

File tree

2 files changed

+62
-23
lines changed

2 files changed

+62
-23
lines changed

CMakeLists.txt

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,49 +38,68 @@ add_library(${PROJECT_NAME}::${PROJECT_NAME}-compile-options ALIAS ${PROJECT_NAM
3838
#
3939
# Compiler Flags and Conditions
4040
#
41+
42+
# MSVC Compiler Options
4143
if (MSVC)
42-
# MSVC-specific options
44+
# Set MSVC-specific compilation flags
4345
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
4850
)
49-
# Only define NOMINMAX on Windows platforms
51+
52+
# Define NOMINMAX on Windows platforms to avoid macro conflicts with std::min/std::max
5053
if (WIN32)
5154
target_compile_definitions(${PROJECT_NAME}-compile-options INTERFACE NOMINMAX)
5255
endif ()
5356

57+
# Treat warnings as errors if CCMATH_STRICT_WARNINGS is set
5458
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
5660
endif ()
5761

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")
6164

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
6467
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
7373
$<$<BOOL:${WIN32}>:-DNOMINMAX>
7474
)
7575

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")
7778
target_compile_options(${PROJECT_NAME}-compile-options INTERFACE
78-
-Wpedantic-macros
79+
-Wpedantic-macros # Warn about non-standard macro usage
7980
)
8081
endif ()
8182

83+
# Treat specific warnings as errors if CCMATH_STRICT_WARNINGS is set
8284
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 ()
84103
endif ()
85104

86105
# TODO: Decide if we plan to delete this or not

test/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,26 @@ if (NOT TARGET ccmath)
66
find_package(ccmath CONFIG REQUIRED)
77
endif ()
88

9+
# Apply super lenient compiler warnings for testing
10+
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
11+
add_compile_options(
12+
-Wall # Basic warnings
13+
-Wextra # Some additional warnings
14+
-Wno-unused-function # Suppress unused function warnings
15+
-Wno-unused-variable # Suppress unused variable warnings
16+
-Wno-pedantic # Disable pedantic warnings
17+
-Wno-sign-compare # Disable warnings about signed/unsigned comparisons
18+
-Wno-overflow # Disable warnings about overflow # TODO: Fix test cases that cause actual oflow
19+
)
20+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
21+
add_compile_options(
22+
/W3 # Moderate warning level (instead of /W4)
23+
/wd4100 # Suppress 'unreferenced formal parameter'
24+
/wd4189 # Suppress 'local variable is initialized but not referenced'
25+
/wd4505 # Suppress 'unreferenced local function has been removed'
26+
)
27+
endif ()
28+
929

1030
add_library(${PROJECT_NAME} STATIC)
1131
add_library(ccmath::test ALIAS ${PROJECT_NAME})

0 commit comments

Comments
 (0)