2021-08-22 10:20:59 +00:00
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
set(CMAKE_CXX_STANDARD 14)
|
|
|
|
|
|
|
|
set(CMAKE_C_STANDARD 99)
|
|
|
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
|
|
|
|
2023-09-06 13:31:12 +00:00
|
|
|
if(NOT ARCH_ID)
|
|
|
|
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "")
|
|
|
|
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR})
|
|
|
|
endif()
|
|
|
|
string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" ARCH_ID)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (ARCH_ID MATCHES "^(aarch64|arm64|armv8-a)$")
|
|
|
|
set(ARMv8 1)
|
|
|
|
endif()
|
|
|
|
|
2021-08-22 10:20:59 +00:00
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES GNU)
|
2022-05-03 18:52:24 +00:00
|
|
|
set(GENERAL_FLAGS "-pthread")
|
2023-05-17 21:06:54 +00:00
|
|
|
|
2023-09-06 13:31:12 +00:00
|
|
|
if (ARMv8)
|
|
|
|
set(GENERAL_FLAGS "${GENERAL_FLAGS} -mfix-cortex-a53-835769 -mfix-cortex-a53-843419")
|
|
|
|
endif()
|
|
|
|
|
2023-05-17 21:06:54 +00:00
|
|
|
if (DEV_WITH_TSAN)
|
|
|
|
set(GENERAL_FLAGS "${GENERAL_FLAGS} -fno-omit-frame-pointer -fsanitize=thread")
|
|
|
|
endif()
|
|
|
|
|
2023-05-25 06:56:10 +00:00
|
|
|
if (DEV_WITH_UBSAN)
|
|
|
|
set(GENERAL_FLAGS "${GENERAL_FLAGS} -fno-omit-frame-pointer -fsanitize=undefined")
|
|
|
|
endif()
|
|
|
|
|
2023-05-25 10:57:06 +00:00
|
|
|
if (DEV_WITH_ASAN)
|
|
|
|
set(GENERAL_FLAGS "${GENERAL_FLAGS} -fno-omit-frame-pointer -fsanitize=address")
|
|
|
|
endif()
|
|
|
|
|
2022-06-01 12:25:58 +00:00
|
|
|
set(WARNING_FLAGS "-Wall -Wextra -Wcast-align -Wcast-qual -Wlogical-op -Wstrict-overflow=2 -Wundef -Wformat=2 -Wpointer-arith -Werror")
|
2023-05-17 21:06:54 +00:00
|
|
|
|
2023-05-25 10:57:06 +00:00
|
|
|
if (DEV_WITH_TSAN OR DEV_WITH_UBSAN OR DEV_WITH_ASAN)
|
2023-05-17 21:06:54 +00:00
|
|
|
set(OPTIMIZATION_FLAGS "-O2 -g")
|
|
|
|
else()
|
|
|
|
set(OPTIMIZATION_FLAGS "-Ofast -s")
|
|
|
|
endif()
|
2023-02-07 09:04:37 +00:00
|
|
|
|
|
|
|
if (WITH_LTO)
|
|
|
|
set(OPTIMIZATION_FLAGS "${OPTIMIZATION_FLAGS} -flto -fuse-linker-plugin")
|
|
|
|
endif()
|
2021-08-22 10:20:59 +00:00
|
|
|
|
2023-02-02 21:22:49 +00:00
|
|
|
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9)
|
|
|
|
set(OPTIMIZATION_FLAGS "${OPTIMIZATION_FLAGS} -fno-associative-math")
|
|
|
|
endif()
|
|
|
|
|
2022-05-03 18:52:24 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GENERAL_FLAGS} ${WARNING_FLAGS} ${OPTIMIZATION_FLAGS}")
|
|
|
|
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${GENERAL_FLAGS} ${WARNING_FLAGS} ${OPTIMIZATION_FLAGS}")
|
2021-08-22 10:20:59 +00:00
|
|
|
|
2022-05-03 18:52:24 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GENERAL_FLAGS} ${WARNING_FLAGS} ${OPTIMIZATION_FLAGS}")
|
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${GENERAL_FLAGS} ${WARNING_FLAGS} ${OPTIMIZATION_FLAGS}")
|
2021-08-22 10:20:59 +00:00
|
|
|
|
|
|
|
if (WIN32)
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
|
|
|
|
else()
|
2022-02-16 09:43:04 +00:00
|
|
|
if (STATIC_BINARY)
|
2021-08-22 10:20:59 +00:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
|
|
|
|
else()
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
elseif (CMAKE_CXX_COMPILER_ID MATCHES MSVC)
|
2022-10-13 19:41:08 +00:00
|
|
|
set(GENERAL_FLAGS "/MP")
|
2021-08-22 10:20:59 +00:00
|
|
|
set(WARNING_FLAGS "/Wall /WX /sdl")
|
|
|
|
set(SECURITY_FLAGS "/GS /guard:cf")
|
|
|
|
set(OPTIMIZATION_FLAGS "/O2 /Oi /Ob2 /Ot /DNDEBUG /GL")
|
|
|
|
|
2022-05-03 18:52:24 +00:00
|
|
|
set(CMAKE_C_FLAGS_DEBUG "${GENERAL_FLAGS} ${WARNING_FLAGS} ${SECURITY_FLAGS} /Od /Ob0 /Zi /MTd /fsanitize=address")
|
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${GENERAL_FLAGS} ${WARNING_FLAGS} ${SECURITY_FLAGS} /Od /Ob0 /Zi /MTd /fsanitize=address")
|
2021-08-22 10:20:59 +00:00
|
|
|
|
2022-05-03 18:52:24 +00:00
|
|
|
set(CMAKE_C_FLAGS_RELEASE "${GENERAL_FLAGS} ${WARNING_FLAGS} ${SECURITY_FLAGS} ${OPTIMIZATION_FLAGS} /MT")
|
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${GENERAL_FLAGS} ${WARNING_FLAGS} ${SECURITY_FLAGS} ${OPTIMIZATION_FLAGS} /MT")
|
2021-08-22 10:20:59 +00:00
|
|
|
|
2022-05-03 18:52:24 +00:00
|
|
|
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${GENERAL_FLAGS} ${WARNING_FLAGS} ${SECURITY_FLAGS} /Ob1 /Ot /Zi /MT")
|
|
|
|
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${GENERAL_FLAGS} ${WARNING_FLAGS} ${SECURITY_FLAGS} /Ob1 /Ot /Zi /MT")
|
2023-02-26 18:03:19 +00:00
|
|
|
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG")
|
2021-08-22 10:20:59 +00:00
|
|
|
elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang)
|
2023-08-15 11:31:28 +00:00
|
|
|
if (WIN32)
|
2023-09-06 13:31:12 +00:00
|
|
|
set(GENERAL_FLAGS "")
|
2023-08-15 11:31:28 +00:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
|
|
|
|
else()
|
|
|
|
set(GENERAL_FLAGS "-pthread")
|
|
|
|
endif()
|
|
|
|
|
2023-09-06 13:31:12 +00:00
|
|
|
if (ARMv8)
|
|
|
|
set(GENERAL_FLAGS "${GENERAL_FLAGS} -mfix-cortex-a53-835769")
|
|
|
|
endif()
|
|
|
|
|
2022-06-01 12:25:58 +00:00
|
|
|
set(WARNING_FLAGS "-Wall -Wextra -Wno-undefined-internal -Wunreachable-code-aggressive -Wmissing-prototypes -Wmissing-variable-declarations -Werror")
|
2023-05-24 14:02:10 +00:00
|
|
|
|
2023-08-24 13:02:32 +00:00
|
|
|
if (DEV_WITH_MSAN)
|
|
|
|
set(OPTIMIZATION_FLAGS "-O2 -g")
|
|
|
|
else()
|
2023-05-24 14:02:10 +00:00
|
|
|
set(OPTIMIZATION_FLAGS "-Ofast -funroll-loops -fmerge-all-constants")
|
|
|
|
endif()
|
2023-02-07 09:04:37 +00:00
|
|
|
|
|
|
|
if (WITH_LTO)
|
|
|
|
set(OPTIMIZATION_FLAGS "${OPTIMIZATION_FLAGS} -flto")
|
|
|
|
endif()
|
2021-08-22 10:20:59 +00:00
|
|
|
|
2022-05-03 18:52:24 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GENERAL_FLAGS} ${WARNING_FLAGS} ${OPTIMIZATION_FLAGS}")
|
|
|
|
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${GENERAL_FLAGS} ${WARNING_FLAGS} ${OPTIMIZATION_FLAGS}")
|
2021-08-22 10:20:59 +00:00
|
|
|
|
2022-05-03 18:52:24 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GENERAL_FLAGS} ${WARNING_FLAGS} ${OPTIMIZATION_FLAGS}")
|
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${GENERAL_FLAGS} ${WARNING_FLAGS} ${OPTIMIZATION_FLAGS}")
|
2021-08-22 10:20:59 +00:00
|
|
|
endif()
|