Skip to content

Commit

Permalink
update config_macros.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
i80287 committed Nov 9, 2024
1 parent 7391be9 commit 36e76b3
Show file tree
Hide file tree
Showing 24 changed files with 1,552 additions and 4,412 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/fedora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Install dependencies
run: |
sudo dnf -y update
sudo dnf -y install gcc gcc-c++ libasan libasan-static libubsan libubsan-static cmake make gmp gmp-devel gmp-c++ gmp-devel gmp-static mpfr-devel
sudo dnf -y install gcc gcc-c++ libasan libasan-static libubsan libubsan-static make ninja-build cmake gmp gmp-devel gmp-c++ gmp-devel gmp-static mpfr-devel
sudo dnf upgrade
- name: Install cppcheck
Expand All @@ -52,7 +52,7 @@ jobs:
- name: Install dependencies
run: |
sudo dnf -y update
sudo dnf -y install gcc libasan libasan-static libubsan libubsan-static clang llvm cmake make gmp gmp-devel gmp-c++ gmp-devel gmp-static mpfr-devel
sudo dnf -y install gcc libasan libasan-static libubsan libubsan-static clang llvm make ninja-build cmake gmp gmp-devel gmp-c++ gmp-devel gmp-static mpfr-devel
sudo dnf upgrade
- name: Install cppcheck
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
run: |
brew update
brew install gcc libtool make cmake
brew install gcc libtool make ninja cmake
# > GNU "make" has been installed as "gmake".
# > If you need to use it as "make", you can add a "gnubin" directory
# > to your PATH from your bashrc like:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt update
sudo apt install gcc g++ build-essential cmake make libgmp-dev libmpfr-dev
sudo apt install gcc g++ build-essential make ninja-build cmake libgmp-dev libmpfr-dev
- name: Install cppcheck
run: |
Expand All @@ -50,7 +50,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt update
sudo apt install clang llvm cmake make libgmp-dev libmpfr-dev
sudo apt install clang llvm make ninja-build cmake libgmp-dev libmpfr-dev
- name: Install cppcheck
run: |
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
gcc-mingw-w64 gcc-mingw-w64-i686 gcc-mingw-w64-i686-posix gcc-mingw-w64-i686-posix-runtime \
g++-mingw-w64 g++-mingw-w64-i686 g++-mingw-w64-i686-posix \
mingw-w64 mingw-w64-common mingw-w64-tools mingw-w64-i686-dev \
cmake make wine
make ninja-build cmake wine
- name: Install cppcheck
run: |
Expand Down Expand Up @@ -110,7 +110,7 @@ jobs:
gcc-mingw-w64 gcc-mingw-w64-x86-64-posix gcc-mingw-w64-x86-64-posix-runtime \
g++-mingw-w64 g++-mingw-w64-x86-64-posix \
mingw-w64 mingw-w64-common mingw-w64-tools mingw-w64-x86-64-dev \
cmake make wine
make ninja-build cmake wine
- name: Install cppcheck
run: |
Expand Down
229 changes: 10 additions & 219 deletions bstrees/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,229 +1,20 @@
cmake_minimum_required(VERSION 3.28)
project(tests)
project(rbtree_datastructure)

include(../tests/CMakeTestsUtils.cmake)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)
# Empty by default
set(TEST_C_COMPILE_OPTIONS)
set(TEST_CXX_COMPILE_OPTIONS)
set(TEST_COMPILE_DEFINITIONS)

function(configure_gcc_or_clang_gcc_options)
if (MSVC)
message(FATAL_ERROR "ClangCL should not be configured with this function")
endif ()

set(LOCAL_FN_TEST_C_COMPILE_OPTIONS
${TEST_C_COMPILE_OPTIONS})
set(LOCAL_FN_TEST_CXX_COMPILE_OPTIONS
${TEST_CXX_COMPILE_OPTIONS})
set(LOCAL_FN_TEST_COMPILE_DEFINITIONS
${TEST_COMPILE_DEFINITIONS})
set(LOCAL_FN_CMAKE_C_FLAGS_RELWITHDEBINFO
${CMAKE_C_FLAGS_RELWITHDEBINFO})
set(LOCAL_FN_CMAKE_CXX_FLAGS_RELWITHDEBINFO
${CMAKE_CXX_FLAGS_RELWITHDEBINFO})

