-
Notifications
You must be signed in to change notification settings - Fork 28
/
CMakeLists.txt
136 lines (111 loc) · 4.53 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
132
133
134
135
136
cmake_minimum_required(VERSION 3.6 FATAL_ERROR)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
cmake_host_system_information(RESULT CORE_COUNT QUERY NUMBER_OF_LOGICAL_CORES)
set(CMAKE_VERBOSE_MAKEFILE true CACHE BOOL "")
set(USED_CMAKE_GENERATOR "${CMAKE_GENERATOR}" CACHE STRING "Expose CMAKE_GENERATOR" FORCE)
if (USED_CMAKE_GENERATOR MATCHES "Ninja")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")
endif ()
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif ()
################################################################################
option(WITH_THREADS "use Threads" TRUE)
option(WITH_BOOST "use Boost" FALSE)
option(WITH_WCHAR "use wchar_t for system calls (instead of char)" FALSE)
option(WITH_EXCEPTIONS "use exceptions" FALSE)
################################################################################
################################################################################
option(BUILD_DOC "Build documentation" OFF)
# check if Doxygen is installed
find_package(Doxygen)
if (DOXYGEN_FOUND AND BUILD_DOC)
# set input and output files
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
# request to configure the file
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
message("Doxygen build started")
# note the option ALL which allows to build the docs together with the application
add_custom_target( doc_doxygen ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM )
else (DOXYGEN_FOUND AND BUILD_DOC)
message("Doxygen need to be installed to generate the doxygen documentation")
endif (DOXYGEN_FOUND AND BUILD_DOC)
################################################################################
################################################################################
option(BUILD_JSLIB "Build JS version of TML library" OFF)
option(BUILD_JSMODULE "Build JS version of TML library (ES6 module)" OFF)
if (BUILD_JSMODULE)
set(BUILD_JSLIB ON CACHE STRING "")
endif ()
if (BUILD_JSLIB)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
include(emscripten_toolchain)
set_emscripten_toolchain()
set(BUILD_TESTS OFF CACHE STRING "") # no automated tests
set(BUILD_CODE_COVERAGE OFF CACHE STRING "") # no coverage
endif ()
################################################################################
project(tml)
if (BUILD_JSLIB)
if (EMSCRIPTEN)
add_subdirectory("js")
endif ()
else ()
add_subdirectory("src")
endif ()
set(BUILD_TESTS ON CACHE STRING "build the tml test suite ON")
set_property(CACHE BUILD_TESTS PROPERTY STRINGS "OFF" "ON")
# Testing
if (BUILD_TESTS)
set(DOCTEST_HEADER "${PROJECT_SOURCE_DIR}/src/doctest.h" CACHE PATH "Doctest header")
if (NOT EXISTS "${DOCTEST_HEADER}")
message(STATUS "Downloading doctest to '${PROJECT_SOURCE_DIR}'")
find_package(Wget REQUIRED)
execute_process(COMMAND "${WGET_EXECUTABLE}" https://raw.githubusercontent.com/onqtam/doctest/master/doctest/doctest.h -P ${PROJECT_SOURCE_DIR}/src)
endif ()
add_library(doctest INTERFACE)
target_compile_definitions(doctest INTERFACE TML_USE_DOCTEST)
set(TEST_FRAMEWORK doctest)
enable_testing()
add_subdirectory(tests)
endif ()
option(BUILD_CLANG_TIDY "Run clang tidy" FALSE)
option(BUILD_CLANG_FORMAT "Run clang format" FALSE)
option(BUILD_CPPCHECK "Run cppcheck" FALSE)
option(BUILD_CODE_COVERAGE "Generate code coverage" FALSE)
option(BUILD_TML_CHECK "Build TML parsing check" TRUE)
message(STATUS "CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "CMAKE_CXX_COMPILER_ID ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER}")
if (BUILD_CLANG_TIDY AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
include(clang-tidy)
endif ()
if (BUILD_CLANG_FORMAT AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
include(clang-format)
endif ()
if (BUILD_CPPCHECK)
message(STATUS "Including cppcheck")
include(cppcheck)
endif ()
if (BUILD_CODE_COVERAGE)
find_program(GCOVR gcovr)
if (GCOVR)
message(STATUS "Including code coverage")
set(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage" CACHE STRING "Code coverage CXX options" FORCE)
include(code-coverage)
append_coverage_compiler_flags()
else ()
message(WARNING "Gcovr not found!")
endif ()
endif ()
if (BUILD_TML_CHECK)
message(STATUS "Including tml parsing check")
include(tml-check)
endif ()
endif ()