From 14a852d98a19d1864bbd2e0eb1fd5e1144cee75b Mon Sep 17 00:00:00 2001 From: Andrei Lebedev Date: Tue, 24 Apr 2018 13:47:20 +0300 Subject: [PATCH] Fix bindings and Android package build (#1249) - UPDATE_COMMAND was supposedly doing an unnecessary reconfiguration and rebuild - SWIG_DIR was pointing to root instead of directory with swig.swg - Add swig dependency for target introduced in CMake 3.11 - Fix android-build.sh with new lines in sed - Fix empty dependency list handling; fix swig flags @luckychess - Set version as separate var in Findswig.cmake; use $HOME in example Signed-off-by: Andrei Lebedev --- cmake/Modules/Findswig.cmake | 8 ++++--- shared_model/bindings/CMakeLists.txt | 22 +++++++++++++++---- .../packages/android/android-build.sh | 10 ++++----- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/cmake/Modules/Findswig.cmake b/cmake/Modules/Findswig.cmake index 449a957902..e012686edf 100644 --- a/cmake/Modules/Findswig.cmake +++ b/cmake/Modules/Findswig.cmake @@ -8,8 +8,9 @@ find_package_handle_standard_args(SWIG DEFAULT_MSG if(NOT SWIG_EXECUTABLE) find_package(Git REQUIRED) - set(URL ftp://www.mirrorservice.org/sites/ftp.sourceforge.net/pub/sourceforge/s/sw/swig/swig/swig-3.0.12/swig-3.0.12.tar.gz) - set_target_description(swig "Simplified Wrapper and Interface Generator (SWIG)" ${URL} 3.0.12) + set(SWIG_VERSION 3.0.12) + set(URL ftp://www.mirrorservice.org/sites/ftp.sourceforge.net/pub/sourceforge/s/sw/swig/swig/swig-${SWIG_VERSION}/swig-${SWIG_VERSION}.tar.gz) + set_target_description(swig "Simplified Wrapper and Interface Generator (SWIG)" ${URL} ${SWIG_VERSION}) ExternalProject_Add(swig_swig URL ${URL} @@ -20,12 +21,13 @@ if(NOT SWIG_EXECUTABLE) BUILD_IN_SOURCE ON BUILD_COMMAND ${MAKE} swig TEST_COMMAND "" # remove test step + UPDATE_COMMAND "" # remove update step ) ExternalProject_Get_Property(swig_swig source_dir) # Predefined vars for local installed SWIG set(SWIG_EXECUTABLE ${source_dir}/swig) - set(SWIG_DIR ${source_dir}) + set(SWIG_DIR ${source_dir}/share/swig/${SWIG_VERSION}) add_dependencies(swig swig_swig) diff --git a/shared_model/bindings/CMakeLists.txt b/shared_model/bindings/CMakeLists.txt index 93cdc42011..213bed5777 100644 --- a/shared_model/bindings/CMakeLists.txt +++ b/shared_model/bindings/CMakeLists.txt @@ -41,6 +41,20 @@ if (SWIG_PYTHON OR SWIG_JAVA OR SWIG_CSHARP OR SWIG_NODE) set_property(GLOBAL PROPERTY SWIG_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}) add_dependencies(bindings swig) + + macro (myswig_add_library target) + swig_add_library(${ARGV}) + # get internal dependencies + get_target_property(dependencies + ${SWIG_MODULE_${target}_REAL_NAME} + MANUALLY_ADDED_DEPENDENCIES) + if (dependencies) + # add external project dependency on internal targets + foreach (dependency IN LISTS dependencies) + add_dependencies(${dependency} swig) + endforeach() + endif() + endmacro() endif() if (SWIG_PYTHON) @@ -54,7 +68,7 @@ if (SWIG_PYTHON) set(MAC_OPTS "-flat_namespace -undefined suppress") endif() - swig_add_library(iroha LANGUAGE python SOURCES bindings.i) + myswig_add_library(iroha LANGUAGE python SOURCES bindings.i) swig_link_libraries(iroha ${Python_LIBRARIES} bindings ${MAC_OPTS}) add_custom_target(irohapy DEPENDS ${SWIG_MODULE_iroha_REAL_NAME}) # path to where Python.h is found @@ -66,7 +80,7 @@ endif() if (SWIG_JAVA) find_package(JNI REQUIRED) - swig_add_library(irohajava LANGUAGE java SOURCES bindings.i) + myswig_add_library(irohajava LANGUAGE java SOURCES bindings.i) swig_link_libraries(irohajava ${Java_LIBRARIES} bindings) # the include path to jni.h and jni_md.h target_include_directories(${SWIG_MODULE_irohajava_REAL_NAME} PUBLIC @@ -76,7 +90,7 @@ if (SWIG_JAVA) endif() if (SWIG_CSHARP) - swig_add_library(libirohacs LANGUAGE csharp SOURCES bindings.i) + myswig_add_library(libirohacs LANGUAGE csharp SOURCES bindings.i) swig_link_libraries(libirohacs bindings) add_custom_target(irohacs DEPENDS ${SWIG_MODULE_libirohacs_REAL_NAME}) endif() @@ -99,7 +113,7 @@ if (SWIG_NODE) set_property(SOURCE bindings.i PROPERTY SWIG_FLAGS "-node" "-DV8_VERSION=${V8_VERSION_HEX}") # Build SWIG library always statically for the subsequent assembly by GYP - swig_add_library(irohanode + myswig_add_library(irohanode TYPE STATIC LANGUAGE javascript SOURCES bindings.i diff --git a/shared_model/packages/android/android-build.sh b/shared_model/packages/android/android-build.sh index a7f1caca92..e6359c87cc 100755 --- a/shared_model/packages/android/android-build.sh +++ b/shared_model/packages/android/android-build.sh @@ -7,7 +7,7 @@ fi if [[ ( "$#" -ne 4 ) && ( "$#" -ne 5 ) ]]; then echo "Illegal number of parameters" echo "Usage: $0 [BUILD_TYPE=Release]" - echo "Example: $0 arm64-v8a 26 /Users/me/Downloads/android-ndk-r16b jp.co.soramitsu.iroha.android Debug" + echo "Example: $0 arm64-v8a 26 $HOME/Downloads/android-ndk-r16b jp.co.soramitsu.iroha.android Debug" exit 1 fi @@ -99,10 +99,10 @@ VERBOSE=1 cmake --build ./iroha-ed25519/build --target install -- -j"$CORES" mv "$DEPS_DIR"/lib/static/libed25519.a "$DEPS_DIR"/lib; rmdir "$DEPS_DIR"/lib/static/ # SWIG fixes -sed -i.bak "s~find_package(JNI REQUIRED)~#find_package(JNI REQUIRED)~" ./iroha/shared_model/bindings/CMakeLists.txt -sed -i.bak "s~include_directories(${JAVA_INCLUDE_PATH})~#include_directories(${JAVA_INCLUDE_PATH})~" ./iroha/shared_model/bindings/CMakeLists.txt -sed -i.bak "s~include_directories(${JAVA_INCLUDE_PATH2})~#include_directories(${JAVA_INCLUDE_PATH2})~" ./iroha/shared_model/bindings/CMakeLists.txt -sed -i.bak "s~# the include path to jni.h~SET(CMAKE_SWIG_FLAGS \${CMAKE_SWIG_FLAGS} -package ${PACKAGE})~" ./iroha/shared_model/bindings/CMakeLists.txt +sed -i.bak "s~find_package(JNI REQUIRED)~SET(CMAKE_SWIG_FLAGS \${CMAKE_SWIG_FLAGS} -package ${PACKAGE})~" ./iroha/shared_model/bindings/CMakeLists.txt +sed -i.bak "s~\${JAVA_INCLUDE_PATH}~#\${JAVA_INCLUDE_PATH}~" ./iroha/shared_model/bindings/CMakeLists.txt +sed -i.bak "s~\${JAVA_INCLUDE_PATH2}~#\${JAVA_INCLUDE_PATH2}~" ./iroha/shared_model/bindings/CMakeLists.txt +sed -i.bak "s~target_include_directories(\${SWIG_MODULE_irohajava_REAL_NAME} PUBLIC~SET(CMAKE_SWIG_FLAGS \${CMAKE_SWIG_FLAGS}~" ./iroha/shared_model/bindings/CMakeLists.txt sed -i.bak "s~swig_link_libraries(irohajava~swig_link_libraries(irohajava \"${PWD}/protobuf/.build/lib${PROTOBUF_LIB_NAME}.a\" \"${NDK_PATH}/platforms/android-${VERSION}/${ARCH}/usr/${LIBP}/liblog.so\"~" ./iroha/shared_model/bindings/CMakeLists.txt # build iroha