Mercurial > hg > orthanc-stone
comparison Resources/CMake/ProtobufCodeGeneration.cmake @ 504:7cdb4634846c
Merge
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 26 Feb 2019 21:15:20 +0100 |
parents | 5055031f4a06 |
children |
comparison
equal
deleted
inserted
replaced
460:4d8ac609fc33 | 504:7cdb4634846c |
---|---|
1 # HOW TO USE: | |
2 # the GenerateCodeFromProtobufSchema will generate files in ${CMAKE_BINARY_DIR} and will | |
3 # populate PROTOBUF_AUTOGENERATED_SOURCES with the list of generated files | |
4 # AS OF 2019-01-30, it requires protoc (version 3.6.1.x) to be available in the path | |
5 set(PROTOBUF_AUTOGENERATED_SOURCES) | |
6 | |
7 # TODO: use find_program (<VAR> name1 [path1 path2 ...]) to located the protobuf compiler | |
8 # TODO: automated the TS plugin installation | |
9 | |
10 macro(GenerateCodeFromProtobufSchema schemaFilePath outputBaseDirectory) | |
11 # extract file name | |
12 GetFilePathWithoutLastExtension(schemaFilePathWithoutExt ${schemaFilePath}) | |
13 | |
14 # remove extension | |
15 GetFilenameFromPath(schemaFileNameWithoutExt ${schemaFilePathWithoutExt}) | |
16 | |
17 set(generatedFilePathWithoutExtension "${CMAKE_BINARY_DIR}/AUTOGENERATED/${schemaFileNameWithoutExt}") | |
18 set(generatedCppSourceFilePath "${generatedFilePathWithoutExtension}.pb.cc") | |
19 set(generatedCppHeaderFilePath "${generatedFilePathWithoutExtension}.pb.h") | |
20 set(generatedJsFilePath "${generatedFilePathWithoutExtension}_pb.js") | |
21 set(generatedTsFilePath "${generatedFilePathWithoutExtension}_pb.d.ts") | |
22 # set(generatedJsFileName "${generatedFilePathWithoutExtension}.js") | |
23 | |
24 # set(AUTOGENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/AUTOGENERATED") | |
25 # set(AUTOGENERATED_SOURCES) | |
26 | |
27 set(PROTOC_EXECUTABLE "PROTOC") | |
28 find_program(PROTOC_EXECUTABLE_SEARCH ${FLATC_EXECUTABLE}) | |
29 if(NOT PROTOC_EXECUTABLE_SEARCH) | |
30 message(FATAL_ERROR "The Protocol Buffers compiler (protoc[.exe]) cannot be found!") | |
31 endif() | |
32 | |
33 # TODO CUSTOMIZE FOR TYPESCRIPT | |
34 set(SCRIPT_CPP_OPTIONS) | |
35 list(APPEND SCRIPT_CPP_OPTIONS "----cpp_out=${CMAKE_BINARY_DIR}/AUTOGENERATED") | |
36 # list(APPEND SCRIPT_CPP_OPTIONS "gnagna") | |
37 | |
38 set(SCRIPT_TS_OPTIONS) | |
39 | |
40 list(APPEND SCRIPT_TS_OPTIONS "--ts") | |
41 list(APPEND SCRIPT_TS_OPTIONS "gnagna") | |
42 | |
43 add_custom_command( | |
44 OUTPUT | |
45 ${generatedCppSourceFilePath} | |
46 ${generatedCppHeaderFilePath} | |
47 COMMAND | |
48 ${PROTOC_EXECUTABLE} ${SCRIPT_CPP_OPTIONS} ${schemaFilePath} | |
49 DEPENDS | |
50 ${schemaFilePath} | |
51 ) | |
52 | |
53 add_custom_command( | |
54 OUTPUT | |
55 ${generatedTsFileName} | |
56 ${generatedJsFilePath} | |
57 COMMAND | |
58 ${PROTOC_EXECUTABLE} ${SCRIPT_TS_OPTIONS} ${schemaFilePath} | |
59 DEPENDS | |
60 ${schemaFilePath} | |
61 ) | |
62 | |
63 # add_custom_command( | |
64 # OUTPUT | |
65 # ${generatedJsFileName} | |
66 # COMMAND | |
67 # ${FLATC_EXECUTABLE} ${SCRIPT_JS_OPTIONS} ${schemaFilePath} | |
68 # DEPENDS | |
69 # ${schemaFilePath} | |
70 # ) | |
71 | |
72 list(APPEND FLATC_AUTOGENERATED_SOURCES "${generatedCppFileName}") | |
73 # list(APPEND FLATC_AUTOGENERATED_SOURCES "${generatedJsFileName}") | |
74 list(APPEND FLATC_AUTOGENERATED_SOURCES "${generatedTsFileName}") | |
75 | |
76 endmacro() | |
77 |