[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:
Andrei Shkrob
2025-05-21 21:44:07 +02:00
committed by Konstantin Pastbin
parent c1b45828b0
commit 0996917a1b
8 changed files with 125 additions and 185 deletions

View File

@@ -90,7 +90,7 @@ jobs:
# -g1 should slightly reduce build time.
run: |
cmake . -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_FLAGS=-g1 -DUNITY_DISABLE=ON
-DCMAKE_CXX_FLAGS=-g1 -DCMAKE_UNITY_BUILD=OFF
- name: Compile
shell: bash

View File

@@ -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")

View File

@@ -6,3 +6,69 @@ set(OMIM_WARNING_FLAGS
set(3PARTY_INCLUDE_DIRS "${OMIM_ROOT}/3party/boost")
set(OMIM_DATA_DIR "${OMIM_ROOT}/data")
set(OMIM_USER_RESOURCES_DIR "${OMIM_ROOT}/data")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# 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 (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()
if (USE_ASAN AND USE_TSAN)
message(FATAL_ERROR "Can't use asan and tsan sanitizers together")
elseif (USE_ASAN)
message(STATUS "Address Sanitizer is enabled")
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
elseif (USE_TSAN)
message(STATUS "Thread Sanitizer is enabled")
add_compile_options(-fsanitize=thread -fno-omit-frame-pointer)
endif()
if (USE_LIBFUZZER)
message(STATUS "LibFuzzer is enabled")
add_compile_options(-fsanitize=fuzzer)
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()
if (BUILD_DESIGNER)
message(STATUS "Designer tool building is enabled")
add_definitions(-DBUILD_DESIGNER)
endif()
if (BUILD_STANDALONE)
message(STATUS "Standalone building is enabled")
endif()

View File

@@ -1,5 +1,3 @@
include(OmimConfig)
# Functions for using in subdirectories
function(omim_add_executable executable)
add_executable(${executable} ${ARGN})

19
cmake/OmimOptions.cmake Normal file
View File

@@ -0,0 +1,19 @@
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type")
option(CMAKE_UNITY_BUILD "Use unity build" ON)
set(CMAKE_UNITY_BUILD_BATCH_SIZE "50" CACHE STRING "Batch size for unity build")
option(USE_CCACHE "Use ccache" ON)
option(WITH_SYSTEM_PROVIDED_3PARTY "Enable compilation with system provided dependencies" OFF)
option(BUILD_DESIGNER "Build application as design tool" OFF)
option(BUILD_STANDALONE "Build standalone application" OFF)
option(USE_ASAN "Enable Address Sanitizer" OFF)
option(USE_TSAN "Enable Thread Sanitizer" OFF)
option(USE_LIBFUZZER "Enable LibFuzzer" OFF)
option(USE_HEAPPROF "Enable heap profiler" 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)
option(USE_PPROF "Enable Google Profiler" OFF)
option(COVERAGE_REPORT "Configure for coverage report" OFF)

23
cmake/OmimPlatform.cmake Normal file
View File

@@ -0,0 +1,23 @@
set(PLATFORM_LINUX FALSE)
set(PLATFORM_MAC FALSE)
set(PLATFORM_WIN FALSE)
set(PLATFORM_ANDROID FALSE)
set(PLATFORM_IPHONE FALSE)
set(PLATFORM_DESKTOP FALSE)
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(PLATFORM_LINUX TRUE)
set(PLATFORM_DESKTOP TRUE)
elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
set(PLATFORM_MAC TRUE)
set(PLATFORM_DESKTOP TRUE)
elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
set(PLATFORM_WIN TRUE)
set(PLATFORM_DESKTOP TRUE)
elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
set(PLATFORM_ANDROID TRUE)
elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
set(PLATFORM_IPHONE TRUE)
else ()
message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}")
endif ()

View File

@@ -1,5 +1,3 @@
include(OmimConfig)
# Tests read files from a data directory.
if (NOT SKIP_TESTS)
if (NOT IS_DIRECTORY ${CMAKE_BINARY_DIR}/data AND NOT IS_SYMLINK ${CMAKE_BINARY_DIR}/data)

View File

@@ -160,9 +160,9 @@ tools/unix/build_omim.sh -d help
#### Build issues
- If you get "not enough memory" errors during builds, you may disable
[CMake Unity Builds](https://cmake.org/cmake/help/latest/prop_tgt/UNITY_BUILD.html) with `export UNITY_DISABLE=1`
or by passing `-DUNITY_DISABLE=1` option to `cmake` invocation. Or you can reduce Unity build batch size from
the default `50` to a lower value (`2`-`16`) with `export UNITY_BUILD_BATCH_SIZE=8`.
[CMake Unity Builds](https://cmake.org/cmake/help/latest/prop_tgt/UNITY_BUILD.html) by passing
`-DCMAKE_UNITY_BUILD=OFF` option to `cmake` invocation. Or you can reduce Unity build batch size from
the default `50` to a lower value (`2`-`16`) by passing `-DCMAKE_UNITY_BUILD_BATCH_SIZE=8`.
Note that these changes may significantly increase the build time.
### Running