-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
137 lines (120 loc) · 4.71 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
cmake_minimum_required(VERSION 3.0.0)
project(cpptoml)
include(CheckCXXCompilerFlag)
include(CheckCXXSourceCompiles)
include(CheckCXXSourceRuns)
option(USE_LIBCXX "Use libc++ for the C++ standard library" ON)
if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if(USE_LIBCXX)
message("-- Locating libc++...")
find_library(LIBCXX_LIBRARY NAMES c++ cxx)
if(LIBCXX_LIBRARY)
message("-- Located libc++, using it.")
set(LIBCXX_OPTIONS "-stdlib=libc++")
message("-- Locating libc++'s abi...")
find_library(LIBCXXABI_LIBRARY NAMES c++abi)
find_library(LIBCXXRT_LIBRARY NAMES cxxrt)
if(LIBCXXABI_LIBRARY)
message("-- Found libc++abi, using it.")
set(CXXABI_LIBRARY ${LIBCXXABI_LIBRARY})
elseif(LIBCXXRT_LIBRARY)
message("-- Found libcxxrt, using it.")
set(CXXABI_LIBRARY ${LIBCXXRT_LIBRARY})
else()
message("-- No abi library found. "
"Attempting to continue without one...")
endif()
else()
message("-- Could not find libc++, will not use it.")
endif()
endif()
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXX_OPTIONS}")
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${CXXABI_LIBRARY}")
# if we don't already set the standard for the compiler, detect the
# best one available and use it
if(NOT "${CMAKE_CXX_FLAGS}" MATCHES "std=c\\+\\+(0x|11|1y|14)")
check_cxx_compiler_flag(-std=c++14 HAS_CXX14)
if(HAS_CXX14)
message("-- Compiler supports C++14 (using it)")
set(STDOPT "-std=c++14")
endif()
if(NOT STDOPT)
check_cxx_compiler_flag(-std=c++1y HAS_CXX1Y)
if(HAS_CXX1Y)
message("-- Compiler supports C++1y (using it)")
set(STDOPT "-std=c++1y")
endif()
endif()
if(NOT STDOPT)
check_cxx_compiler_flag(-std=c++11 HAS_CXX11)
if(HAS_CXX11)
message("-- Compiler supports C++11 (using it)")
set(STDOPT "-std=c++11")
endif()
endif()
if(NOT STDOPT)
check_cxx_compiler_flag(-std=c++0x HAS_CXX0X)
if(HAS_CXXOX)
message("-- Compiler supports C++0x (using it)")
set(STDOPT "-std=c++0x")
endif()
endif()
if(NOT STDOPT)
message(FATAL_ERROR
"cpptoml requires a compiler with at least C++0x support")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${STDOPT}")
endif()
endif()
check_cxx_source_compiles("
#include <iomanip>
int main() {
std::tm t;
std::put_time(&t, \"%Y\");
return 0;
}" CPPTOML_HAS_STD_PUT_TIME)
check_cxx_source_runs("
#include <cstring>
#include <ctime>
#include <regex>
int main() {
std::string to_match = \"2014-02-05T14:30:05Z\";
std::regex pattern{\"(\\\\\\\\d{4})-(\\\\\\\\d{2})-(\\\\\\\\d{2})T(\\\\\\\\d{2}):(\\\\\\\\d{2}):(\\\\\\\\d{2})Z\"};
std::match_results<std::string::const_iterator> results;
std::regex_match(to_match, results, pattern);
std::tm date;
std::memset(&date, '\\\\0', sizeof(date));
date.tm_year = stoi(results[1]) - 1900;
date.tm_mon = stoi(results[2]) - 1;
date.tm_mday = stoi(results[3]);
date.tm_hour = stoi(results[4]);
date.tm_min = stoi(results[5]);
date.tm_sec = stoi(results[6]);
return 0;
}" CPPTOML_HAS_STD_REGEX)
add_library(cpptoml INTERFACE)
target_include_directories(cpptoml INTERFACE ${PROJECT_SOURCE_DIR}/include)
target_compile_options(cpptoml INTERFACE ${STDOPT} ${LIBCXX_OPTIONS})
if(CPPTOML_HAS_STD_PUT_TIME)
target_compile_definitions(cpptoml INTERFACE -DCPPTOML_HAS_STD_PUT_TIME=1)
endif()
if (CPPTOML_HAS_STD_REGEX)
target_compile_definitions(cpptoml INTERFACE -DCPPTOML_HAS_STD_REGEX=1)
endif()
target_link_libraries(cpptoml INTERFACE ${LIBCXX_LIBRARY} ${CXXABI_LIBRARY})
add_executable(parse parse.cpp)
target_link_libraries(parse cpptoml)
add_executable(cpptoml-parser parse_stdin.cpp)
target_link_libraries(cpptoml-parser cpptoml)
find_package(Doxygen)
if(DOXYGEN_FOUND AND NOT TARGET doc)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cpptoml.doxygen.in
${CMAKE_CURRENT_BINARY_DIR}/cpptoml.doxygen @ONLY)
add_custom_target(doc
${DOXYGEN_EXECUTABLE}
${CMAKE_CURRENT_BINARY_DIR}/cpptoml.doxygen
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif()