-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
92 lines (75 loc) · 3.23 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
cmake_minimum_required(VERSION 3.1)
project(Units VERSION 0.0.1 LANGUAGES CXX)
#---------------------------------------------------------------------------------------
# include CMake modules
#---------------------------------------------------------------------------------------
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(AddCatchTest) # Function add_catch_test()
include(EnableCoverage) # Function target_enable_coverage()
include(EnableWarnings) # Function target_enable_warnings()
#---------------------------------------------------------------------------------------
# set default build to debug
#---------------------------------------------------------------------------------------
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose Release or Debug" FORCE)
endif()
# ---------------------------------------------------------------------------------------
# Set UNITS_MASTER_PROJECT to ON if we are building Units
# ---------------------------------------------------------------------------------------
# Check if Units is being used directly or via add_subdirectory, but allow overriding
if(NOT DEFINED UNITS_MASTER_PROJECT)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(UNITS_MASTER_PROJECT ON)
message(STATUS "Building Units as master project")
else()
set(UNITS_MASTER_PROJECT OFF)
endif()
endif()
#---------------------------------------------------------------------------------------
# compiler config
#---------------------------------------------------------------------------------------
option(CODE_COVERAGE "Enable coverage reporting" OFF)
option(UNITS_BUILD_TESTS "Build unit tests" ${UNITS_MASTER_PROJECT})
option(UNITS_BUILD_EXAMPLES "Build example files" ${UNITS_MASTER_PROJECT})
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
if(UNITS_BUILD_TESTS)
include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.13.4)
FetchContent_MakeAvailable(Catch2)
enable_testing()
add_subdirectory(tests)
endif()
if(UNITS_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
add_library(units STATIC
src/Buffer.cpp
src/Input.cpp
src/Output.cpp
src/Quantity.cpp
src/Unit.cpp
src/UnitData.cpp)
target_include_directories(units PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
if(UNITS_MASTER_PROJECT)
target_include_directories(units PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
else()
target_include_directories(units SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
endif()
set_target_properties(units PROPERTIES CXX_STANDARD 11)
set_target_properties(units PROPERTIES CXX_STANDARD_REQUIRED ON)
add_library(Units::Units ALIAS units)
#---------------------------------------------------------------------------------------
# Turn on compiler warnings
#---------------------------------------------------------------------------------------
if(UNITS_MASTER_PROJECT)
target_enable_warnings(units)
endif()
#---------------------------------------------------------------------------------------
# Enable (or disable) features based on the given options
#---------------------------------------------------------------------------------------
if(UNITS_MASTER_PROJECT AND CODE_COVERAGE)
target_enable_coverage(units)
endif()