-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCMakeLists.txt
73 lines (61 loc) · 1.93 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
cmake_minimum_required(VERSION 3.4)
project(file_monitor)
option(file_monitor_BUILD_TESTS "Build tests" ON)
option(file_monitor_FIND_BOOST "Find boost library via find_package" OFF)
option(file_monitor_USE_CONAN "Use conan" ON)
option(file_monitor_USE_BOOST "Use boost instead of C++17 features" OFF)
option(file_monitor_USE_CXX17 "Use C++17 features" ON)
# Validate options
if (NOT file_monitor_USE_BOOST AND NOT file_monitor_USE_CXX17)
message(FATAL_ERROR "Need to enable either boost or C++17 for filesystem types")
endif()
if (file_monitor_FIND_BOOST AND NOT file_monitor_USE_BOOST)
message(FATAL_ERROR "No need to find boost if not using boost")
endif()
if (file_monitor_USE_BOOST)
message("Using boost::filesystem")
else()
message("Using std::filesystem")
endif()
# Optionally enable C++17
if (file_monitor_USE_CXX17)
set(CMAKE_CXX_STANDARD 17)
else()
set(CMAKE_CXX_STANDARD 14)
endif()
# Canonize platform selection
set(file_monitor_PLATFORM Undefined)
if(WIN32)
set(file_monitor_PLATFORM PLATFORM_WIN32)
elseif(APPLE)
set(file_monitor_PLATFORM PLATFORM_MACOS)
elseif(UNIX AND NOT APPLE)
set(file_monitor_PLATFORM PLATFORM_LINUX)
endif()
if (file_monitor_USE_CONAN)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
endif()
# Handle Boost dependency
if (file_monitor_USE_BOOST)
if (file_monitor_USE_CONAN)
set(BOOST_TARGETS
CONAN_PKG::boost_filesystem
CONAN_PKG::boost_algorithm
CONAN_PKG::boost_range)
if(file_monitor_PLATFORM STREQUAL PLATFORM_MACOS)
set(BOOST_TARGETS ${BOOST_TARGETS}
PUBLIC CONAN_PKG::boost_iostreams)
endif()
elseif(file_monitor_FIND_BOOST)
find_package(Boost REQUIRED COMPONENTS filesystem)
set(BOOST_TARGETS Boost::filesystem Boost::disable_autolinking)
endif()
endif()
# Go for the library
add_subdirectory(source)
if(file_monitor_BUILD_TESTS)
message("Building tests..")
# Go for the tests
add_subdirectory(tests)
endif()