@@ -6,35 +6,42 @@ project(
66 LANGUAGES CXX
77)
88
9-
10- # set c++ standard
9+ # set C++ standard
1110if (NOT DEFINED CMAKE_CXX_STANDARD )
1211 set (CMAKE_CXX_STANDARD 20)
1312endif ()
14-
15-
16- # compiler flags
1713set (CMAKE_CXX_STANDARD_REQUIRED ON )
1814set (CMAKE_CXX_EXTENSIONS OFF )
1915
16+ if (MSVC )
17+ # Globally disable specific MSVC warnings from external headers
18+ add_compile_options (
19+ /wd5039 # 'TpSetCallbackCleanupGroup' potentially throwing
20+ /wd4820 # padding added after data member
21+ /wd4626 # deleted assignment operator
22+ /wd5045 # Spectre mitigation notice
23+ /wd4668 # undefined macro replaced with '0'
24+ )
25+ endif ()
26+
27+ # compiler flags
2028if (MSVC )
2129 set (CMAKE_CXX_FLAGS "/Wall /W4 /EHsc" )
2230else ()
23- # linux and apple
31+ # Linux and Apple
2432 set (CMAKE_CXX_FLAGS "-Wextra -Wall -Wextra -Wconversion -Wdouble-promotion -Wno-unused-parameter -Wno-unused-function -Wno-sign-conversion" )
2533endif ()
2634
2735if (CMAKE_C_COMPILER_ID STREQUAL "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "GNU" )
2836 set (CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -lstdc++ -lm" )
2937endif ()
3038
31-
3239# find available compilers
3340if (LINUX )
3441 find_program (CLANGPP_EXECUTABLE NAMES clang++ )
3542 find_program (GPP_EXECUTABLE NAMES g++ )
3643
37- # select compiler with preference for clang++ (just a personal choice of mine, i'm kinda obsessed with llvm honestly)
44+ # select compiler with preference for clang++
3845 if (CLANGPP_EXECUTABLE)
3946 set (CMAKE_CXX_COMPILER "${CLANGPP_EXECUTABLE} " )
4047 get_filename_component (COMPILER_NAME ${CLANGPP_EXECUTABLE} NAME )
@@ -45,67 +52,59 @@ if (LINUX)
4552endif ()
4653
4754message (STATUS "Compiler: ${COMPILER_NAME} " )
48- #message(STATUS "Compiler version: ${CMAKE_CXX_COMPILER_VERSION}")
49-
50-
5155
5256# fetch and set build type
5357set (available_build_types Debug Release)
5458if (NOT CMAKE_BUILD_TYPE )
55- set (CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build (Debug or Release)" FORCE )
59+ set (CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build (Debug or Release)" FORCE )
5660endif ()
5761
58-
5962# Define preprocessor macros based on the build type
6063if (CMAKE_BUILD_TYPE STREQUAL "Debug" )
61- add_compile_definitions (__VMAWARE_DEBUG__ )
64+ add_compile_definitions (__VMAWARE_DEBUG__ )
6265elseif (CMAKE_BUILD_TYPE STREQUAL "Release" )
63- add_compile_definitions (__VMAWARE_RELEASE__ )
66+ add_compile_definitions (__VMAWARE_RELEASE__ )
6467endif ()
6568
66-
6769# general variables
6870set (PROJECT_DIR "${CMAKE_CURRENT_SOURCE_DIR} " )
6971set (BUILD_DIR "${PROJECT_DIR} /build" )
7072set (TARGET "vmaware" )
7173
72-
7374# debug/release CXX flag options
7475if (MSVC )
7576 if (CMAKE_BUILD_TYPE MATCHES "Debug" )
76- MESSAGE (STATUS "Build set to debug mode" )
77+ message (STATUS "Build set to debug mode" )
7778 elseif (CMAKE_BUILD_TYPE MATCHES "Release" )
78- MESSAGE (STATUS "Build set to release mode" )
79+ message (STATUS "Build set to release mode" )
7980 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2" )
8081 endif ()
8182elseif (APPLE )
8283 if (CMAKE_BUILD_TYPE MATCHES "Debug" )
83- MESSAGE (STATUS "Build set to debug mode" )
84+ message (STATUS "Build set to debug mode" )
8485 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fsanitize=address" )
8586 elseif (CMAKE_BUILD_TYPE MATCHES "Release" )
86- MESSAGE (STATUS "Build set to release mode" )
87- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g0 -O2" )
88- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -mtune=native" )
87+ message (STATUS "Build set to release mode" )
88+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g0 -O2 -march=native -mtune=native" )
8989 endif ()
9090elseif (LINUX )
9191 if (CMAKE_BUILD_TYPE MATCHES "Debug" )
92- MESSAGE (STATUS "Build set to debug mode" )
93- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fmax-errors=5 -DDEBUG -O0 -fsanitize=address,leak" ) # todo, add ubsan
92+ message (STATUS "Build set to debug mode" )
93+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fmax-errors=5 -DDEBUG -O0 -fsanitize=address,leak" )
9494 elseif (CMAKE_BUILD_TYPE MATCHES "Release" )
95- MESSAGE (STATUS "Build set to release mode" )
95+ message (STATUS "Build set to release mode" )
9696 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g0 -O2" )
97- if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64" )
97+ if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64" )
9898 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -mtune=native" )
9999 elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" )
100100 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=native" )
101101 endif ()
102102 endif ()
103103else ()
104- MESSAGE (STATUS "Build set to release mode" )
104+ message (STATUS "Build set to release mode" )
105105 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2" )
106106endif ()
107107
108-
109108# add executable
110109set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BUILD_DIR} " )
111110add_executable (${TARGET} "src/cli.cpp" )
@@ -114,19 +113,17 @@ if(NOT DEFINED CMAKE_CXX_STANDARD)
114113endif ()
115114set_property (TARGET ${TARGET} PROPERTY CXX_STANDARD_REQUIRED ON )
116115
117-
118116# CTest stuff
119117include (CTest )
120118enable_testing ()
121119set (ARGUMENTS "--all" )
122120if (MSVC )
123- add_test (executable, "${BUILD_DIR} /Release/${TARGET} " )
121+ add_test (executable "${BUILD_DIR} /Release/${TARGET} " )
124122else ()
125- add_test (NAME TARGET COMMAND "${BUILD_DIR} /${TARGET} " ${ARGUMENTS} )
123+ add_test (NAME TARGET COMMAND "${BUILD_DIR} /${TARGET} " ${ARGUMENTS} )
126124endif ()
127125
128-
129- # release stuff
126+ # install rules
130127if (NOT MSVC )
131128 if (CMAKE_BUILD_TYPE MATCHES "Release" )
132129 install (TARGETS ${TARGET} DESTINATION /usr/bin)
@@ -142,4 +139,4 @@ elseif(MSVC)
142139 set (HEADER_INSTALL_PATH "C:\\ Program Files (x86)\\ YourLibrary\\ include" )
143140 install (FILES "src/vmaware.hpp" DESTINATION "${HEADER_INSTALL_PATH} " )
144141 install (FILES "src/vmaware_MIT.hpp" DESTINATION "${HEADER_INSTALL_PATH} " )
145- endif ()
142+ endif ()
0 commit comments