Skip to content

Commit

Permalink
cmake: set STL preprocessor debug flags more consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
sthalik committed Aug 12, 2024
1 parent be453a4 commit 8db5d92
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
23 changes: 14 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,27 +151,33 @@ if(MSVC)
add_link_options(-HIGHENTROPYVA)
endif()
else()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
add_definitions(-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-ambiguous-reversed-operator>)
add_compile_options(-Wno-reserved-macro-identifier)
#add_compile_definitions($<$<COMPILE_LANGUAGE:CXX>:$<$<CONFIG:DEBUG,Debug>:_LIBCPP_ENABLE_ASSERTIONS>>)
else()
#add_compile_definitions($<$<COMPILE_LANGUAGE:CXX>:$<$<CONFIG:DEBUG,Debug>:-D_GLIBCXX_ASSERTIONS>>)
#add_compile_definitions($<$<COMPILE_LANGUAGE:CXX>:$<$<CONFIG:DEBUG,Debug>:-D_GLIBCXX_DEBUG>>)
#add_compile_definitions($<$<COMPILE_LANGUAGE:CXX>:$<$<CONFIG:DEBUG,Debug>:-D_GLIBCXX_DEBUG_PEDANTIC>>)
endif()

add_compile_options(-Wstrict-aliasing -Werror=strict-aliasing)
add_compile_options(-Wno-float-equal)
if(NOT WIN32)

if(NOT APPLE)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fuse-cxa-atexit>)
endif()
if(WIN32)
add_link_options(-Wl,--nxcompat -Wl,--dynamicbase)
if(CMAKE_SIZEOF_VOID_P GREATER_EQUAL 8)
if(CMAKE_SIZEOF_VOID_P GREATER 4)
add_link_options(-Wl,--high-entropy-va)
else()
add_link_options(-Wl,--large-address-aware)
endif()
endif()
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
add_compile_definitions($<$<COMPILE_LANGUAGE:CXX>:$<$<CONFIG:DEBUG,Debug>:_LIBCPP_ENABLE_ASSERTIONS>>)
add_compile_options(-Wno-reserved-macro-identifier)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-ambiguous-reversed-operator>)
endif()

set_directory_properties(PROPERTIES CORRADE_USE_PEDANTIC_FLAGS OFF)
set_directory_properties(PROPERTIES CORRADE_CXX_STANDARD ${CMAKE_CXX_STANDARD})
set_directory_properties(PROPERTIES INTERFACE_CORRADE_CXX_STANDARD ${CMAKE_CXX_STANDARD})
Expand Down Expand Up @@ -224,7 +230,6 @@ if(CMAKE_COMPILER_IS_GNUCXX)
endif()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
add_definitions(-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
add_compile_options(-Wno-shift-op-parentheses)
add_compile_options(-Wno-c99-compat)
elseif(CMAKE_COMPILER_IS_GNUCXX)
Expand Down
3 changes: 3 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ sets(STRING
CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}"
)

add_definitions(-D_LIBCPP_ENABLE_ASSERTIONS)
add_definitions(-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)

if(NOT CMAKE_CXX_COMPILER_VERSION LESS "18.0")
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fassume-nothrow-exception-dtor>)
endif()
Expand Down
16 changes: 9 additions & 7 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@ sets(STRING
list(APPEND CMAKE_IGNORE_PATH "c:/msys64" "c:/msys64/clang64")
list(APPEND CMAKE_IGNORE_PREFIX_PATH "c:/msys64" "c:/msys64/clang64")

add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fconcepts-diagnostics-depth=3>)
add_definitions(-D_GLIBCXX_USE_DEPRECATED=0 -D_GLIBCXX_USE_CXX11_ABI)
add_compile_options(-fdiagnostics-color=always)
add_compile_options(-fstack-usage -Wstack-usage=16384)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fconcepts-diagnostics-depth=3>)

add_definitions(-D_GLIBCXX_ASSERTIONS)
add_compile_definitions($<$<COMPILE_LANGUAGE:CXX>:$<$<CONFIG:DEBUG,Debug>:-D_GLIBCXX_DEBUG>>)
add_compile_definitions($<$<COMPILE_LANGUAGE:CXX>:$<$<CONFIG:DEBUG,Debug>:-D_GLIBCXX_DEBUG_PEDANTIC>>)
add_compile_definitions($<$<NOT:$<CONFIG:Debug,DEBUG>>:_FORTIFY_SOURCE=2>)
add_compile_definitions($<$<CONFIG:Debug,DEBUG>:_FORTIFY_SOURCE=3>)

if(CMAKE_BUILD_TYPE STREQUAL "DEBUG")
add_definitions(-D_GLIBCXX_ASSERTIONS)
add_definitions(-D_GLIBCXX_USE_DEPRECATED=0 -D_GLIBCXX_USE_CXX11_ABI)
add_definitions(-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC)
set(OpenCV_DIR "f:/build/opencv/build-gcc-debug-floormat/install" CACHE PATH "" FORCE)
else()
set(BUILD_SHARED_LIBS OFF)
set(OpenCV_DIR "f:/build/opencv/build-gcc-release-floormat/install" CACHE PATH "" FORCE)
endif()
add_compile_definitions("$<$<CONFIG:Debug,DEBUG>:_FORTIFY_SOURCE=3>")
add_compile_definitions("$<IF:$<CONFIG:Debug,DEBUG>,,_FORTIFY_SOURCE=3>")

# for building submodule dependencies
function(fm-userconfig-external)
Expand Down Expand Up @@ -68,6 +69,7 @@ endfunction()

# for floormat sources only
function(fm-userconfig-src)
add_compile_options(-fstack-usage -Wstack-usage=16384)
add_compile_options(
-Wall -Wextra -Wpedantic -Wno-old-style-cast -Wno-padded
-Wstringop-overflow -Wstringop-truncation
Expand Down

0 comments on commit 8db5d92

Please sign in to comment.