# Flags for both C and C++
set(LOCAL_FN_TEST_CXX_COMPILE_OPTIONS
${LOCAL_FN_TEST_CXX_COMPILE_OPTIONS}
-Wall
-Wextra
-Wcast-qual
-Wpedantic
-Wunused
-Wshadow
-Wnull-dereference
-Wundef
-Wsign-conversion
-Wsign-compare
-Wconversion
-Wmissing-noreturn
-Wunreachable-code
-Wcast-align
-Wformat=2
-Wswitch-bool
-Wswitch-default
-Wswitch-enum
-Wdeprecated
-Wtype-limits
-Werror
-pedantic-errors
)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(LOCAL_FN_TEST_CXX_COMPILE_OPTIONS
${LOCAL_FN_TEST_CXX_COMPILE_OPTIONS}
-Warray-bounds=2
-Wshift-overflow=2
-Wlogical-op
-Wunsafe-loop-optimizations
-Wduplicated-cond
-fdiagnostics-color=always)
endif ()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(LOCAL_FN_TEST_CXX_COMPILE_OPTIONS
${LOCAL_FN_TEST_CXX_COMPILE_OPTIONS}
-Warray-bounds
-Wshift-overflow
-Wshift-sign-overflow
-Wshorten-64-to-32
-Wthread-safety
-Wnull-pointer-arithmetic
-Wnull-pointer-subtraction
-Wnullable-to-nonnull-conversion
-fcolor-diagnostics
-fansi-escape-codes
-ftemplate-backtrace-limit=0)
set(LOCAL_FN_TEST_COMPILE_DEFINITIONS
${LOCAL_FN_TEST_COMPILE_DEFINITIONS}
_LIBCPP_ENABLE_ASSERTIONS)
endif ()
if (NOT USING_MINGW_GCC AND CMAKE_SYSTEM_NAME MATCHES "Linux")
set(LOCAL_FN_TEST_CXX_COMPILE_OPTIONS
${LOCAL_FN_TEST_CXX_COMPILE_OPTIONS}
-fstack-protector-strong
)
endif ()

set(LOCAL_FN_TEST_C_COMPILE_OPTIONS
${LOCAL_FN_TEST_C_COMPILE_OPTIONS}
${LOCAL_FN_TEST_CXX_COMPILE_OPTIONS}
)

# Flags for C only
set(LOCAL_FN_TEST_C_COMPILE_OPTIONS
${LOCAL_FN_TEST_C_COMPILE_OPTIONS}
-Wwrite-strings
-Wbad-function-cast
-Wint-conversion
)
# Flags for C++ only
set(LOCAL_FN_TEST_CXX_COMPILE_OPTIONS
${LOCAL_FN_TEST_CXX_COMPILE_OPTIONS}
-Weffc++
-Wsign-promo
-Wold-style-cast
)
set(LOCAL_FN_TEST_CXX_COMPILE_OPTIONS
${LOCAL_FN_TEST_CXX_COMPILE_OPTIONS}
-U_GLIBCXX_USE_DEPRECATED)
set(LOCAL_FN_TEST_COMPILE_DEFINITIONS
${LOCAL_FN_TEST_COMPILE_DEFINITIONS}
_GLIBCXX_SANITIZE_VECTOR
ENABLE_LONGINT_DEBUG_ASSERTS=1)
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0)
# In gcc with version < 10.0 these checks break `constexpr`-tivity of some std:: functions
set(LOCAL_FN_TEST_COMPILE_DEFINITIONS
${LOCAL_FN_TEST_COMPILE_DEFINITIONS}
_GLIBCXX_DEBUG
_GLIBCXX_DEBUG_PEDANTIC
_GLIBCXX_CONCEPT_CHECKS)
endif ()

# Remove -DNDEBUG from the RelWithDebInfo mode flags
string(REGEX REPLACE "-D\\s?NDEBUG(=\\d)?" "" LOCAL_FN_CMAKE_C_FLAGS_RELWITHDEBINFO "${LOCAL_FN_CMAKE_C_FLAGS_RELWITHDEBINFO}")
string(REGEX REPLACE "-D\\s?NDEBUG(=\\d)?" "" LOCAL_FN_CMAKE_CXX_FLAGS_RELWITHDEBINFO "${LOCAL_FN_CMAKE_CXX_FLAGS_RELWITHDEBINFO}")

set(TEST_C_COMPILE_OPTIONS
${LOCAL_FN_TEST_C_COMPILE_OPTIONS}
PARENT_SCOPE)
set(TEST_CXX_COMPILE_OPTIONS
${LOCAL_FN_TEST_CXX_COMPILE_OPTIONS}
PARENT_SCOPE)
set(TEST_COMPILE_DEFINITIONS
${LOCAL_FN_TEST_COMPILE_DEFINITIONS}
PARENT_SCOPE)
set(CMAKE_C_FLAGS_RELWITHDEBINFO
${LOCAL_FN_CMAKE_C_FLAGS_RELWITHDEBINFO}
PARENT_SCOPE)
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO
${LOCAL_FN_CMAKE_CXX_FLAGS_RELWITHDEBINFO}
PARENT_SCOPE)

