mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 04:53:36 +00:00
[cmake] Refactor root cmake
Moved options to OmimOptions.cmake Moved some parts of configuration to OmimConfig.cmake Removed disable color output option Renamed DISABLE_UNITY to CMAKE_UNITY_BUILD Renamed DIABLE_CCACHE to USE_CCACHE Signed-off-by: Andrei Shkrob <andrei@shkrob.dev>
This commit is contained in:
committed by
Konstantin Pastbin
parent
c1b45828b0
commit
0996917a1b
190
CMakeLists.txt
190
CMakeLists.txt
@@ -19,6 +19,15 @@ if (POLICY CMP0156)
|
||||
cmake_policy(SET CMP0156 NEW)
|
||||
endif()
|
||||
|
||||
set(OMIM_ROOT ${CMAKE_SOURCE_DIR})
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${OMIM_ROOT}/cmake")
|
||||
|
||||
include(OmimPlatform)
|
||||
include(OmimOptions)
|
||||
include(OmimConfig)
|
||||
include(OmimHelpers)
|
||||
include(OmimTesting)
|
||||
|
||||
if (APPLE AND NOT ("${CMAKE_SYSTEM_NAME}" STREQUAL Android))
|
||||
# OBJC/OBJCXX are needed to skip m/mm files in Unity builds.
|
||||
# https://gitlab.kitware.com/cmake/cmake/-/issues/21963
|
||||
@@ -36,24 +45,14 @@ endif()
|
||||
|
||||
message(STATUS "Using compiler ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
|
||||
|
||||
option(COVERAGE_REPORT "Configure for coverage report" OFF)
|
||||
|
||||
option(UNITY_DISABLE "Disable unity build" OFF)
|
||||
if (NOT UNITY_DISABLE AND NOT DEFINED ENV{UNITY_DISABLE})
|
||||
set(CMAKE_UNITY_BUILD ON)
|
||||
if (DEFINED ENV{UNITY_BUILD_BATCH_SIZE})
|
||||
set(CMAKE_UNITY_BUILD_BATCH_SIZE $ENV{UNITY_BUILD_BATCH_SIZE})
|
||||
else()
|
||||
set(CMAKE_UNITY_BUILD_BATCH_SIZE 50)
|
||||
endif()
|
||||
message(STATUS "Using Unity Build with batch ${CMAKE_UNITY_BUILD_BATCH_SIZE}, export UNITY_DISABLE=1 or use -DUNITY_DISABLE=ON to disable it.")
|
||||
if (CMAKE_UNITY_BUILD)
|
||||
message(STATUS "Using Unity Build with batch ${CMAKE_UNITY_BUILD_BATCH_SIZE}, use -DCMAKE_UNITY_BUILD=OFF to disable it.")
|
||||
endif()
|
||||
|
||||
option(CCACHE_DISABLE "Disable ccache" OFF)
|
||||
if (NOT CCACHE_DISABLE AND NOT DEFINED ENV{CCACHE_DISABLE})
|
||||
if (USE_CCACHE)
|
||||
find_program(CCACHE_PROGRAM ccache HINTS /usr/local/bin/)
|
||||
if (CCACHE_PROGRAM)
|
||||
message(STATUS "Using ccache, export CCACHE_DISABLE=1 or use -DCCACHE_DISABLE=ON to disable it.")
|
||||
message(STATUS "Using ccache, use -DUSE_CCACHE=OFF to disable it.")
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE_PROGRAM}")
|
||||
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
|
||||
@@ -61,38 +60,6 @@ if (NOT CCACHE_DISABLE AND NOT DEFINED ENV{CCACHE_DISABLE})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
option(COLORS_DISABLE "Disable colored compiler output" OFF)
|
||||
if (NOT DEFINED ENV{COLORS_DISABLE} AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
||||
message(STATUS "export COLORS_DISABLE=1 or use -DCOLORS_DISABLE=ON to disable colored compiler output.")
|
||||
add_compile_options($<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color=always> $<$<CXX_COMPILER_ID:Clang,AppleClang>:-fcolor-diagnostics>)
|
||||
add_link_options($<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color=always> $<$<CXX_COMPILER_ID:Clang,AppleClang>:-fcolor-diagnostics>)
|
||||
endif()
|
||||
|
||||
option(WITH_SYSTEM_PROVIDED_3PARTY "Enable compilation with system provided dependencies" OFF)
|
||||
set(OMIM_ROOT ${CMAKE_SOURCE_DIR})
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${OMIM_ROOT}/cmake")
|
||||
|
||||
include(OmimHelpers)
|
||||
include(OmimTesting)
|
||||
|
||||
set(PLATFORM_DESKTOP TRUE)
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
set(PLATFORM_LINUX TRUE)
|
||||
elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
||||
set(PLATFORM_MAC TRUE)
|
||||
elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
set(PLATFORM_WIN TRUE)
|
||||
elseif (CMAKE_SYSTEM_NAME STREQUAL "Android")
|
||||
set(PLATFORM_ANDROID TRUE)
|
||||
set(PLATFORM_DESKTOP FALSE)
|
||||
elseif (CMAKE_SYSTEM_NAME STREQUAL "iOS")
|
||||
set(PLATFORM_IPHONE TRUE)
|
||||
set(PLATFORM_DESKTOP FALSE)
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}")
|
||||
endif()
|
||||
|
||||
if(${PLATFORM_MAC})
|
||||
set(XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES)
|
||||
|
||||
@@ -106,23 +73,6 @@ if(${PLATFORM_MAC})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Sanitizer
|
||||
if (PLATFORM_DESKTOP)
|
||||
# https://clang.llvm.org/docs/UsersManual.html#controlling-code-generation
|
||||
set(BUILD_WITH_SANITIZER None CACHE STRING "Set to 'address' or others to enable sanitizer")
|
||||
|
||||
if (NOT ${BUILD_WITH_SANITIZER} MATCHES "None")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${BUILD_WITH_SANITIZER} -fno-omit-frame-pointer")
|
||||
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fsanitize=${BUILD_WITH_SANITIZER} -fno-omit-frame-pointer")
|
||||
message(STATUS "Enable sanitizer: ${BUILD_WITH_SANITIZER}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Set build type:
|
||||
if (NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Release")
|
||||
endif()
|
||||
|
||||
# Global compile options for all configurations.
|
||||
if (MSVC)
|
||||
add_compile_options(/utf-8)
|
||||
@@ -154,98 +104,6 @@ else()
|
||||
endif()
|
||||
|
||||
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
|
||||
# End of setting build type
|
||||
|
||||
# Options
|
||||
|
||||
# Call `make package` after cmake to build design tool.
|
||||
option(BUILD_DESIGNER "Build application as design tool" OFF)
|
||||
if (BUILD_DESIGNER)
|
||||
message(STATUS "Designer tool building is enabled")
|
||||
add_definitions(-DBUILD_DESIGNER)
|
||||
endif()
|
||||
|
||||
option(BUILD_STANDALONE "Build standalone application" OFF)
|
||||
if (BUILD_STANDALONE)
|
||||
message(STATUS "Standalone building is enabled")
|
||||
add_definitions(-DBUILD_STANDALONE)
|
||||
endif()
|
||||
|
||||
option(USE_ASAN "Enable Address Sanitizer" OFF)
|
||||
option(USE_TSAN "Enable Thread Sanitizer" OFF)
|
||||
option(USE_LIBFUZZER "Enable LibFuzzer" OFF)
|
||||
option(PYBINDINGS "Create makefiles for building python bindings" OFF)
|
||||
option(SKIP_QT_GUI "Skip building of Qt GUI" OFF)
|
||||
option(USE_PCH "Use precompiled headers" OFF)
|
||||
option(NJOBS "Number of parallel processes" OFF)
|
||||
option(ENABLE_VULKAN_DIAGNOSTICS "Enable Vulkan diagnostics" OFF)
|
||||
option(ENABLE_TRACE "Enable Tracing" OFF)
|
||||
|
||||
if (NJOBS)
|
||||
message(STATUS "Number of parallel processes: ${NJOBS}")
|
||||
set(CMAKE_JOB_POOLS custom=${NJOBS})
|
||||
set(CMAKE_JOB_POOL_COMPILE custom)
|
||||
set(CMAKE_JOB_POOL_LINK custom)
|
||||
set(CMAKE_JOB_POOL_PRECOMPILE_HEADER custom)
|
||||
endif()
|
||||
|
||||
# GCC 10.0 is required to support <charconv> header inclusion in base/string_utils.hpp
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0)
|
||||
message(FATAL_ERROR "Minimum supported g++ version is 10.0, yours is ${CMAKE_CXX_COMPILER_VERSION}")
|
||||
endif()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
set(PCH_EXTENSION "pch")
|
||||
endif()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
set(PCH_EXTENSION "gch")
|
||||
endif()
|
||||
|
||||
if (PLATFORM_LINUX)
|
||||
option(USE_PPROF "Enable Google Profiler" OFF)
|
||||
endif()
|
||||
|
||||
if (USE_ASAN)
|
||||
message(STATUS "Address Sanitizer is enabled")
|
||||
endif()
|
||||
|
||||
if (USE_TSAN)
|
||||
message(STATUS "Thread Sanitizer is enabled")
|
||||
endif()
|
||||
|
||||
if (USE_ASAN AND USE_TSAN)
|
||||
message(FATAL_ERROR "Can't use two different sanitizers together")
|
||||
endif()
|
||||
|
||||
if (USE_LIBFUZZER)
|
||||
message(STATUS "LibFuzzer is enabled")
|
||||
endif()
|
||||
|
||||
if (USE_PPROF)
|
||||
message(STATUS "Google Profiler is enabled")
|
||||
add_definitions(-DUSE_PPROF)
|
||||
endif()
|
||||
|
||||
if (USE_HEAPPROF)
|
||||
message(STATUS "Heap Profiler is enabled")
|
||||
endif()
|
||||
|
||||
if (ENABLE_VULKAN_DIAGNOSTICS)
|
||||
message(WARNING "Vulkan diagnostics are enabled. Be aware of performance impact!")
|
||||
add_definitions(-DENABLE_VULKAN_DIAGNOSTICS)
|
||||
endif()
|
||||
|
||||
if (ENABLE_TRACE)
|
||||
message(STATUS "Tracing is enabled")
|
||||
add_definitions(-DENABLE_TRACE)
|
||||
endif()
|
||||
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
# Set environment variables
|
||||
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
if (PLATFORM_LINUX OR PLATFORM_ANDROID)
|
||||
find_program(LLD_FOUND ld.lld)
|
||||
@@ -303,28 +161,6 @@ endif()
|
||||
# To allow #include "base/file_name.hpp" in all sources.
|
||||
include_directories(${CMAKE_HOME_DIRECTORY})
|
||||
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
if (USE_ASAN)
|
||||
add_compile_options(
|
||||
"-fsanitize=address"
|
||||
"-fno-omit-frame-pointer"
|
||||
)
|
||||
endif()
|
||||
|
||||
if (USE_TSAN)
|
||||
add_compile_options(
|
||||
"-fsanitize=thread"
|
||||
"-fno-omit-frame-pointer"
|
||||
)
|
||||
endif()
|
||||
|
||||
if (USE_LIBFUZZER)
|
||||
add_compile_options(
|
||||
"-fsanitize=fuzzer"
|
||||
)
|
||||
endif()
|
||||
|
||||
if (USE_PCH)
|
||||
message(STATUS "Precompiled headers are ON")
|
||||
set(OMIM_PCH_TARGET_NAME "omim_pch")
|
||||
|
||||
Reference in New Issue
Block a user