Переписана работа с флагами по умолчанию

This commit is contained in:
Andrei Astafev 2020-04-27 19:30:41 +03:00
parent 9df188963e
commit 23be253a8d

View File

@ -21,32 +21,24 @@ else()
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} -ggdb -pg -fno-omit-frame-pointer)
list(REMOVE_DUPLICATES CMAKE_C_FLAGS_PROFILE)
set(CMAKE_C_FLAGS_PROFILE CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_PROFILE ${CMAKE_CXX_FLAGS_RELEASE} -ggdb -pg -fno-omit-frame-pointer)
list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS_PROFILE)
set(CMAKE_CXX_FLAGS_PROFILE CACHE STRING "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_PROFILE ${CMAKE_EXE_LINKER_FLAGS_RELEASE} -pg)
list(REMOVE_DUPLICATES CMAKE_EXE_LINKER_FLAGS_PROFILE)
set(CMAKE_EXE_LINKER_FLAGS_PROFILE CACHE STRING "" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_PROFILE ${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -pg)
list(REMOVE_DUPLICATES CMAKE_SHARED_LINKER_FLAGS_PROFILE)
set(CMAKE_SHARED_LINKER_FLAGS_PROFILE CACHE STRING "" FORCE)
set(CMAKE_STATIC_LINKER_FLAGS_PROFILE ${CMAKE_STATIC_LINKER_FLAGS_RELEASE} -pg)
list(REMOVE_DUPLICATES CMAKE_STATIC_LINKER_FLAGS_PROFILE)
set(CMAKE_STATIC_LINKER_FLAGS_PROFILE CACHE STRING "" FORCE)
set(CMAKE_MODULE_LINKER_FLAGS_PROFILE ${CMAKE_MODULE_LINKER_FLAGS_RELEASE} -pg)
list(REMOVE_DUPLICATES CMAKE_MODULE_LINKER_FLAGS_PROFILE)
set(CMAKE_MODULE_LINKER_FLAGS_PROFILE CACHE STRING "" FORCE)
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} ${_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)
@ -58,13 +50,11 @@ if(CMAKE_BUILD_TYPE STREQUAL Profile)
elseif(CMAKE_BUILD_TYPE STREQUAL Debug)
# В режиме отладки подробный вывод сообщений компилятора
if(CMAKE_CXX_COMPILER_IS_Clang OR CMAKE_CXX_COMPILER_IS_GCC)
set(CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} -ggdb -fno-omit-frame-pointer)
list(REMOVE_DUPLICATES CMAKE_C_FLAGS_DEBUG)
set(CMAKE_C_FLAGS_DEBUG CACHE STRING "" FORCE)
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)
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} -ggdb -fno-omit-frame-pointer)
list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS_DEBUG)
set(CMAKE_CXX_FLAGS_DEBUG CACHE STRING "" FORCE)
string(REPLACE " ${_gcc_debug_flags}" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${_gcc_debug_flags}" CACHE STRING "" FORCE)
endif()
set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "Enable generation of verbose build scripts." FORCE)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "Enable generation of compile_commands.json." FORCE)
@ -77,3 +67,6 @@ elseif(CMAKE_BUILD_TYPE STREQUAL None)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "Enable generation of compile_commands.json." FORCE)
set(ANALYSIS 1)
endif()
unset(_gcc_debug_flags)
unset(_gcc_profile_flags)