-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
168 lines (137 loc) · 5.27 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
cmake_minimum_required(VERSION 3.26)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/modules)
set(INIT_SUBMODULE_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/external)
include(BuildEnv)
include(FetchContent)
file(READ ci/vcpkg-additional-ports/stencil/vcpkg.json VCPKG_MANIFEST_INFO)
string(JSON PROJECT_VERSION GET "${VCPKG_MANIFEST_INFO}" "version")
project(stencil VERSION "${PROJECT_VERSION}")
if (DEFINED Quick_DIR)
find_package(Quick)
QuickInit()
endif()
include(CMakePackageConfigHelpers)
option(BUILD_TESTING "Build Test" ON)
option(STENCIL_INSTALL_BUILDTOOLS "Install Extra Build Tools with install" OFF)
set(CMAKE_CXX_STANDARD 20)
EnableStrictCompilation()
find_package(Threads REQUIRED)
file(GLOB public_headers ${CMAKE_CURRENT_LIST_DIR}/include/stencil/*)
include(cmake/modules/cxxopts.cmake)
include(cmake/modules/date.cmake)
include(cmake/modules/EmbedResource.cmake)
include(cmake/modules/fmt.cmake)
include(cmake/modules/BoostBeast.cmake)
include(cmake/modules/LexYacc.cmake)
include(cmake/modules/RapidJSON.cmake)
include(cmake/modules/stduuid.cmake)
include(cmake/modules/tinyxml2.cmake)
include(cmake/modules/toml11.cmake)
include(cmake/CommonMacros.cmake)
list(APPEND public_headers "${COMMONMACROS_INCLUDE_FILE}")
if (BUILD_TESTING)
enable_testing()
include(cmake/modules/Catch2.cmake)
endif()
file(GLOB resfiles src/templates/*)
add_library(libstencil OBJECT
src/ModelGenerator.cpp
src/Binding.h
src/DebugInfo.h
src/GeneratedCodeFragment.h
src/Generator.h
src/IDL2.h
src/IDL3Generics.h
src/TemplateFragment.h
src/Thrift.h
src/tree.h
)
target_include_directories(libstencil PUBLIC src include)
add_lexyacc_library(TARGET Thrift LYFILE src/Thrift.ly SOURCES src/Thrift.cpp)
target_include_directories(Thrift PUBLIC src include)
target_link_libraries(Thrift PUBLIC CommonMacros fmt::fmt-header-only)
if (MSVC)
# TOML11 has a nasty usage of insecure apis
set_source_files_properties("src/ModelGenerator.cpp" PROPERTIES COMPILE_FLAGS "/D_CRT_SECURE_NO_WARNINGS")
endif()
target_link_libraries(libstencil PUBLIC Thrift)
target_add_resource(libstencil RESOURCE_COLLECTION_NAME templates RESOURCES ${resfiles})
list(APPEND resfiles ${public_headers})
if (NOT BUILD_TESTING)
target_add_resource(libstencil RESOURCE_COLLECTION_NAME commonheaders RESOURCES ${resfiles})
endif()
target_link_libraries(libstencil PUBLIC
toml11::toml11
tinyxml2::tinyxml2
fmt::fmt-header-only
CommonMacros
)
set(stencil_INCLUDE_PATH "${CMAKE_CURRENT_LIST_DIR}/include" CACHE PATH "Stencil include path")
# For add_subdirectory mode
include(stencilTargets)
target_link_libraries(stencil_runtime INTERFACE CommonMacros)
add_executable(stencil src/main.cpp)
set_target_properties(stencil PROPERTIES PUBLIC_HEADER "${public_headers}")
target_link_libraries(stencil PRIVATE libstencil Thrift cxxopts::cxxopts)
if (BUILD_TESTING)
add_subdirectory(tests/CodegenRuntime)
endif()
if (BUILD_TESTING)
enable_testing()
include(cmake/TestCommon.cmake)
file(GLOB resfiles CONFIGURE_DEPENDS tests/testdata/*)
file(GLOB pidlfiles tests/*.pidl)
add_executable(codegen_tests
tests/Codegen/Test_ThriftGenerator.cpp
)
add_test(NAME codegen_tests COMMAND codegen_tests)
target_include_directories(codegen_tests PRIVATE src include tests)
target_link_libraries(codegen_tests PRIVATE libstencil Thrift TestCommon)
target_add_resource(codegen_tests RESOURCE_COLLECTION_NAME testdata RESOURCES ${resfiles} ${pidlfiles})
target_compile_definitions(codegen_tests PRIVATE HAVE_EMBEDRESOURCE=1)
add_executable(runtime_tests
tests/HandwrittenRuntime/Test_Handwritten_CLOpts.cpp
tests/HandwrittenRuntime/Test_Handwritten_Json.cpp
tests/HandwrittenRuntime/Test_Handwritten_Binary.cpp
)
target_compile_definitions(runtime_tests PRIVATE HAVE_NLOHMANN_JSON)
target_link_libraries(runtime_tests PRIVATE stencil_runtime)
target_link_libraries(runtime_tests PRIVATE TestCommon httplib::httplib stencil::runtime)
target_link_libraries (runtime_tests PRIVATE Threads::Threads)
add_test(NAME runtime_tests COMMAND runtime_tests)
target_add_resource(runtime_tests RESOURCE_COLLECTION_NAME testdata RESOURCES ${resfiles})
target_compile_definitions(runtime_tests PRIVATE HAVE_EMBEDRESOURCE=1)
target_include_directories(runtime_tests PRIVATE src include tests)
endif()
configure_package_config_file(cmake/stencilConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/stencilConfig.cmake
INSTALL_DESTINATION share/stencil
)
install(
TARGETS stencil
EXPORT stencilTargets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include/stencil
)
install(FILES
cmake/stencilTargets.cmake
cmake/FindOrBuildTool.cmake
${CMAKE_CURRENT_BINARY_DIR}/stencilConfig.cmake
DESTINATION share/stencil
)
#install(EXPORT stencilTargets
# NAMESPACE stencil::
# DESTINATION share/stencil
#)
#
# CPACK
#
set (CPACK_GENERATOR ZIP)
set (CPACK_PACKAGE_NAME ${PROJECT_NAME})
set (CPACK_PACKAGE_VENDOR "Ankur Verma")
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Stencil Build Tools")
set (CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
include(CPack)