forked from Samuel-Tyler/fast_ber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
61 lines (53 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
cmake_minimum_required(VERSION 3.20)
project(fast_ber VERSION "0.4")
if (NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 23)
endif()
option(SKIP_TESTING "Skip building tests" ON)
option(SKIP_AUTO_GENERATION "Use checked in lexer rather than generating with bison" OFF)
if (NOT ${SKIP_TESTING})
enable_testing()
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(default_build_type Release)
set(BENCHMARKS_INCLUDE_ASN1C true)
find_package(Boost REQUIRED COMPONENTS date_time)
if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
if (CMAKE_BUILD_TYPE MATCHES "Release")
add_compile_options("-O3")
endif()
add_compile_options("-Wall" "-Wextra" "-pedantic" "-Wcast-align" "-Wpointer-arith" "-Wshadow")
add_compile_options("-Wfloat-equal" "-Wuninitialized")
add_compile_options("-Wno-missing-field-initializers") # Stop spam on g++-4.8
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast")
if (CMAKE_BUILD_TYPE MATCHES "Debug")
add_compile_options("-g")
if (${FB_ENABLE_SANITIZER})
message("Enabled sanitizer")
add_compile_options("-fsanitize=address" "-fsanitize=undefined" "-Werror")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -fsanitize=undefined -static-libsan")
endif()
else()
add_definitions("-DNDEBUG -march=native")
if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# Link time optimisation. Disabled on clang due to issue on travis
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -flto")
endif()
set(SKIP_AUTO_GENERATION true)
endif()
else()
set(SKIP_AUTO_GENERATION true) # Can't autogen on windows, used checked in files instead
set(BENCHMARKS_INCLUDE_ASN1C false)
set(CTEST_CONFIGURATION_TYPE "${CMAKE_BUILD_TYPE}")
add_compile_options("/W4")
add_compile_options("-DNOMINMAX")
if (CMAKE_BUILD_TYPE MATCHES "Release")
add_compile_options("/O2")
endif ()
endif()
add_subdirectory(src)
if (DEFINED CMAKE_TESTING_ENABLED)
add_subdirectory(test)
add_subdirectory(sample)
add_subdirectory(benchmarks)
endif()