2021-12-08 11:32:04 +00:00
|
|
|
|
cmake_policy(PUSH)
|
|
|
|
|
cmake_policy(SET CMP0057 NEW) # IN_LIST operator
|
|
|
|
|
|
|
|
|
|
option(MYX_CMAKE_ENABLE_WARNING_FLAGS "Enable autodetected warning flags" ON)
|
2021-12-12 20:11:20 +00:00
|
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL
|
|
|
|
|
"Enable generation of compile_commands.json." FORCE)
|
2021-12-08 11:32:04 +00:00
|
|
|
|
|
|
|
|
|
# Добавление конфигурации для профилирования
|
|
|
|
|
if(CMAKE_CONFIGURATION_TYPES)
|
|
|
|
|
if(NOT "Profile" IN_LIST CMAKE_CONFIGURATION_TYPES)
|
|
|
|
|
list(APPEND CMAKE_CONFIGURATION_TYPES Profile)
|
|
|
|
|
endif()
|
|
|
|
|
else()
|
|
|
|
|
set(_allowed_build_types None Debug Release Profile RelWithDebInfo MinSizeRel)
|
|
|
|
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${_allowed_build_types})
|
|
|
|
|
if(NOT CMAKE_BUILD_TYPE)
|
2021-12-12 20:11:20 +00:00
|
|
|
|
set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE)
|
2021-12-08 11:32:04 +00:00
|
|
|
|
elseif(NOT "${CMAKE_BUILD_TYPE}" IN_LIST _allowed_build_types)
|
|
|
|
|
message(FATAL_ERROR "Invalid build type: ${CMAKE_BUILD_TYPE}")
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
set(_gcc_debug_flags "-ggdb -fno-omit-frame-pointer")
|
|
|
|
|
set(_gcc_profile_flags "-pg")
|
|
|
|
|
|
|
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL Profile)
|
|
|
|
|
# Ключи компиляции для режима профилирования в зависимости от типа компилятора
|
|
|
|
|
if(CMAKE_CXX_COMPILER_IS_CLANG OR CMAKE_CXX_COMPILER_IS_GCC)
|
|
|
|
|
set(CMAKE_C_FLAGS_PROFILE
|
|
|
|
|
"${CMAKE_C_FLAGS_RELEASE} ${_gcc_debug_flags} ${_gcc_profile_flags}"
|
|
|
|
|
CACHE STRING "" FORCE)
|
|
|
|
|
set(CMAKE_CXX_FLAGS_PROFILE
|
|
|
|
|
"${CMAKE_CXX_FLAGS_RELEASE} ${MYX_CMAKE_DETECTED_CXX_FLAGS} ${_gcc_debug_flags} ${_gcc_profile_flags}"
|
|
|
|
|
CACHE STRING "" FORCE)
|
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS_PROFILE
|
|
|
|
|
"${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${_gcc_profile_flags}"
|
|
|
|
|
CACHE STRING "" FORCE)
|
|
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS_PROFILE
|
|
|
|
|
"${CMAKE_SHARED_LINKER_FLAGS_RELEASE} ${_gcc_profile_flags}"
|
|
|
|
|
CACHE STRING "" FORCE)
|
|
|
|
|
set(CMAKE_STATIC_LINKER_FLAGS_PROFILE
|
|
|
|
|
"${CMAKE_STATIC_LINKER_FLAGS_RELEASE} ${_gcc_profile_flags}"
|
|
|
|
|
CACHE STRING "" FORCE)
|
|
|
|
|
set(CMAKE_MODULE_LINKER_FLAGS_PROFILE
|
|
|
|
|
"${CMAKE_MODULE_LINKER_FLAGS_RELEASE} ${_gcc_profile_flags}"
|
|
|
|
|
CACHE STRING "" FORCE)
|
|
|
|
|
elseif(CMAKE_CXX_COMPILER_IS_Intel)
|
|
|
|
|
message("Set options for profiling with Intel C++")
|
|
|
|
|
elseif(CMAKE_CXX_COMPILER_IS_MSVC)
|
|
|
|
|
message("Set options for profiling with Visual Studio C++")
|
|
|
|
|
endif()
|
2021-12-12 20:11:20 +00:00
|
|
|
|
set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL
|
|
|
|
|
"Enable generation of verbose build scripts." FORCE)
|
2021-12-08 11:32:04 +00:00
|
|
|
|
elseif(CMAKE_BUILD_TYPE STREQUAL Debug)
|
|
|
|
|
# В режиме отладки подробный вывод сообщений компилятора
|
|
|
|
|
if(CMAKE_CXX_COMPILER_IS_CLANG OR CMAKE_CXX_COMPILER_IS_GCC)
|
2021-12-12 20:11:20 +00:00
|
|
|
|
string(REPLACE " ${_gcc_debug_flags}" "" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
|
|
|
|
|
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${_gcc_debug_flags}" CACHE STRING "" FORCE)
|
2021-12-08 11:32:04 +00:00
|
|
|
|
|
2021-12-12 20:11:20 +00:00
|
|
|
|
string(REPLACE " ${_gcc_debug_flags}" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
|
2021-12-08 11:32:04 +00:00
|
|
|
|
if(MYX_CMAKE_ENABLE_WARNING_FLAGS)
|
|
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG
|
|
|
|
|
"${CMAKE_CXX_FLAGS_DEBUG} ${MYX_CMAKE_DETECTED_CXX_FLAGS_DEBUG} ${_gcc_debug_flags}"
|
|
|
|
|
CACHE STRING "" FORCE)
|
|
|
|
|
else()
|
|
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG
|
|
|
|
|
"${CMAKE_CXX_FLAGS_DEBUG} ${_gcc_debug_flags}"
|
|
|
|
|
CACHE STRING "" FORCE)
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
2021-12-12 20:11:20 +00:00
|
|
|
|
set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL
|
|
|
|
|
"Enable generation of verbose build scripts." FORCE)
|
2021-12-08 11:32:04 +00:00
|
|
|
|
elseif(CMAKE_BUILD_TYPE STREQUAL Release)
|
2021-12-12 20:11:20 +00:00
|
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${MYX_CMAKE_DETECTED_CXX_FLAGS}"
|
2021-12-08 11:32:04 +00:00
|
|
|
|
CACHE STRING "" FORCE)
|
|
|
|
|
elseif(CMAKE_BUILD_TYPE STREQUAL None)
|
|
|
|
|
# Режим None используется для статического анализа кода
|
2021-12-12 20:11:20 +00:00
|
|
|
|
set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL
|
|
|
|
|
"Enable generation of verbose build scripts." FORCE)
|
2021-12-08 11:32:04 +00:00
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
unset(_gcc_debug_flags)
|
|
|
|
|
unset(_gcc_profile_flags)
|
|
|
|
|
|
|
|
|
|
cmake_policy(POP)
|