geocore/CMakeLists.txt

173 lines
4.2 KiB
CMake

cmake_minimum_required(VERSION 3.2)
project(geocore C CXX)
set(CMAKE_CXX_STANDARD 14)
get_filename_component(GEOCORE_ROOT . ABSOLUTE)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${GEOCORE_ROOT}/cmake")
include(GeoCoreHelpers)
if (NOT SKIP_TESTS)
set(SKIP_TESTS FALSE)
ENABLE_TESTING()
configure_gtest()
endif()
# TCMalloc Linking
add_library(tcmalloc_config INTERFACE)
option(USE_TCMALLOC "Link TCMalloc memory allocator" ON)
if (USE_TCMALLOC)
find_package(tcmalloc)
target_link_libraries(tcmalloc_config INTERFACE tcmalloc)
endif()
# Code Coverage Configuration
add_library(coverage_config INTERFACE)
option(CODE_COVERAGE "Enable coverage reporting" OFF)
if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# Add required flags (GCC & LLVM/Clang)
target_compile_options(coverage_config INTERFACE
-O0 # no optimization
-g # generate debug info
--coverage # sets all required flags
)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
target_link_options(coverage_config INTERFACE --coverage)
else()
target_link_libraries(coverage_config INTERFACE --coverage)
endif()
endif()
# Set build type:
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
add_definitions(-DDEBUG)
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
add_definitions(-DRELEASE)
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
add_definitions(-DRELEASE)
add_compile_options(
"-fno-omit-frame-pointer"
)
else()
message(FATAL_ERROR "Unknown build type: " ${CMAKE_BUILD_TYPE})
endif()
message("Build type: " ${CMAKE_BUILD_TYPE})
# End of setting build type
option(USE_ASAN "Enable Address Sanitizer" OFF)
option(USE_TSAN "Enable Thread Sanitizer" OFF)
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND
CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0)
message(FATAL_ERROR "Minimum supported g++ version is 7.0 yours is ${CMAKE_CXX_COMPILER_VERSION}")
endif()
if (PLATFORM_LINUX)
option(USE_PPROF "Enable Google Profiler" OFF)
endif()
if (USE_ASAN)
message("Address Sanitizer is enabled")
endif()
if (USE_TSAN)
message("Thread Sanitizer is enabled")
endif()
if (USE_ASAN AND USE_TSAN)
message(FATAL_ERROR "Can't use two different sanitizers together")
endif()
if (USE_PPROF)
message("Google Profiler is enabled")
add_definitions(-DUSE_PPROF)
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})
# End of setting environment variables
# Find installed packages
find_package(Threads)
# TODO: Uncomment these lines when XCode project is finally generated by CMake.
#init_boost()
#install_boost_headers()
find_package(Boost ${BOOST_VERSION} EXACT COMPONENTS system filesystem serialization iostreams program_options REQUIRED)
set(Boost_USE_MULTITHREADED ON)
include_directories(${CMAKE_HOME_DIRECTORY})
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
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()
# Include subdirectories
add_subdirectory(3party/expat)
add_subdirectory(3party/icu)
add_subdirectory(3party/jansson)
add_subdirectory(3party/protobuf)
add_subdirectory(3party/succinct)
# Only options related to warnings should be placed here.
# Other options should be set before all add_subdirectory calls.
add_compile_options(
"-Wall"
"-Wextra"
"-Werror"
)
add_clang_compile_options("-Wshorten-64-to-32")
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
add_gcc_cpp_compile_options("-Wno-noexcept-type")
endif()
add_subdirectory(base)
add_subdirectory(coding)
add_subdirectory(geometry)
add_subdirectory(indexer)
add_subdirectory(platform)
add_subdirectory(generator)
add_subdirectory(geocoder)
add_custom_target(BuildVersion ALL
COMMAND ${CMAKE_COMMAND}
ARGS
-D MAPSME_CURRENT_PROJECT_ROOT=${GEOCORE_ROOT}
-D PATH_WITH_BUILD_VERSION_HPP=${GEOCORE_ROOT}
-D PROJECT_NAME=${PROJECT_NAME}
-P ${GEOCORE_ROOT}/cmake/BuildVersion.cmake
)