-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
131 lines (113 loc) · 3.9 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
cmake_minimum_required(VERSION 3.1.0)
project(cppglob VERSION 1.1.0 LANGUAGES CXX)
option(BUILD_STATIC "Build static library" OFF)
option(BUILD_SHARED "Build shared library" ON)
option(BUILD_TEST "Build test" OFF)
option(WITH_COTIRE "Use cotire to create precompiled header before build" OFF)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
if (WITH_COTIRE)
include(cotire)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
set(BUILD_TEST ON)
endif()
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE ON)
set(BUILD_SHARED_LIBS ON)
set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_definitions("-DCPPGLOB_BUILDING")
file(GLOB cpp_sources ${PROJECT_SOURCE_DIR}/src/*.cpp)
if(MSVC)
set(CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
)
if(BUILD_SHARED_LIBS)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MT" "/MD" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
else()
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
endif()
endif()
# compiler requirements
if (MSVC)
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.14)
message(WARNING "MSVC < 19.14 is currently not supported. Some errors may be caused during build")
endif()
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.1)
message(WARNING "GCC < 8.1 is currently not supported. Some errors may be caused during build")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5.0)
message(WARNING "Clang < 3.5.0 is currently not supported. Some errors may be caused during build")
endif()
else()
message(WARNING "Your compiler is currently not supported. Some errors may be caused during build")
endif()
# enable C++17 support
if (CMAKE_VERSION VERSION_LESS "3.8.2")
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0.0)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
endif()
else()
message(FATAL_ERROR "Your cmake version is not supported. Please update cmake.")
endif()
else()
set(CMAKE_CXX_STANDARD 17)
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Coverage")
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
message(STATUS "Coverage option enabled!")
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 3)
message(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...")
else()
message(STATUS "Coverage option enabled!")
endif()
else()
message(FATAL_ERROR "Coverage report requires GNU gcc compiler")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
add_definitions("-DCPPGLOB_COVERAGE")
endif()
# Use libc++ in Mac OSX
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
include_directories(include)
add_subdirectory(src)
if(BUILD_TEST)
enable_testing()
add_subdirectory(test)
endif()
install(
DIRECTORY include/cppglob
DESTINATION include
COMPONENT headers)
install(
EXPORT cppglob-config
DESTINATION share/cmake/cppglob)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake
)