forked from lispparser/sexp-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
105 lines (89 loc) · 4.03 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
# SExp - A S-Expression Parser for C++
# Copyright (C) 2015 Ingo Ruhnke <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
cmake_minimum_required(VERSION 3.0)
project(sexp VERSION 0.1.0)
option(WARNINGS "Switch on extra warnings" OFF)
option(WERROR "Turn warnings into errors" OFF)
option(USE_LOCALE "Use C++ locale support" OFF)
if(WARNINGS)
set(WARNINGS_CXX_FLAGS ${WARNINGS_CXX_FLAGS}
-pedantic -Wall -Wextra -Wno-c++0x-compat -Wnon-virtual-dtor
-Wshadow -Wcast-qual -Winit-self -Wno-unused-parameter
-Weffc++ -Wconversion -Wold-style-cast)
# -Winline -Wfloat-equal -Wunreachable-code
endif()
if(WERROR)
set(WARNINGS_CXX_FLAGS ${WARNINGS_CXX_FLAGS}
-Werror)
endif()
find_package(Threads REQUIRED)
add_compile_options(-std=c++11)
if(USE_LOCALE)
add_definitions(-DSEXP_USE_LOCALE)
endif()
# file(GLOB SUPERTUX_LISP_SOURCES supertux/lisp/*.cpp)
# add_library(supertux-lisp ${SUPERTUX_LISP_SOURCES})
# target_include_directories(supertux-lisp SYSTEM PUBLIC supertux)
# file(GLOB PINGUS_LISP_SOURCES pingus/lisp/*.cpp)
# add_library(pingus-lisp ${PINGUS_LISP_SOURCES})
# target_include_directories(pingus-lisp SYSTEM PUBLIC pingus)
file(GLOB SEXP_SOURCES src/*.cpp)
add_library(sexp ${SEXP_SOURCES})
target_compile_options(sexp PRIVATE ${WARNINGS_CXX_FLAGS})
target_include_directories(sexp SYSTEM PUBLIC include)
if(BUILD_TESTS)
# build gtest
# ${CMAKE_CURRENT_SOURCE_DIR} in include_directories is needed to generate -isystem instead of -I flags
add_library(gtest_main STATIC ${CMAKE_CURRENT_SOURCE_DIR}/external/googletest/googletest/src/gtest_main.cc)
target_include_directories(gtest_main SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/external/googletest/googletest/include/)
add_library(gtest STATIC ${CMAKE_CURRENT_SOURCE_DIR}/external/googletest/googletest/src/gtest-all.cc)
target_include_directories(gtest SYSTEM PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/external/googletest/googletest/)
target_include_directories(gtest SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/external/googletest/googletest/include/)
# build sexp tests
file(GLOB TEST_SEXP_SOURCES tests/*.cpp)
add_executable(test_sexp ${TEST_SEXP_SOURCES})
target_compile_options(test_sexp PRIVATE ${WARNINGS_CXX_FLAGS})
target_link_libraries(test_sexp
gtest gtest_main
sexp
${CMAKE_THREAD_LIBS_INIT})
# add 'make test' target, use 'make test ARGS="-V"' or 'ctest -V' for verbose
enable_testing()
add_test(NAME test_sexp
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND test_sexp)
endif()
if(BUILD_BENCHMARKS)
# build google-benchmark
include_directories(${PROJECT_SOURCE_DIR}/src)
file(GLOB BENCHMARK_SOURCES external/benchmark/src/*.cc)
add_library(benchmark ${BENCHMARK_SOURCES})
target_compile_definitions(benchmark PRIVATE -DHAVE_STD_REGEX)
target_compile_options(benchmark PRIVATE -std=c++1y)
target_include_directories(benchmark SYSTEM PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/external/benchmark/include)
# build benchmarks
file(GLOB BENCHMARKSOURCES benchmarks/*.cpp)
foreach(SOURCE ${BENCHMARKSOURCES})
get_filename_component(SOURCE_BASENAME ${SOURCE} NAME_WE)
add_executable(${SOURCE_BASENAME} ${SOURCE})
target_link_libraries(${SOURCE_BASENAME} benchmark sexp ${CMAKE_THREAD_LIBS_INIT})
set_target_properties(${SOURCE_BASENAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/benchmarks/")
target_compile_options(${SOURCE_BASENAME} PRIVATE -std=c++1y ${WARNINGS_CXX_FLAGS})
endforeach(SOURCE)
endif()
# EOF #