-
Notifications
You must be signed in to change notification settings - Fork 323
/
Bond.cmake
157 lines (152 loc) · 4.84 KB
/
Bond.cmake
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
include (CMakeParseArguments)
include (Folders)
#
# add_bond_codegen (file.bond [file2.bond ...]
# [ENUM_HEADER]
# [OUTPUT_DIR dir]
# [IMPORT_DIR dir [dir2, ...]]
# [OPTIONS opt [opt2 ...]])
# [TARGET name]
#
function (add_bond_codegen)
set (flagArgs ENUM_HEADER)
set (oneValueArgs OUTPUT_DIR TARGET)
set (multiValueArgs IMPORT_DIR OPTIONS)
cmake_parse_arguments (arg "${flagArgs}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set (options)
set (outputDir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
if (arg_OUTPUT_DIR)
set (outputDir ${arg_OUTPUT_DIR})
endif()
list (APPEND options --output-dir="${outputDir}")
list (APPEND options --import-dir="${BOND_IDL}")
foreach (dir ${arg_IMPORT_DIR})
list(APPEND options --import-dir="${dir}")
endforeach()
foreach (opt ${arg_OPTIONS})
list (APPEND options "${opt}")
endforeach()
if (arg_ENUM_HEADER)
list(APPEND options --enum-header)
endif()
set (inputs "${arg_UNPARSED_ARGUMENTS}")
set (outputs)
foreach (file ${inputs})
get_filename_component (name ${file} NAME_WE)
list (APPEND outputs
"${outputDir}/${name}_reflection.h"
"${outputDir}/${name}_types.h"
"${outputDir}/${name}_types.cpp"
"${outputDir}/${name}_apply.h"
"${outputDir}/${name}_apply.cpp"
)
if (arg_ENUM_HEADER)
list(APPEND outputs "${outputDir}/${name}_enum.h")
endif()
endforeach()
# if BOND_GBC_PATH is not set we must add a dependency on the "gbc" target to build it
if (NOT BOND_GBC_PATH)
set(gbc "gbc")
elseif()
set(gbc "")
endif()
add_custom_command(
OUTPUT ${outputs}
COMMAND ${GBC_EXECUTABLE} c++ ${options} ${inputs}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${inputs} ${gbc} ${GBC_EXECUTABLE})
if (arg_TARGET)
add_custom_target (${arg_TARGET}
DEPENDS ${outputs}
SOURCES ${inputs})
add_target_to_folder(${arg_TARGET})
endif()
endfunction()
#
# add_bond_executable (name
# [schem.bond [schema2.bond]]
# source.cpp [source2.cpp])
#
function (add_bond_executable target)
set (schemas)
set (sources)
cmake_parse_arguments (arg "" "" "" ${ARGN})
foreach (file ${ARGV})
get_filename_component (ext ${file} EXT)
if (ext STREQUAL ".bond")
get_filename_component (name ${file} NAME_WE)
list (APPEND schemas "${file}")
list (APPEND sources "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${name}_types.cpp")
endif()
endforeach()
if (schemas)
set (options)
add_bond_codegen (${schemas} ${options})
endif()
add_executable (${ARGV} ${sources})
add_target_to_folder(${target})
target_link_libraries (${target} PRIVATE
bond
bond_apply)
target_include_directories (${target} PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}
${CMAKE_CURRENT_SOURCE_DIR})
endfunction()
#
# add_bond_test (name
# [schem.bond [schema2.bond]]
# source.cpp [source2.cpp]
# [BUILD_ONLY])
#
function (add_bond_test test)
set (flagArgs BUILD_ONLY)
cmake_parse_arguments (arg "${flagArgs}" "" "" ${ARGN})
list (REMOVE_ITEM ARGV BUILD_ONLY)
list (INSERT ARGV 1 EXCLUDE_FROM_ALL)
add_bond_executable (${ARGV})
add_dependencies (check ${test})
if (NOT arg_BUILD_ONLY)
add_test (
NAME ${test}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${test})
endif()
endfunction()
#
# add_bond_python_module (name
# [schem.bond [schema2.bond]]
# source.cpp [source2.cpp])
#
function (add_bond_python_module target)
set (schemas)
set (sources)
foreach (file ${ARGV})
get_filename_component (ext ${file} EXT)
if (ext STREQUAL ".bond")
get_filename_component (name ${file} NAME_WE)
list (APPEND schemas "${file}")
list (APPEND sources "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${name}_types.cpp")
endif()
endforeach()
if (schemas)
add_bond_codegen (${schemas})
endif()
list (INSERT ARGV 1 EXCLUDE_FROM_ALL)
python_add_module (${ARGV} ${sources})
add_dependencies (check ${target})
add_target_to_folder(${target})
target_link_libraries (${target} PRIVATE
bond
bond_apply
${PYTHON_LIBRARIES}
${Boost_PYTHON_LIBRARY})
target_include_directories (${target} PRIVATE
${BOND_PYTHON_INCLUDE}
${WINDOWSSDK_PREFERRED_DIR}/Include
${WINDOWSSDK_PREFERRED_DIR}/Include/shared
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}
${CMAKE_CURRENT_SOURCE_DIR}
${PYTHON_INCLUDE_DIR})
target_compile_definitions (${target} PRIVATE
-DBOOST_PYTHON_STATIC_LIB)
endfunction()