445
|
1 # Stone of Orthanc
|
|
2 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
|
|
3 # Department, University Hospital of Liege, Belgium
|
|
4 # Copyright (C) 2017-2019 Osimis S.A., Belgium
|
|
5 #
|
|
6 # This program is free software: you can redistribute it and/or
|
|
7 # modify it under the terms of the GNU Affero General Public License
|
|
8 # as published by the Free Software Foundation, either version 3 of
|
|
9 # the License, or (at your option) any later version.
|
|
10 #
|
|
11 # This program is distributed in the hope that it will be useful, but
|
|
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
14 # Affero General Public License for more details.
|
|
15 #
|
|
16 # You should have received a copy of the GNU Affero General Public License
|
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
18 include(${ORTHANC_ROOT}/Resources/CMake/DownloadPackage.cmake)
|
|
19 set(FLATC_AUTOGENERATED_SOURCES)
|
|
20
|
|
21 if (STATIC_BUILD OR NOT USE_SYSTEM_FLATBUFFERS)
|
|
22 SET(FLATBUFFERS_SOURCES_DIR ${CMAKE_BINARY_DIR}/flatbuffers-1.10)
|
|
23 SET(FLATBUFFERS_URL "http://127.0.0.1:8000/flatbuffers-1.10.tar.gz")
|
|
24 SET(FLATBUFFERS_MD5 "d5f131809c14def9682d49385b452e43")
|
|
25
|
|
26 DownloadPackage(${FLATBUFFERS_MD5} ${FLATBUFFERS_URL} "${FLATBUFFERS_SOURCES_DIR}")
|
|
27
|
|
28 include_directories(${FLATBUFFERS_SOURCES_DIR}/include)
|
|
29
|
|
30 # we only need the flatc compiler!
|
|
31 set(FLATBUFFERS_BUILD_TESTS OFF)
|
|
32 set(FLATBUFFERS_INSTALL OFF)
|
|
33 set(FLATBUFFERS_BUILD_FLATLIB OFF)
|
|
34 set(FLATBUFFERS_BUILD_FLATC ON)
|
|
35 set(FLATBUFFERS_BUILD_FLATHASH OFF)
|
|
36 set(FLATBUFFERS_BUILD_GRPCTEST OFF)
|
|
37 set(FLATBUFFERS_BUILD_SHAREDLIB OFF)
|
|
38 set(FLATBUFFERS_LIBCXX_WITH_CLANG OFF)
|
|
39
|
|
40 # add_subdirectory(${FLATBUFFERS_SOURCES_DIR}
|
|
41 # ${CMAKE_CURRENT_BINARY_DIR}/flatbuffers-build
|
|
42 # EXCLUDE_FROM_ALL)
|
|
43
|
|
44 # Now simply link against flatbuffers as needed to your already declared target.
|
|
45 # The flatbuffers target carry header search path automatically if CMake > 2.8.11.
|
|
46 #target_link_libraries(own_project_target PRIVATE flatbuffers)
|
|
47
|
|
48 else()
|
|
49 find_package(FlatBuffers)
|
|
50 include_directories(${SDL2_INCLUDE_DIRS})
|
|
51 link_libraries(${SDL2_LIBRARIES})
|
|
52 endif()
|
|
53
|
|
54 macro(GetFilenameFromPath TargetVariable Path)
|
|
55 #message(STATUS "GetFilenameFromPath (1): Path = ${Path} TargetVariable = ${${TargetVariable}}")
|
|
56 string(REPLACE "\\" "/" PathWithFwdSlashes "${Path}")
|
|
57 string(REGEX REPLACE "^.*/" "" ${TargetVariable} "${PathWithFwdSlashes}")
|
|
58 #message(STATUS "GetFilenameFromPath (2): Path = ${Path} Path = ${PathWithFwdSlashes} TargetVariable = ${TargetVariable}")
|
|
59 endmacro()
|
|
60
|
|
61 macro(GetFilePathWithoutLastExtension TargetVariable FilePath)
|
|
62 string(REGEX REPLACE "(^.*)\\.([^\\.]+)" "\\1" ${TargetVariable} "${FilePath}")
|
|
63 #message(STATUS "GetFileNameWithoutLastExtension: FilePath = ${FilePath} TargetVariable = ${${TargetVariable}}")
|
|
64 endmacro()
|
|
65
|
|
66 macro(Test_GetFilePathWithoutLastExtension)
|
|
67 set(tmp "/prout/zi/goui.goui.cpp")
|
|
68 GetFilePathWithoutLastExtension(TargetVariable "${tmp}")
|
|
69 if(NOT ("${TargetVariable}" STREQUAL "/prout/zi/goui.goui"))
|
|
70 message(FATAL_ERROR "Test_GetFilePathWithoutLastExtension failed (1)")
|
|
71 else()
|
|
72 #message(STATUS "Test_GetFilePathWithoutLastExtension: <<OK>>")
|
|
73 endif()
|
|
74 endmacro()
|
|
75
|
|
76 Test_GetFilePathWithoutLastExtension()
|
|
77
|
|
78 macro(Test_GetFilenameFromPath)
|
|
79 set(tmp "/prout/../../dada/zi/goui.goui.cpp")
|
|
80 GetFilenameFromPath(TargetVariable "${tmp}")
|
|
81 if(NOT ("${TargetVariable}" STREQUAL "goui.goui.cpp"))
|
|
82 message(FATAL_ERROR "Test_GetFilenameFromPath failed")
|
|
83 else()
|
|
84 #message(STATUS "Test_GetFilenameFromPath: <<OK>>")
|
|
85 endif()
|
|
86 endmacro()
|
|
87
|
|
88 Test_GetFilenameFromPath()
|
|
89
|
|
90 macro(GenerateCodeFromFlatBufferSchema schemaFilePath)
|
|
91 # extract file name
|
|
92 GetFilePathWithoutLastExtension(schemaFilePathWithoutExt ${schemaFilePath})
|
|
93
|
|
94 # remove extension
|
|
95 GetFilenameFromPath(schemaFileNameWithoutExt ${schemaFilePathWithoutExt})
|
|
96
|
|
97 set(generatedFilePathWithoutExtension "${CMAKE_BINARY_DIR}/${schemaFileNameWithoutExt}_generated")
|
|
98 set(generatedCppFileName "${generatedFilePathWithoutExtension}.h")
|
|
99 set(generatedTsFileName "${generatedFilePathWithoutExtension}.ts")
|
|
100 set(generatedJsFileName "${generatedFilePathWithoutExtension}.js")
|
|
101
|
|
102 set(AUTOGENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/AUTOGENERATED")
|
|
103 set(AUTOGENERATED_SOURCES)
|
|
104
|
|
105 set(FLATC_EXECUTABLE "flatc")
|
|
106 find_program(FLATC_EXECUTABLE_SEARCH ${FLATC_EXECUTABLE})
|
|
107 if(NOT FLATC_EXECUTABLE_SEARCH)
|
|
108 message(FATAL_ERROR "FlatBuffers compiler not found")
|
|
109 endif()
|
|
110
|
|
111 set(SCRIPT_CPP_OPTIONS)
|
|
112 list(APPEND SCRIPT_CPP_OPTIONS "--gen-object-api")
|
|
113 list(APPEND SCRIPT_CPP_OPTIONS "--cpp")
|
|
114 list(APPEND SCRIPT_CPP_OPTIONS "--gen-onefile")
|
|
115 list(APPEND SCRIPT_CPP_OPTIONS "--gen-all")
|
|
116 list(APPEND SCRIPT_CPP_OPTIONS "--force-empty")
|
|
117 list(APPEND SCRIPT_CPP_OPTIONS "--reflect-types")
|
|
118 list(APPEND SCRIPT_CPP_OPTIONS "--reflect-names")
|
|
119
|
|
120 set(SCRIPT_TS_OPTIONS)
|
|
121 list(APPEND SCRIPT_TS_OPTIONS "--gen-object-api")
|
|
122 list(APPEND SCRIPT_TS_OPTIONS "--ts")
|
|
123 list(APPEND SCRIPT_TS_OPTIONS "--gen-onefile")
|
|
124 list(APPEND SCRIPT_TS_OPTIONS "--gen-all")
|
|
125 list(APPEND SCRIPT_TS_OPTIONS "--no-js-exports")
|
|
126 list(APPEND SCRIPT_TS_OPTIONS "--force-empty")
|
|
127 list(APPEND SCRIPT_TS_OPTIONS "--reflect-types")
|
|
128 list(APPEND SCRIPT_TS_OPTIONS "--reflect-names")
|
|
129
|
|
130 set(SCRIPT_JS_OPTIONS)
|
|
131 list(APPEND SCRIPT_JS_OPTIONS "--gen-object-api")
|
|
132 list(APPEND SCRIPT_JS_OPTIONS "--js")
|
|
133 list(APPEND SCRIPT_JS_OPTIONS "--gen-onefile")
|
|
134 list(APPEND SCRIPT_JS_OPTIONS "--gen-all")
|
|
135 list(APPEND SCRIPT_JS_OPTIONS "--no-js-exports")
|
|
136 list(APPEND SCRIPT_JS_OPTIONS "--force-empty")
|
|
137 list(APPEND SCRIPT_JS_OPTIONS "--reflect-types")
|
|
138 list(APPEND SCRIPT_JS_OPTIONS "--reflect-names")
|
|
139
|
|
140 add_custom_command(
|
|
141 OUTPUT
|
|
142 ${generatedCppFileName}
|
|
143 COMMAND
|
|
144 ${FLATC_EXECUTABLE} ${SCRIPT_CPP_OPTIONS} ${schemaFilePath}
|
|
145 DEPENDS
|
|
146 ${schemaFilePath}
|
|
147 )
|
|
148
|
|
149 add_custom_command(
|
|
150 OUTPUT
|
|
151 ${generatedTsFileName}
|
|
152 COMMAND
|
|
153 ${FLATC_EXECUTABLE} ${SCRIPT_TS_OPTIONS} ${schemaFilePath}
|
|
154 DEPENDS
|
|
155 ${schemaFilePath}
|
|
156 )
|
|
157
|
|
158 add_custom_command(
|
|
159 OUTPUT
|
|
160 ${generatedJsFileName}
|
|
161 COMMAND
|
|
162 ${FLATC_EXECUTABLE} ${SCRIPT_JS_OPTIONS} ${schemaFilePath}
|
|
163 DEPENDS
|
|
164 ${schemaFilePath}
|
|
165 )
|
|
166
|
|
167 list(APPEND FLATC_AUTOGENERATED_SOURCES "${generatedCppFileName}")
|
|
168 list(APPEND FLATC_AUTOGENERATED_SOURCES "${generatedJsFileName}")
|
|
169 list(APPEND FLATC_AUTOGENERATED_SOURCES "${generatedTsFileName}")
|
|
170
|
|
171 endmacro()
|