diff Resources/CMake/ProtobufCodeGeneration.cmake @ 466:5055031f4a06 bgo-commands-codegen

- Added browserify to build. This allows using require calls for modules that work with tsc compiler. - removed older stuff related to Protocol Buffers and Flatbuffers - changed triple-slash references to import statements - module prefixes are now added at call sites - added cmake module for filename handling - switched to Ninja for sample build - Added virtual dtor in ICommand
author bgo-osimis
date Mon, 11 Feb 2019 16:00:04 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/CMake/ProtobufCodeGeneration.cmake	Mon Feb 11 16:00:04 2019 +0100
@@ -0,0 +1,77 @@
+# HOW TO USE:
+# the GenerateCodeFromProtobufSchema will generate files in ${CMAKE_BINARY_DIR} and will
+# populate PROTOBUF_AUTOGENERATED_SOURCES with the list of generated files
+# AS OF 2019-01-30, it requires protoc (version 3.6.1.x) to be available in the path
+set(PROTOBUF_AUTOGENERATED_SOURCES)
+
+# TODO: use find_program (<VAR> name1 [path1 path2 ...]) to located the protobuf compiler
+# TODO: automated the TS plugin installation
+
+macro(GenerateCodeFromProtobufSchema schemaFilePath outputBaseDirectory)
+  # extract file name
+  GetFilePathWithoutLastExtension(schemaFilePathWithoutExt ${schemaFilePath})
+  
+  # remove extension
+  GetFilenameFromPath(schemaFileNameWithoutExt ${schemaFilePathWithoutExt})
+  
+  set(generatedFilePathWithoutExtension "${CMAKE_BINARY_DIR}/AUTOGENERATED/${schemaFileNameWithoutExt}")
+  set(generatedCppSourceFilePath "${generatedFilePathWithoutExtension}.pb.cc")
+  set(generatedCppHeaderFilePath "${generatedFilePathWithoutExtension}.pb.h")
+  set(generatedJsFilePath "${generatedFilePathWithoutExtension}_pb.js")
+  set(generatedTsFilePath "${generatedFilePathWithoutExtension}_pb.d.ts")
+  # set(generatedJsFileName "${generatedFilePathWithoutExtension}.js")
+
+  # set(AUTOGENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/AUTOGENERATED")
+  # set(AUTOGENERATED_SOURCES)
+  
+  set(PROTOC_EXECUTABLE "PROTOC")
+  find_program(PROTOC_EXECUTABLE_SEARCH ${FLATC_EXECUTABLE})
+  if(NOT PROTOC_EXECUTABLE_SEARCH)
+    message(FATAL_ERROR "The Protocol Buffers compiler (protoc[.exe]) cannot be found!")
+  endif()
+
+  # TODO CUSTOMIZE FOR TYPESCRIPT
+  set(SCRIPT_CPP_OPTIONS)
+  list(APPEND SCRIPT_CPP_OPTIONS "----cpp_out=${CMAKE_BINARY_DIR}/AUTOGENERATED")
+  # list(APPEND SCRIPT_CPP_OPTIONS "gnagna")
+  
+  set(SCRIPT_TS_OPTIONS)
+
+  list(APPEND SCRIPT_TS_OPTIONS "--ts")
+  list(APPEND SCRIPT_TS_OPTIONS "gnagna")
+
+  add_custom_command(
+    OUTPUT
+    ${generatedCppSourceFilePath}
+    ${generatedCppHeaderFilePath}
+    COMMAND 
+    ${PROTOC_EXECUTABLE} ${SCRIPT_CPP_OPTIONS} ${schemaFilePath}
+    DEPENDS
+    ${schemaFilePath}
+    )
+  
+  add_custom_command(
+    OUTPUT
+    ${generatedTsFileName}
+    ${generatedJsFilePath}
+    COMMAND 
+    ${PROTOC_EXECUTABLE} ${SCRIPT_TS_OPTIONS} ${schemaFilePath}
+    DEPENDS
+    ${schemaFilePath}
+    )
+  
+  # add_custom_command(
+  #   OUTPUT
+  #   ${generatedJsFileName}
+  #   COMMAND 
+  #   ${FLATC_EXECUTABLE} ${SCRIPT_JS_OPTIONS} ${schemaFilePath}
+  #   DEPENDS
+  #   ${schemaFilePath}
+  #   )
+
+    list(APPEND FLATC_AUTOGENERATED_SOURCES "${generatedCppFileName}") 
+    # list(APPEND FLATC_AUTOGENERATED_SOURCES "${generatedJsFileName}") 
+    list(APPEND FLATC_AUTOGENERATED_SOURCES "${generatedTsFileName}") 
+
+endmacro()
+