forked from yhirose/cpp-peglib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
68 lines (60 loc) · 2.13 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
cmake_minimum_required(VERSION 2.8)
# Check if a supported compiler is used and add c++11 flag:
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
message(FATAL_ERROR "Need at least gcc 4.9 to compile.")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(MSVC)
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19)
message(FATAL_ERROR "Visual Studio 2015 or newer is required.")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0)
message(FATAL_ERROR "Need at least AppleClang 7.0 to compile.")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
message(FATAL_ERROR "Clang below version 3.4 will most likely not work. Please upgrade your compiler.")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else() # no GNU, no MSVC, no Clang
message(WARNING "You are using an unsupported compiler. Compilation has only been tested with MSVC, GCC and Clang.")
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-std=c++11 HAS_CXX11_FLAG)
if(HAS_CXX11_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
message(FATAL_ERROR "Your compiler doesn't support the '-std=c++11' flag.")
endif()
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
set(warning_options -Weverything
-Wno-c++98-compat
-Wno-padded
-Wno-c++98-compat-pedantic
-Wno-exit-time-destructors
-Wno-missing-prototypes
-Wno-weak-vtables
-Wno-global-constructors
-Wno-format-nonliteral
-Wno-switch-enum
-Wno-missing-noreturn
-Wno-covered-switch-default
)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(warning_options -Wall -Wpedantic -Wextra)
elseif(MSVC)
set(warning_options /W4 /wd4503 /wd4512)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(add_link_deps pthread)
endif()
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
endif()
enable_testing()
add_subdirectory(test)
add_subdirectory(example)