Skip to content

Commit

Permalink
Added an option to generate the C#, Ruby, and Python glue code alongs…
Browse files Browse the repository at this point in the history
…ide the CMake build
  • Loading branch information
shartte committed Aug 13, 2021
1 parent 97d6cb3 commit 62a1eb3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
4 changes: 4 additions & 0 deletions contrib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ IF (SOLOUD_BUILD_DEMOS)
include (demos.cmake)
endif ()

IF (SOLOUD_GENERATE_GLUE)
include (gen_glue.cmake)
endif ()

include (InstallExport)
3 changes: 3 additions & 0 deletions contrib/Configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ print_option_status (SOLOUD_BACKEND_WINMM "WINMM backend")

option (SOLOUD_BACKEND_WASAPI "Set to ON for building WASAPI backend" OFF)
print_option_status (SOLOUD_BACKEND_WASAPI "WASAPI backend")

option (SOLOUD_GENERATE_GLUE "Set to ON for generating the Glue APIs" OFF)
print_option_status (SOLOUD_GENERATE_GLUE "Generate Glue")
44 changes: 44 additions & 0 deletions contrib/gen_glue.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

# We need python to run the glue-code generators
find_package (Python3 COMPONENTS Interpreter REQUIRED)

# Create the executable that generates soloud_codegen.py
add_executable (codegen ../src/tools/codegen/main.cpp)

# Add a command to run the executable to generate the python file
add_custom_command (OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/../scripts/soloud_codegen.py"
COMMAND codegen ARGS go
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

# Now we can run the actual Python code-generators, BUT we need to add a dependency on
# soloud_codegen.py, or otherwise codegen.exe will not be run beforehand

###############################################################################
# C# API
###############################################################################
add_custom_command (OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/../glue/soloud.cs"
COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../scripts/gen_cs.py"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../scripts/soloud_codegen.py"
)
add_custom_target (generate_glue_cs ALL DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../glue/soloud.cs")
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/../glue/soloud.cs" DESTINATION glue)

###############################################################################
# Python API
###############################################################################
add_custom_command (OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/../glue/soloud.rb"
COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../scripts/gen_ruby.py"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../scripts/soloud_codegen.py"
)
add_custom_target (generate_glue_ruby ALL DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../glue/soloud.rb")
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/../glue/soloud.rb" DESTINATION glue)

###############################################################################
# Ruby API
###############################################################################
add_custom_command (OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/../glue/soloud.py"
COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../scripts/gen_python.py"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../scripts/soloud_codegen.py"
)
add_custom_target(generate_glue_python ALL DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../glue/soloud.py")
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/../glue/soloud.py" DESTINATION glue)

0 comments on commit 62a1eb3

Please sign in to comment.