forked from cieslarmichal/faker-cxx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
59 lines (49 loc) · 1.8 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
cmake_minimum_required(VERSION 3.22)
project(faker-cxx
LANGUAGES CXX
VERSION 2.0.0
DESCRIPTION "C++ Faker library for generating fake (but realistic) data."
HOMEPAGE_URL "https://github.com/cieslarmichal/faker-cxx")
include(cmake/CompilerWarnings.cmake)
include(CMakeDependentOption)
option(USE_SYSTEM_DEPENDENCIES "Use fmt and GTest from system" OFF)
option(BUILD_EXAMPLES "Build examples" OFF)
option(BUILD_TESTING "Build tests" ON)
option(CODE_COVERAGE "Build faker-cxx with coverage support" OFF)
if (MSVC)
set(CMAKE_REQUIRED_FLAGS /std:c++20)
else()
set(CMAKE_REQUIRED_FLAGS -std=c++20)
endif()
include(CheckCXXSourceCompiles)
check_cxx_source_compiles("#include <format>\nint main(){ auto var = std::format(\"{}\", \"Hello\"); return 0; }"
HAS_STD_FORMAT)
if (NOT HAS_STD_FORMAT)
message(STATUS "Compiler has no support for std::format. Need to use fmt library as dependency.")
endif()
cmake_dependent_option(USE_STD_FORMAT "Use std::format when available" ON "HAS_STD_FORMAT" OFF)
add_library(${CMAKE_PROJECT_NAME})
if (USE_SYSTEM_DEPENDENCIES)
find_package(fmt CONFIG REQUIRED)
elseif (NOT USE_STD_FORMAT)
add_subdirectory("${CMAKE_SOURCE_DIR}/externals/fmt")
find_library(FMT_LIBRARY fmt)
if (NOT FMT_LIBRARY)
message(FATAL_ERROR "Could not find fmt library. Please, read the contribution guide.")
endif()
set(FMT_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/externals/fmt/include")
endif ()
add_subdirectory(src)
if (CODE_COVERAGE)
set(target_code_coverage_ALL 1)
include("cmake/cmake-coverage.cmake")
add_code_coverage_all_targets(EXCLUDE tests/*)
target_code_coverage(${CMAKE_PROJECT_NAME} ALL)
endif ()
if (BUILD_TESTING)
enable_testing()
add_subdirectory(tests)
endif ()
if (BUILD_EXAMPLES)
add_subdirectory(examples)
endif ()