-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
executable file
·66 lines (51 loc) · 1.94 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
# Basic CMake project
cmake_minimum_required(VERSION 2.8.2)
# Output compilation database for clangtidy
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
# Set default build type to Release
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Release.")
set(CMAKE_BUILD_TYPE "Release")
endif()
# Include the current directory in every build
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Name the project
project(primes CXX)
# Enable C++17 features on gcc/clang
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Clang)")
set(CMAKE_CXX_FLAGS "-fcolor-diagnostics -Weverything -Wpedantic -Werror -std=c++1z")
# Turn off select warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++98-compat -Wno-padded")
# TODO Remove on C++17 compatibility
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-implicit-fallthrough")
endif()
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(GCC)")
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Werror -std=c++1z")
set(CMAKE_CXX_FLAGS_DEBUG "-Og")
endif()
# Add pthread support
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
# Locate Boost libraries: unit_test_framework
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
# Add primes to a lib
add_library(primes primes.cpp primes.h)
# Build executable from sources and headers
add_executable(unittest primes test/unittest.cpp)
# Link to Boost
target_link_libraries(unittest primes ${Boost_LIBRARIES})
# Turn off warnings on unittest file due to Boost
set_source_files_properties(test/unittest.cpp PROPERTIES COMPILE_FLAGS "-w")
# Add this as a test
enable_testing()
add_test(unittest unittest)
add_custom_command(TARGET unittest
POST_BUILD
COMMAND unittest
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
# Add benchmark executable
add_executable(benchmark test/benchmark.cpp)
target_link_libraries(benchmark primes)