You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

100 lines
4.0 KiB

cmake_minimum_required(VERSION 3.23)
# Make sure the user doesn't play dirty with symlinks
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)
# Disallow in-source builds
if(${srcdir} STREQUAL ${bindir})
message(FATAL_ERROR "In-source builds are not allowed."
" Please create a directory and run cmake from there, passing the path"
" to this source directory as the last argument. This process created"
" the file `CMakeCache.txt' and the directory `CMakeFiles' in ${srcdir}."
" Please remove them.")
endif()
project(odm CXX)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel" FORCE)
endif()
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/" CACHE INTERNAL "Location of our custom CMake modules." FORCE)
include_directories(include)
# Checking compiler options
set(default_options -Wall)
set(linker_options -Wall)
include(CheckCXXCompilerFlag)
set(saved_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
# C++20 is required
CHECK_CXX_COMPILER_FLAG(-std=c++20 COMPILER_SUPPORTS_CXX20)
if(COMPILER_SUPPORTS_CXX20)
set(default_options ${default_options} -std=c++20)
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++20 support. Please use a different C++ compiler.")
endif()
# OpenMP is required
CHECK_CXX_COMPILER_FLAG(-fopenmp COMPILER_SUPPORTS_OPENMP)
if(COMPILER_SUPPORTS_OPENMP)
set(default_options ${default_options} -fopenmp)
set(linker_options ${linker_options} -fopenmp)
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no OpenMP support. Please use a different C++ compiler.")
endif()
# Link time optimization check
set(CMAKE_REQUIRED_FLAGS -flto=auto)
CHECK_CXX_COMPILER_FLAG(-flto=auto COMPILER_SUPPORTS_FLTO)
if(COMPILER_SUPPORTS_FLTO AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
set(default_options ${default_options} -flto=auto)
set(linker_options ${linker_options} -flto=auto)
endif()
unset(CMAKE_REQUIRED_FLAGS)
# Clang can use lto only with gold linker
if(NOT COMPILER_SUPPORTS_FLTO)
set(CMAKE_REQUIRED_FLAGS -flto\ -fuse-ld=gold)
CHECK_CXX_COMPILER_FLAG(-flto\ -fuse-ld=gold COMPILER_SUPPORTS_FLTO_GOLD)
if(COMPILER_SUPPORTS_FLTO_GOLD AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
set(default_options ${default_options} -flto)
set(linker_options ${linker_options} -flto\ -fuse-ld=gold)
endif()
unset(CMAKE_REQUIRED_FLAGS)
endif()
# Dwarf-4 support check
set(CMAKE_REQUIRED_FLAGS -gdwarf-4)
CHECK_CXX_COMPILER_FLAG(-gdwarf-4 COMPILER_SUPPORTS_DWARF4)
if(COMPILER_SUPPORTS_DWARF4 AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
set(default_options ${default_options} -gdwarf-4)
set(linker_options ${linker_options} -gdwarf-4)
endif()
unset(CMAKE_REQUIRED_FLAGS)
# -ipo flag check (Intel compiler link time optimization)
set(CMAKE_REQUIRED_FLAGS -ipo)
CHECK_CXX_COMPILER_FLAG(-ipo COMPILER_SUPPORTS_IPO)
if(COMPILER_SUPPORTS_IPO AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
set(default_options ${default_options} -ipo)
set(linker_options ${linker_options} -ipo)
endif()
unset(CMAKE_REQUIRED_FLAGS)
# Default hidden visibility check
set(CMAKE_REQUIRED_FLAGS -fvisibility=hidden)
CHECK_CXX_COMPILER_FLAG(-fvisibility=hidden COMPILER_SUPPORTS_HIDDEN)
if(COMPILER_SUPPORTS_HIDDEN)
set(default_options ${default_options} -fvisibility=hidden)
set(linker_options ${linker_options} -fvisibility=hidden)
endif()
unset(CMAKE_REQUIRED_FLAGS)
# Export dynamic. Required as modules mast call functions from main programm
set(CMAKE_REQUIRED_FLAGS -Wl,--export-dynamic)
CHECK_CXX_COMPILER_FLAG(-Wl,--export-dynamic COMPILER_SUPPORTS_EXPORTDYNAMIC)
if(COMPILER_SUPPORTS_EXPORTDYNAMIC)
set(linker_options ${linker_options} -Wl,--export-dynamic)
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no support of --export-dynamic. Please use a different C++ compiler.")
endif()
unset(CMAKE_REQUIRED_FLAGS)
add_compile_options(${default_options})
set(CMAKE_REQUIRED_FLAGS ${saved_CMAKE_REQUIRED_FLAGS})
add_subdirectory(src)