-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
212 lines (178 loc) · 7.56 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
cmake_minimum_required(VERSION 3.5)
# FIXME: This silences a warning but I'm not sure why its needed.
set(CMAKE_MACOSX_RPATH 1)
project(test_ffig)
if(MSVC)
add_compile_options("/EHsc")
else()
add_compile_options("-std=c++14")
endif()
if(NOT WIN32)
set(CMAKE_CXX_FLAGS_ASAN "-g -fno-omit-frame-pointer -O0 -fsanitize=address")
set(CMAKE_C_FLAGS_ASAN "-g -fno-omit-frame-pointer -O0 -fsanitize=address")
set(CMAKE_EXE_LINKER_FLAGS_ASAN "-fsanitize=address")
set(CMAKE_SHARED_LINKER_FLAGS_ASAN "-fsanitize=address")
endif()
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
include(ffig)
include_directories(externals/catch2/single_include)
include_directories(externals/variant/include)
# FIXME: Use FFIG to get this path.
include_directories(ffig/include)
# Check that the found version of Python==3 on Windows.
# Trust the user if they have supplied their own.
# FIXME: Get to the bottom of the libclang/ctypes issues with Python2.
if(NOT PYTHON_EXECUTABLE)
find_package(PythonInterp REQUIRED)
if(WIN32)
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import sys; assert sys.version_info[0] == 3" RESULT_VARIABLE result OUTPUT_QUIET ERROR_QUIET)
if(result)
message(FATAL_ERROR "CMake failed: Python 3 is required for Windows.")
endif()
endif()
else()
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import this" RESULT_VARIABLE result OUTPUT_QUIET ERROR_QUIET)
if(result)
message(FATAL_ERROR "CMake failed: ${PYTHON_EXECUTABLE} cannot execute a simple Python script.")
endif()
endif()
# Look for Go
# FIXME: Make this less hacky, ideally using a real CMake module
execute_process(COMMAND go version RESULT_VARIABLE result OUTPUT_QUIET ERROR_QUIET)
if(result)
set(Go_FOUND FALSE)
else()
set(Go_FOUND True)
endif()
# Look for Ruby
find_package(Ruby)
if(NOT Ruby_FOUND)
message(STATUS "Ruby tests disabled: Ruby interpreter not found.")
endif()
# Look for Lua
# FIXME: Make this less hacky.
execute_process(COMMAND luajit -e "print('testing')" RESULT_VARIABLE result OUTPUT_QUIET ERROR_QUIET)
if(result)
message(STATUS "Lua tests disabled: luajit cannot execute a simple Lua script.")
else()
set(LuaJIT_FOUND 1)
set(LuaJIT_EXECUTABLE "luajit")
endif()
# Look for C#
# FIXME: Make this less hacky, ideally using a real CMake module
execute_process(COMMAND dotnet --version RESULT_VARIABLE result OUTPUT_QUIET ERROR_QUIET)
if(result)
message(STATUS "Dotnet tests disabled: dotnet executable not found.")
else()
set(dotnet_FOUND 1)
configure_file(${CMAKE_CURRENT_LIST_DIR}/tests/dotnet/TestTree.cs.in ${CMAKE_CURRENT_BINARY_DIR}/generated/TestTree.cs)
configure_file(${CMAKE_CURRENT_LIST_DIR}/tests/dotnet/TestShape.cs.in ${CMAKE_CURRENT_BINARY_DIR}/generated/TestShape.cs)
configure_file(${CMAKE_CURRENT_LIST_DIR}/tests/dotnet/ffig.net.csproj.in ${CMAKE_CURRENT_BINARY_DIR}/generated/ffig.net.csproj)
endif()
set(all_ffig_bindings "PYTHON;CPP;CPP_MOCKS;DOTNET")
if(Ruby_FOUND)
list(APPEND all_ffig_bindings "RUBY")
endif()
if(Go_FOUND)
list(APPEND all_ffig_bindings "GO")
endif()
file(GLOB_RECURSE FFIG_SOURCE ${CMAKE_CURRENT_LIST_DIR}/ffig/*)
# Add FFIG build targets
ffig_add_library(NAME Shape INPUTS tests/input/Shape.h ${all_ffig_bindings})
ffig_add_library(NAME Tree INPUTS tests/input/Tree.h NOEXCEPT PYTHON CPP D SWIFT DOTNET)
ffig_add_library(NAME Asset INPUTS tests/input/Asset.h PYTHON LUA)
ffig_add_library(NAME Animal INPUTS tests/input/Animal.h PYTHON)
# build dotnet test dll
# FIXME: Work out how to get dependencies calculated more robustly
if(dotnet_FOUND)
file(GLOB TEST_INPUT ${CMAKE_CURRENT_LIST_DIR}/tests/input/*.h)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated/ffig.net.dll
COMMAND dotnet build ffig.net.csproj -o .
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/generated/Shape.cs;${CMAKE_CURRENT_BINARY_DIR}/generated/Tree.cs
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated
COMMENT "Building DOTNET assembly ffig.net.dll")
add_custom_target(ffig.net ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/generated/ffig.net.dll)
endif()
add_subdirectory(tests/src)
enable_testing()
add_test(
NAME test_cppmodel
COMMAND ${PYTHON_EXECUTABLE} -m nose -v ${CMAKE_CURRENT_LIST_DIR}/tests/cppmodel
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/ffig)
add_test(
NAME test_python_bindings
COMMAND ${PYTHON_EXECUTABLE} -m nose -v ${CMAKE_CURRENT_LIST_DIR}/tests
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated)
set_property(TEST test_python_bindings PROPERTY LABELS PYTHON)
add_test(
NAME test_cpp_mocks
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/tests/src/TestShapeMocks
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated)
set_property(TEST test_cpp_mocks PROPERTY LABELS MOCKS)
add_test(
NAME test_cpp_circle
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/tests/src/TestCppCircle
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated)
set_property(TEST test_cpp_circle PROPERTY LABELS CPP)
add_test(
NAME test_tree_capi
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/tests/src/TestTreeCAPI
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated)
set_property(TEST test_tree_capi PROPERTY LABELS C)
add_test(
NAME test_cpp_tree
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/tests/src/TestCppTree
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated)
set_property(TEST test_cpp_tree PROPERTY LABELS CPP)
add_test(
NAME test_d_tree_output
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/scripts/pydiff.py
${CMAKE_CURRENT_LIST_DIR}/tests/expected_output/Tree.d.expected
${CMAKE_CURRENT_BINARY_DIR}/generated/Tree.d)
set_property(TEST test_d_tree_output PROPERTY LABELS D TEXT)
add_test(
NAME test_dotnet_shape_output
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/scripts/pydiff.py
${CMAKE_CURRENT_LIST_DIR}/tests/expected_output/Shape.cs.expected
${CMAKE_CURRENT_BINARY_DIR}/generated/Shape.cs)
set_property(TEST test_dotnet_shape_output PROPERTY LABELS DOTNET TEXT)
add_test(
NAME test_dotnet_tree_output
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/scripts/pydiff.py
${CMAKE_CURRENT_LIST_DIR}/tests/expected_output/Tree.cs.expected
${CMAKE_CURRENT_BINARY_DIR}/generated/Tree.cs)
set_property(TEST test_dotnet_tree_output PROPERTY LABELS DOTNET TEXT)
add_test(
NAME test_swift_tree_output
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/scripts/pydiff.py
${CMAKE_CURRENT_LIST_DIR}/tests/expected_output/Tree.swift.expected
${CMAKE_CURRENT_BINARY_DIR}/generated/Tree.swift)
set_property(TEST test_swift_tree_output PROPERTY LABELS SWIFT TEXT)
if(dotnet_FOUND)
add_test(
NAME test_dotnet
COMMAND dotnet test --no-build --no-restore -o .
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated)
set_property(TEST test_dotnet PROPERTY LABELS DOTNET)
set_property(TEST test_dotnet PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/generated")
endif()
if(LuaJIT_FOUND)
# FIXME: The relative paths here (and in the lua test file) are very brittle.
add_test(
NAME test_asset_lua
COMMAND ${LuaJIT_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/tests/test_asset_bindings.lua
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated)
set_property(TEST test_asset_lua PROPERTY LABELS LUA)
set_property(TEST test_asset_lua PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/generated")
endif()
if(Ruby_FOUND)
add_test(
NAME test_ruby_bindings
COMMAND ${RUBY_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/tests/TestShape.rb ${CMAKE_CURRENT_LIST_DIR}/tests/TestShape.rb
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated)
set_property(TEST test_ruby_bindings PROPERTY LABELS RUBY)
endif()
if(Go_FOUND AND NOT WIN32)
add_subdirectory(tests/go)
endif()