-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
144 lines (122 loc) · 5.7 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
project(protogen)
cmake_minimum_required(VERSION 3.18)
# This variables affect everything in the compiler and generated code
set(PROTOGEN_MAJOR 3)
set(PROTOGEN_MINOR 0)
set(PROTOGEN_PATCH 0)
configure_file("source/cmake.hh.in" "__include/cmake.hh")
if (UNIX)
set(ENABLE_SANITIZER OFF CACHE BOOL "")
if (ENABLE_SANITIZER)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fsanitize=address")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fsanitize=address")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wfatal-errors -pedantic -std=c++11 -Wl,--no-undefined -fPIC -Wall -Wextra -Wconversion -Wmaybe-uninitialized -Werror=return-type")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
endif()
if (MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS=1)
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DBUILD_DEBUG)
else()
set(CMAKE_BUILD_TYPE "Release")
add_definitions(-DBUILD_RELEASE)
endif()
message("Build type: ${CMAKE_BUILD_TYPE}")
add_library(libprotogen_static STATIC
"source/proto3.cc"
"source/printer.cc"
"source/exception.cc"
"source/cpp/cppgen.cc" )
target_include_directories(libprotogen_static
PUBLIC "include/"
PRIVATE "${CMAKE_BINARY_DIR}/__include/")
add_dependencies(libprotogen_static process_template)
set_target_properties(libprotogen_static PROPERTIES
OUTPUT_NAME "protogen_static"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
PREFIX "lib" )
add_executable(protogen
"source/main.cc")
target_include_directories(protogen
PRIVATE "${CMAKE_BINARY_DIR}/__include/")
target_link_libraries(protogen libprotogen_static)
set_target_properties(protogen PROPERTIES
OUTPUT_NAME "protogen"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" )
add_custom_command(
OUTPUT "${CMAKE_BINARY_DIR}/__include/auto-code.hh"
DEPENDS template "${CMAKE_CURRENT_LIST_DIR}/source/cpp/code.txt"
COMMAND "${CMAKE_BINARY_DIR}/template" "${CMAKE_CURRENT_LIST_DIR}/source/cpp/code.txt" "${CMAKE_BINARY_DIR}/__include/auto-code.hh"
)
add_custom_command(
OUTPUT "${CMAKE_BINARY_DIR}/__include/auto-protogen.hh"
DEPENDS template "${CMAKE_CURRENT_LIST_DIR}/source/cpp/protogen.hh"
COMMAND "${CMAKE_BINARY_DIR}/template" "${CMAKE_CURRENT_LIST_DIR}/source/cpp/protogen.hh" "${CMAKE_BINARY_DIR}/__include/auto-protogen.hh"
)
add_custom_command(
OUTPUT "${CMAKE_BINARY_DIR}/__include/auto-json.hh"
DEPENDS template "${CMAKE_CURRENT_LIST_DIR}/source/cpp/json.hh"
COMMAND "${CMAKE_BINARY_DIR}/template" "${CMAKE_CURRENT_LIST_DIR}/source/cpp/json.hh" "${CMAKE_BINARY_DIR}/__include/auto-json.hh"
)
add_custom_command(
OUTPUT "${CMAKE_BINARY_DIR}/__include/auto-json-array.hh"
DEPENDS template "${CMAKE_CURRENT_LIST_DIR}/source/cpp/json-array.hh"
COMMAND "${CMAKE_BINARY_DIR}/template" "${CMAKE_CURRENT_LIST_DIR}/source/cpp/json-array.hh" "${CMAKE_BINARY_DIR}/__include/auto-json-array.hh"
)
add_custom_command(
OUTPUT "${CMAKE_BINARY_DIR}/__include/auto-json-base64.hh"
DEPENDS template "${CMAKE_CURRENT_LIST_DIR}/source/cpp/json-base64.hh"
COMMAND "${CMAKE_BINARY_DIR}/template" "${CMAKE_CURRENT_LIST_DIR}/source/cpp/json-base64.hh" "${CMAKE_BINARY_DIR}/__include/auto-json-base64.hh"
)
add_custom_command(
OUTPUT "${CMAKE_BINARY_DIR}/__include/auto-json-number.hh"
DEPENDS template "${CMAKE_CURRENT_LIST_DIR}/source/cpp/json-number.hh"
COMMAND "${CMAKE_BINARY_DIR}/template" "${CMAKE_CURRENT_LIST_DIR}/source/cpp/json-number.hh" "${CMAKE_BINARY_DIR}/__include/auto-json-number.hh"
)
add_custom_command(
OUTPUT "${CMAKE_BINARY_DIR}/__include/auto-json-string.hh"
DEPENDS template "${CMAKE_CURRENT_LIST_DIR}/source/cpp/json-string.hh"
COMMAND "${CMAKE_BINARY_DIR}/template" "${CMAKE_CURRENT_LIST_DIR}/source/cpp/json-string.hh" "${CMAKE_BINARY_DIR}/__include/auto-json-string.hh"
)
add_custom_target(process_template
DEPENDS
"${CMAKE_BINARY_DIR}/__include/auto-code.hh"
"${CMAKE_BINARY_DIR}/__include/auto-protogen.hh"
"${CMAKE_BINARY_DIR}/__include/auto-json.hh"
"${CMAKE_BINARY_DIR}/__include/auto-json-array.hh"
"${CMAKE_BINARY_DIR}/__include/auto-json-base64.hh"
"${CMAKE_BINARY_DIR}/__include/auto-json-number.hh"
"${CMAKE_BINARY_DIR}/__include/auto-json-string.hh"
)
add_executable(template "source/template.cc")
target_include_directories(template
PRIVATE "${CMAKE_BINARY_DIR}/__include/")
set_target_properties(template PROPERTIES
OUTPUT_NAME "template"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" )
set(PROTOGEN_EXEC "${CMAKE_BINARY_DIR}/protogen")
add_custom_target(generate_test1
"${PROTOGEN_EXEC}" "${CMAKE_CURRENT_LIST_DIR}/tests/test1.proto" "${CMAKE_BINARY_DIR}/__include/test1.pg.hh"
DEPENDS protogen process_template)
add_custom_target(generate_test2
"${PROTOGEN_EXEC}" "${CMAKE_CURRENT_LIST_DIR}/tests/test2.proto" "${CMAKE_BINARY_DIR}/__include/test2.pg.hh"
DEPENDS protogen process_template)
add_custom_target(generate_test3
"${PROTOGEN_EXEC}" "${CMAKE_CURRENT_LIST_DIR}/tests/test3.proto" "${CMAKE_BINARY_DIR}/__include/test3.pg.hh"
DEPENDS protogen process_template)
add_custom_target(generate_test7
"${PROTOGEN_EXEC}" "${CMAKE_CURRENT_LIST_DIR}/tests/test7.proto" "${CMAKE_BINARY_DIR}/__include/test7.pg.hh"
DEPENDS protogen process_template)
add_executable(tests "tests/tests.cc")
target_include_directories(tests
PUBLIC "include/"
PRIVATE "${CMAKE_BINARY_DIR}/__include/")
add_dependencies(tests generate_test1 generate_test7 generate_test3)
set_target_properties(tests PROPERTIES
OUTPUT_NAME "run-tests"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" )
install(TARGETS protogen DESTINATION bin)