Skip to content

Commit

Permalink
Fix bindings and Android package build (hyperledger-iroha#1249)
Browse files Browse the repository at this point in the history
 - 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 <[email protected]>
  • Loading branch information
lebdron authored Apr 24, 2018
1 parent 4a13377 commit 14a852d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
8 changes: 5 additions & 3 deletions cmake/Modules/Findswig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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)

Expand Down
22 changes: 18 additions & 4 deletions shared_model/bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions shared_model/packages/android/android-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fi
if [[ ( "$#" -ne 4 ) && ( "$#" -ne 5 ) ]]; then
echo "Illegal number of parameters"
echo "Usage: $0 <PLATFORM> <ANDROID_VERSION> <NDK_PATH> <PACKAGE> [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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 14a852d

Please sign in to comment.