From 33e1ff645c741d4900eac3c343a203a5f77d1e67 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Mon, 30 Sep 2019 22:31:46 +0200 Subject: [PATCH] Allow to pass include directories to the add_swig_xyz commands This will be needed when the wrappers no longer live in the same directory as the objects they are wrapping. --- bindings/python/CMakeLists.txt | 1 + common/cmake_modules/GncAddSwigCommand.cmake | 29 ++++++++++++++++--- common/test-core/CMakeLists.txt | 4 +-- gnucash/gnome-utils/CMakeLists.txt | 2 +- gnucash/gnome/CMakeLists.txt | 2 +- gnucash/html/CMakeLists.txt | 2 +- gnucash/report/CMakeLists.txt | 2 +- libgnucash/app-utils/CMakeLists.txt | 4 +-- libgnucash/core-utils/CMakeLists.txt | 4 +-- libgnucash/engine/CMakeLists.txt | 2 +- libgnucash/gnc-module/CMakeLists.txt | 2 +- .../gnc-module/test/mod-bar/CMakeLists.txt | 2 +- .../gnc-module/test/mod-baz/CMakeLists.txt | 2 +- .../gnc-module/test/mod-foo/CMakeLists.txt | 2 +- 14 files changed, 41 insertions(+), 19 deletions(-) diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt index 83509209c3..324255bdfc 100644 --- a/bindings/python/CMakeLists.txt +++ b/bindings/python/CMakeLists.txt @@ -40,6 +40,7 @@ gnc_add_swig_python_command (swig-gnucash-core SWIG_GNUCASH_CORE_C SWIG_GNUCASH_CORE_PY gnucash_core.c gnucash_core_c.py ${SWIG_FILES} + "" ${CMAKE_SOURCE_DIR}/common/base-typemaps.i ${CMAKE_SOURCE_DIR}/libgnucash/engine/engine-common.i ${GNUCASH_CORE_C_INCLUDES} diff --git a/common/cmake_modules/GncAddSwigCommand.cmake b/common/cmake_modules/GncAddSwigCommand.cmake index 4b96b415b4..75edd5233f 100644 --- a/common/cmake_modules/GncAddSwigCommand.cmake +++ b/common/cmake_modules/GncAddSwigCommand.cmake @@ -10,18 +10,35 @@ # - _out_var will be set to the full path to the generated wrapper file # - _output is the name of the wrapper file to generate # - _input is the swig interface file (*.i) to generate this wrapper from +# - _include_dirs is an optional list of include directories to pass to the swig command +# For guile two directories are always passed by default: +# ${CMAKE_SOURCE_DIR}/common and ${CMAKE_SOURCE_DIR}/libgnucash/engine # Any additional parameters will be used as dependencies for this wrapper target -macro (gnc_add_swig_guile_command _target _out_var _output _input) +macro (gnc_add_swig_guile_command _target _out_var _output _input _include_dirs) set(SW_CURR_BUILD_SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}) set(SW_BUILD_SOURCE_DIR ${CMAKE_BINARY_DIR}) set(outfile ${SW_CURR_BUILD_SOURCE_DIR}/${_output}) set(${_out_var} ${outfile}) # This variable is set for convenience to use in the calling CMakeLists.txt + + set (DEFAULT_SWIG_GUILE_FLAGS + -guile -Linkage module + ${SWIG_ARGS} + ) + set (DEFAULT_SWIG_GUILE_C_INCLUDES + ${CMAKE_SOURCE_DIR}/common + ${CMAKE_SOURCE_DIR}/libgnucash/engine + ) + set (GUILE_SWIG_FLAGS ${DEFAULT_SWIG_GUILE_FLAGS}) + foreach (dir ${DEFAULT_SWIG_GUILE_C_INCLUDES} ${_include_dirs}) + list (APPEND GUILE_SWIG_FLAGS "-I${dir}") + endforeach (dir) + add_custom_command ( OUTPUT ${outfile} DEPENDS ${_input} ${CMAKE_SOURCE_DIR}/common/base-typemaps.i ${ARGN} - COMMAND ${SWIG_EXECUTABLE} -guile ${SWIG_ARGS} -Linkage module -I${CMAKE_SOURCE_DIR}/libgnucash/engine -I${CMAKE_SOURCE_DIR}/common -o ${outfile} ${_input} + COMMAND ${SWIG_EXECUTABLE} ${GUILE_SWIG_FLAGS} -o ${outfile} ${_input} ) add_custom_target(${_target} DEPENDS ${outfile}) endmacro (gnc_add_swig_guile_command) @@ -36,8 +53,12 @@ endmacro (gnc_add_swig_guile_command) # - _output is the name of the wrapper file to generate # - _py_output is the name of the python module associated with this wrapper # - _input is the swig interface file (*.i) to generate this wrapper from +# - _include_dirs is an optional list of include directories to pass to the swig command +# For python four directories are always passed by default: +# ${GLIB2_INCLUDE_DIRS}, ${CMAKE_SOURCE_DIR}/common, +# ${CMAKE_SOURCE_DIR}/libgnucash/app-utils and ${CMAKE_SOURCE_DIR}/libgnucash/engine # Any additional parameters will be used as dependencies for this wrapper target -macro (gnc_add_swig_python_command _target _out_var _py_out_var _output _py_output _input) +macro (gnc_add_swig_python_command _target _out_var _py_out_var _output _py_output _input _include_dirs) set(SW_CURR_BUILD_SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}) set(SW_BUILD_SOURCE_DIR ${CMAKE_BINARY_DIR}) @@ -60,7 +81,7 @@ macro (gnc_add_swig_python_command _target _out_var _py_out_var _output _py_outp ) set (PYTHON_SWIG_FLAGS ${DEFAULT_SWIG_PYTHON_FLAGS}) - foreach (dir ${DEFAULT_SWIG_PYTHON_C_INCLUDES}) + foreach (dir ${DEFAULT_SWIG_PYTHON_C_INCLUDES} ${_include_dirs}) list (APPEND PYTHON_SWIG_FLAGS "-I${dir}") endforeach (dir) add_custom_command(OUTPUT ${outfile} ${py_outfile} diff --git a/common/test-core/CMakeLists.txt b/common/test-core/CMakeLists.txt index 42c13461e3..34fde1e7e1 100644 --- a/common/test-core/CMakeLists.txt +++ b/common/test-core/CMakeLists.txt @@ -30,14 +30,14 @@ endif() # Command to generate the swig-unittest-support-guile.c wrapper file gnc_add_swig_guile_command (swig-unittest-support-guile-c SWIG_UNITTEST_SUPPORT_GUILE_C swig-unittest-support-guile.c - ${CMAKE_CURRENT_SOURCE_DIR}/unittest-support.i ${test_core_HEADERS} + ${CMAKE_CURRENT_SOURCE_DIR}/unittest-support.i "" ${test_core_HEADERS} ) # Command to generate the swig-unittest-support-python.c wrapper file gnc_add_swig_python_command (swig-unittest-support-python SWIG_UNITTEST_SUPPORT_PYTHON_C SWIG_UNITTEST_SUPPORT_PYTHON_PY swig-unittest-support-python.c unittest_support.py - ${CMAKE_CURRENT_SOURCE_DIR}/unittest-support.i + ${CMAKE_CURRENT_SOURCE_DIR}/unittest-support.i "" ) add_library(test-core-guile ${SWIG_UNITTEST_SUPPORT_GUILE_C}) diff --git a/gnucash/gnome-utils/CMakeLists.txt b/gnucash/gnome-utils/CMakeLists.txt index 7f6caf2a89..fe7b29ca56 100644 --- a/gnucash/gnome-utils/CMakeLists.txt +++ b/gnucash/gnome-utils/CMakeLists.txt @@ -5,7 +5,7 @@ add_subdirectory(test) # Command to generate the swig-gnome-utils.c wrapper file gnc_add_swig_guile_command (swig-gnome-utils-c SWIG_GNOME_UTILS_C swig-gnome-utils.c - ${CMAKE_CURRENT_SOURCE_DIR}/gnome-utils.i + ${CMAKE_CURRENT_SOURCE_DIR}/gnome-utils.i "" ) set (WARNINGS_SCHEMA ${DATADIR_BUILD}/glib-2.0/schemas/org.gnucash.warnings.gschema.xml) diff --git a/gnucash/gnome/CMakeLists.txt b/gnucash/gnome/CMakeLists.txt index 01c4663983..45e28a330a 100644 --- a/gnucash/gnome/CMakeLists.txt +++ b/gnucash/gnome/CMakeLists.txt @@ -64,7 +64,7 @@ set (gnc_gnome_noinst_HEADERS # Command to generate the swig-gnome.c wrapper file gnc_add_swig_guile_command (swig-gnome-c SWIG_GNOME_C swig-gnome.c - ${CMAKE_CURRENT_SOURCE_DIR}/gnome.i ${gnc_gnome_HEADERS} + ${CMAKE_CURRENT_SOURCE_DIR}/gnome.i "" ${gnc_gnome_HEADERS} ) set (gnc_gnome_SOURCES diff --git a/gnucash/html/CMakeLists.txt b/gnucash/html/CMakeLists.txt index 834cc8f4a3..4669495727 100644 --- a/gnucash/html/CMakeLists.txt +++ b/gnucash/html/CMakeLists.txt @@ -12,7 +12,7 @@ set (html_HEADERS # Command to generate the swig-gnc-html.c wrapper file gnc_add_swig_guile_command (swig-gnc-html-c SWIG_GNC_HTML_C swig-gnc-html.c - ${CMAKE_CURRENT_SOURCE_DIR}/gnc-html.i "${gncmod_html_HEADERS}" + ${CMAKE_CURRENT_SOURCE_DIR}/gnc-html.i "" "${gncmod_html_HEADERS}" ) set (html_SOURCES diff --git a/gnucash/report/CMakeLists.txt b/gnucash/report/CMakeLists.txt index c7456f6915..2c30a6377a 100644 --- a/gnucash/report/CMakeLists.txt +++ b/gnucash/report/CMakeLists.txt @@ -11,7 +11,7 @@ set (report_HEADERS # Command to generate the swig-report.c wrapper file gnc_add_swig_guile_command (swig-report-c SWIG_REPORT_C swig-report.c - ${CMAKE_CURRENT_SOURCE_DIR}/report.i ${report_HEADERS} + ${CMAKE_CURRENT_SOURCE_DIR}/report.i "" ${report_HEADERS} ) set (report_SOURCES diff --git a/libgnucash/app-utils/CMakeLists.txt b/libgnucash/app-utils/CMakeLists.txt index b34ca641c8..dca49c237c 100644 --- a/libgnucash/app-utils/CMakeLists.txt +++ b/libgnucash/app-utils/CMakeLists.txt @@ -38,14 +38,14 @@ set (app_utils_HEADERS # Command to generate the swig-app-utils-guile.c wrapper file gnc_add_swig_guile_command (swig-apputils-guile-c SWIG_APP_UTILS_GUILE_C swig-app-utils-guile.c - ${CMAKE_CURRENT_SOURCE_DIR}/app-utils.i + ${CMAKE_CURRENT_SOURCE_DIR}/app-utils.i "" ) # Command to generate the swig-app-utils-python.c wrapper file gnc_add_swig_python_command (swig-app-utils-python SWIG_APP_UTILS_PYTHON_C SWIG_APP_UTILS_PYTHON_PY swig-app-utils-python.c sw_app_utils.py - ${CMAKE_CURRENT_SOURCE_DIR}/app-utils.i + ${CMAKE_CURRENT_SOURCE_DIR}/app-utils.i "" ) set (app_utils_SOURCES diff --git a/libgnucash/core-utils/CMakeLists.txt b/libgnucash/core-utils/CMakeLists.txt index a999f15e2c..ac4850cd3c 100644 --- a/libgnucash/core-utils/CMakeLists.txt +++ b/libgnucash/core-utils/CMakeLists.txt @@ -5,14 +5,14 @@ add_subdirectory(test) # Command to generate the swig-core-utils-guile.c wrapper file gnc_add_swig_guile_command (swig-core-utils-guile-c SWIG_CORE_UTILS_GUILE_C swig-core-utils-guile.c - ${CMAKE_CURRENT_SOURCE_DIR}/core-utils.i + ${CMAKE_CURRENT_SOURCE_DIR}/core-utils.i "" ) # Command to generate the swig-core-utils-python.c wrapper file gnc_add_swig_python_command (swig-core-utils-python SWIG_CORE_UTILS_PYTHON_C SWIG_CORE_UTILS_PYTHON_PY swig-core-utils-python.c sw_core_utils.py - ${CMAKE_CURRENT_SOURCE_DIR}/core-utils.i + ${CMAKE_CURRENT_SOURCE_DIR}/core-utils.i "" ) set (core_utils_SOURCES diff --git a/libgnucash/engine/CMakeLists.txt b/libgnucash/engine/CMakeLists.txt index 19e429b9ce..4f9c922961 100644 --- a/libgnucash/engine/CMakeLists.txt +++ b/libgnucash/engine/CMakeLists.txt @@ -121,7 +121,7 @@ set (engine_HEADERS # Command to generate the swig-engine.c wrapper file gnc_add_swig_guile_command (swig-engine-c SWIG_ENGINE_C swig-engine.c - ${CMAKE_CURRENT_SOURCE_DIR}/engine.i ${engine_HEADERS} + ${CMAKE_CURRENT_SOURCE_DIR}/engine.i "" ${engine_HEADERS} ) # Command to generate the iso-4217-currencies.c file diff --git a/libgnucash/gnc-module/CMakeLists.txt b/libgnucash/gnc-module/CMakeLists.txt index b84654b2c0..01d0b2cb73 100644 --- a/libgnucash/gnc-module/CMakeLists.txt +++ b/libgnucash/gnc-module/CMakeLists.txt @@ -5,7 +5,7 @@ add_subdirectory(example) # Command to generate the swig-gnc-module.c wrapper file gnc_add_swig_guile_command (swig-gnc-module-c SWIG_GNC_MODULE_C swig-gnc-module.c - ${CMAKE_CURRENT_SOURCE_DIR}/gnc-module.i + ${CMAKE_CURRENT_SOURCE_DIR}/gnc-module.i "" ) set (gnc_module_SOURCES gnc-module.c) diff --git a/libgnucash/gnc-module/test/mod-bar/CMakeLists.txt b/libgnucash/gnc-module/test/mod-bar/CMakeLists.txt index ddeefb7864..0912b23db6 100644 --- a/libgnucash/gnc-module/test/mod-bar/CMakeLists.txt +++ b/libgnucash/gnc-module/test/mod-bar/CMakeLists.txt @@ -1,7 +1,7 @@ gnc_add_swig_guile_command (swig-bar-c SWIG_BAR_C swig-bar.c - ${CMAKE_CURRENT_SOURCE_DIR}/bar.i bar.h + ${CMAKE_CURRENT_SOURCE_DIR}/bar.i "" bar.h ) add_library(bar EXCLUDE_FROM_ALL bar.c bar.h) diff --git a/libgnucash/gnc-module/test/mod-baz/CMakeLists.txt b/libgnucash/gnc-module/test/mod-baz/CMakeLists.txt index f83fed30e0..f39d658e16 100644 --- a/libgnucash/gnc-module/test/mod-baz/CMakeLists.txt +++ b/libgnucash/gnc-module/test/mod-baz/CMakeLists.txt @@ -1,7 +1,7 @@ gnc_add_swig_guile_command (swig-baz-c SWIG_BAZ_C swig-baz.c - ${CMAKE_CURRENT_SOURCE_DIR}/baz.i baz.h + ${CMAKE_CURRENT_SOURCE_DIR}/baz.i "" baz.h ) add_library(baz EXCLUDE_FROM_ALL baz.c baz.h) diff --git a/libgnucash/gnc-module/test/mod-foo/CMakeLists.txt b/libgnucash/gnc-module/test/mod-foo/CMakeLists.txt index c184eef7dd..583115770f 100644 --- a/libgnucash/gnc-module/test/mod-foo/CMakeLists.txt +++ b/libgnucash/gnc-module/test/mod-foo/CMakeLists.txt @@ -1,7 +1,7 @@ gnc_add_swig_guile_command (swig-foo-c SWIG_FOO_C swig-foo.c - ${CMAKE_CURRENT_SOURCE_DIR}/foo.i foo.h + ${CMAKE_CURRENT_SOURCE_DIR}/foo.i "" foo.h ) add_library(foo EXCLUDE_FROM_ALL foo.c foo.h)