if (NOT USING_MINGW_GCC)
# set(CMAKE_C_FLAGS_RELWITHDEBINFO ${CMAKE_C_FLAGS_RELWITHDEBINFO} -fsanitize=address,undefined PARENT_SCOPE)
# set(CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -fsanitize=address,undefined PARENT_SCOPE)
endif ()

endfunction(configure_gcc_or_clang_gcc_options)
set(CXX_STANDARD_REQUIRED ON)

function(configure_msvc_or_clang_msvc_options)
set(LOCAL_FN_TEST_C_COMPILE_OPTIONS
${TEST_C_COMPILE_OPTIONS})
set(LOCAL_FN_TEST_CXX_COMPILE_OPTIONS
${TEST_CXX_COMPILE_OPTIONS})
set(LOCAL_FN_TEST_COMPILE_DEFINITIONS
${TEST_COMPILE_DEFINITIONS})

set(LOCAL_FN_TEST_COMPILE_DEFINITIONS
${LOCAL_FN_TEST_COMPILE_DEFINITIONS}
_CRT_SECURE_NO_WARNINGS=1)

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(LOCAL_FN_TEST_CXX_COMPILE_OPTIONS
${LOCAL_FN_TEST_CXX_COMPILE_OPTIONS}
-UNDEBUG)
set(LOCAL_FN_TEST_CXX_COMPILE_OPTIONS
${LOCAL_FN_TEST_CXX_COMPILE_OPTIONS}
"/W4" # Enable -Wall and -Wextra
)
else ()
if (MSVC_VERSION GREATER_EQUAL 1914)
set(LOCAL_FN_TEST_CXX_COMPILE_OPTIONS
${LOCAL_FN_TEST_CXX_COMPILE_OPTIONS}
"/Zc:__cplusplus")
endif ()
set(LOCAL_FN_TEST_CXX_COMPILE_OPTIONS
${LOCAL_FN_TEST_CXX_COMPILE_OPTIONS}
"/W4"
"/UNDEBUG"
"/wd4146" # Disable C4146: unary minus operator applied to unsigned type, result still unsigned
)
endif ()

set(LOCAL_FN_TEST_C_COMPILE_OPTIONS
${LOCAL_FN_TEST_C_COMPILE_OPTIONS}
${LOCAL_FN_TEST_CXX_COMPILE_OPTIONS})

set(TEST_C_COMPILE_OPTIONS
${LOCAL_FN_TEST_C_COMPILE_OPTIONS}
PARENT_SCOPE)
set(TEST_CXX_COMPILE_OPTIONS
${LOCAL_FN_TEST_CXX_COMPILE_OPTIONS}
PARENT_SCOPE)
set(TEST_COMPILE_DEFINITIONS
${LOCAL_FN_TEST_COMPILE_DEFINITIONS}
PARENT_SCOPE)
endfunction(configure_msvc_or_clang_msvc_options)


# https://en.cppreference.com/w/cpp/compiler_support
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
configure_msvc_or_clang_msvc_options()
elseif (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
configure_gcc_or_clang_gcc_options()
else ()
message(FATAL_ERROR "Clang with unknown frontend")
endif ()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
configure_gcc_or_clang_gcc_options()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
configure_msvc_or_clang_msvc_options()
endif ()

add_executable(tests RBTreeTests.cpp)
#set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -fsanitize=address,undefined,leak,bounds)

target_compile_definitions(tests PRIVATE ${COMPILE_DEFINITIONS})
target_compile_options(tests PRIVATE ${TEST_CXX_COMPILE_OPTIONS})

add_library(rbtree)
add_library(rbtree STATIC)
target_sources(rbtree PUBLIC
FILE_SET CXX_MODULES
FILES RBTree.cppm)

target_compile_definitions(rbtree PRIVATE ${COMPILE_DEFINITIONS} RBTREE_DEBUG)
target_compile_definitions(rbtree PRIVATE ${TEST_COMPILE_DEFINITIONS} RBTREE_DEBUG)
target_compile_options(rbtree PRIVATE ${TEST_CXX_COMPILE_OPTIONS})

target_link_libraries(tests PRIVATE rbtree)
add_executable(rbtree_tests RBTreeTests.cpp)
target_compile_definitions(rbtree_tests PRIVATE ${TEST_COMPILE_DEFINITIONS})
target_compile_options(rbtree_tests PRIVATE ${TEST_CXX_COMPILE_OPTIONS})
target_link_libraries(rbtree_tests PUBLIC rbtree)
Loading

0 comments on commit 36e76b3

Please sign in to comment.