-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
CMakeLists.txt
122 lines (100 loc) · 3.16 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
cmake_minimum_required(VERSION 3.14)
project(
"ctpg"
VERSION 1.3.6
DESCRIPTION "Compile Time Parser Generator. A single header library turning c++ code into LR(1) parser with finite state machine lexer in compile time."
HOMEPAGE_URL "https://github.com/peter-winter/ctpg"
LANGUAGES CXX
)
# CMake module dependencies
include(CMakePackageConfigHelpers)
include(CTest)
include(GNUInstallDirs)
# CTPG specific options
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" is_top_level)
option(CTPG_ENABLE_INSTALL "Include project-specific install rules" "${is_top_level}")
option(CTPG_ENABLE_TESTS "Build test binaries" "${BUILD_TESTING}")
if (NOT DEFINED CTPG_INSTALL_CMAKEDIR)
set(CTPG_INSTALL_CMAKEDIR "${CMAKE_INSTALL_DATAROOTDIR}/ctpg/cmake"
CACHE STRING "Install path for ctpg CMake files")
endif ()
option(CTPG_WARNING_FLAGS "When ON, enable all warnings and promote warnings to errors." "${is_top_level}")
# CTPG header-only library
add_library(ctpg INTERFACE)
add_library(ctpg::ctpg ALIAS ctpg)
target_include_directories(ctpg INTERFACE "$<BUILD_INTERFACE:${ctpg_SOURCE_DIR}/include>")
target_compile_features(ctpg INTERFACE cxx_std_17)
# Test
if (CTPG_ENABLE_TESTS)
find_package(Catch2 2 REQUIRED)
add_executable(testbin
tests/main.cpp
tests/regex_tests_1.cpp
tests/regex_tests_2.cpp
tests/regex_tests_3.cpp
tests/simple_cases.cpp
tests/simple_grammar.cpp
tests/empty_symbols.cpp
tests/recurrence.cpp
tests/precedence.cpp
tests/compile_time.cpp
tests/list_helpers.cpp
tests/skip_whitespace.cpp
tests/typed_terms.cpp
tests/source_tracking.cpp
tests/error_recovery.cpp
tests/buffers.cpp
tests/contexts.cpp
tests/custom_lexer.cpp
)
target_link_libraries(testbin PRIVATE Catch2::Catch2 ctpg::ctpg)
if (CTPG_WARNING_FLAGS)
if (MSVC)
target_compile_options(testbin PRIVATE /W4 /WX )
else ()
target_compile_options(testbin PRIVATE -Wall -Wextra -pedantic -Werror)
endif ()
endif ()
if (MSVC)
target_compile_options(testbin PRIVATE /EHsc )
endif ()
include(Catch)
catch_discover_tests(testbin)
endif ()
# Install
if (NOT CTPG_ENABLE_INSTALL)
return()
endif ()
install(
TARGETS ctpg
EXPORT ctpg-targets
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
install(
EXPORT ctpg-targets
DESTINATION "${CTPG_INSTALL_CMAKEDIR}"
NAMESPACE ctpg::
FILE ctpg-targets.cmake
COMPONENT ctpg
)
install(
DIRECTORY "${PROJECT_SOURCE_DIR}/include/"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
COMPONENT ctpg
)
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/ctpg-config.cmake.in"
"${PROJECT_BINARY_DIR}/ctpg-config.cmake"
INSTALL_DESTINATION "${CTPG_INSTALL_CMAKEDIR}"
)
write_basic_package_version_file(
"ctpg-config-version.cmake"
COMPATIBILITY SameMajorVersion
ARCH_INDEPENDENT
)
install(
FILES "${PROJECT_BINARY_DIR}/ctpg-config.cmake"
"${PROJECT_BINARY_DIR}/ctpg-config-version.cmake"
DESTINATION "${CTPG_INSTALL_CMAKEDIR}"
COMPONENT ctpg
)