From c8dcc07d7d710b9109bde009ccb0b82306e2d284 Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Wed, 25 Oct 2023 21:53:55 -0700 Subject: [PATCH] Update CMakeLists to autogen yunq files. --- CMakeLists.txt | 35 ++++++++++++++++++++++++++++++++++ sys/denali/CMakeLists.txt | 18 +---------------- sys/yellowstone/CMakeLists.txt | 18 +---------------- yunq/yunq.py | 11 ++++++----- 4 files changed, 43 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c1bd27..0c384ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,41 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS True) set(BASE_COMPILE_FLAGS "-ffreestanding -fno-rtti -fno-exceptions -mgeneral-regs-only") set(BASE_LINK_FLAGS "-nostdlib") +set(PYTHON "${CMAKE_SOURCE_DIR}/yunq/venv/bin/python") +set(YUNQ "${CMAKE_SOURCE_DIR}/yunq/yunq.py") + +macro(yunq_gen dir include_dir name) + set(file_bundle ${name}_yunq_files) + set(target ${name}_yunq) + set(${file_bundle} + ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${name}.yunq.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${name}.yunq.client.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${name}.yunq.server.cpp + ) + + add_library(${target} + ${${file_bundle}} + ) + + target_include_directories(${target} + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/${include_dir}" + ) + + target_link_libraries(${target} + mammoth + ) + set_target_properties(${target} PROPERTIES + COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}" + LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} ${BASE_LINK_FLAGS}" + ) + + add_custom_command( + OUTPUT ${${file_bundle}} + COMMAND ${PYTHON} ${YUNQ} ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/${name}.yunq + DEPENDS ${dir}/${name}.yunq + ) +endmacro() + add_subdirectory(zion) add_subdirectory(lib) add_subdirectory(sys) diff --git a/sys/denali/CMakeLists.txt b/sys/denali/CMakeLists.txt index 24602d1..eab0515 100644 --- a/sys/denali/CMakeLists.txt +++ b/sys/denali/CMakeLists.txt @@ -22,20 +22,4 @@ set_target_properties(denali PROPERTIES LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} ${BASE_LINK_FLAGS}" ) -add_library(denali_yunq - lib/denali/denali.yunq.client.cpp - lib/denali/denali.yunq.server.cpp - lib/denali/denali.yunq.cpp - ) - -target_include_directories(denali_yunq - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/lib") - - target_link_libraries(denali_yunq - mammoth) - -set_target_properties(denali_yunq PROPERTIES - COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}" - LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} ${BASE_LINK_FLAGS}" - ) +yunq_gen(lib/denali lib denali) diff --git a/sys/yellowstone/CMakeLists.txt b/sys/yellowstone/CMakeLists.txt index 84124d6..1fa51b9 100644 --- a/sys/yellowstone/CMakeLists.txt +++ b/sys/yellowstone/CMakeLists.txt @@ -20,21 +20,5 @@ set_target_properties(yellowstone PROPERTIES LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} ${BASE_LINK_FLAGS}" ) +yunq_gen(lib/yellowstone lib yellowstone) -add_library(yellowstone_yunq - lib/yellowstone/yellowstone.yunq.cpp - lib/yellowstone/yellowstone.yunq.client.cpp - lib/yellowstone/yellowstone.yunq.server.cpp - ) - -target_include_directories(yellowstone_yunq - PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/lib") - -target_link_libraries(yellowstone_yunq - mammoth - ) - -set_target_properties(yellowstone_yunq PROPERTIES - COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}" - LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} ${BASE_LINK_FLAGS}" - ) diff --git a/yunq/yunq.py b/yunq/yunq.py index ba83a90..fa139e6 100755 --- a/yunq/yunq.py +++ b/yunq/yunq.py @@ -12,6 +12,7 @@ def main(): sys.exit("Takes name of file.") filename = sys.argv[1] + filebase = os.path.basename(filename) ast = None with open(filename, mode='r') as f: @@ -35,27 +36,27 @@ def main(): message_impl_tmpl = jinja_env.get_template("message.cpp.jinja") message_impl_tmpl.globals['Type'] = Type with open(filename + '.cpp', mode='w') as f: - message_impl = message_impl_tmpl.render(file=filename, messages=messages) + message_impl = message_impl_tmpl.render(file=filebase, messages=messages) f.write(message_impl) client_header_tmpl = jinja_env.get_template("client.h.jinja") with open(filename + '.client.h', mode='w') as f: - client_header = client_header_tmpl.render(file=filename, interfaces=interfaces) + client_header = client_header_tmpl.render(file=filebase, interfaces=interfaces) f.write(client_header) client_impl_tmpl = jinja_env.get_template("client.cpp.jinja") with open(filename + '.client.cpp', mode='w') as f: - client_impl = client_impl_tmpl.render(file=filename, interfaces=interfaces) + client_impl = client_impl_tmpl.render(file=filebase, interfaces=interfaces) f.write(client_impl) server_header_tmpl = jinja_env.get_template("server.h.jinja") with open(filename + '.server.h', mode='w') as f: - server_header = server_header_tmpl.render(file=filename, interfaces=interfaces) + server_header = server_header_tmpl.render(file=filebase, interfaces=interfaces) f.write(server_header) server_impl_tmpl = jinja_env.get_template("server.cpp.jinja") with open(filename + '.server.cpp', mode='w') as f: - server_impl = server_impl_tmpl.render(file=filename, interfaces=interfaces) + server_impl = server_impl_tmpl.render(file=filebase, interfaces=interfaces) f.write(server_impl) if __name__ == "__main__":