UseSWIG.cmake generates source independent of other targets
Target introduced in 2ee10119 in !1457 (merged) triggers generation of cxx files, which does not consider dependencies of target created by swig_add_library
.
Consider the following example:
add_library(A)
swig_add_library(B)
target_link_libraries(B A)
Behaviour prior to 3.11:
- Compile A
- Check dependencies of B and generate cxx files
- Compile B
Behaviour starting with 3.11:
- Compile A or compile
gen_B_bindingsLANG_wrap
, because they don't have mutual dependencies - Check dependencies of B
- Compile B
Example in real project was described in !1973 (closed)
This new target creates an issue when SWIG is downloaded with ExternalProject_Add
as it is done here, because it will run generation command before the executable is downloaded and built due to missing dependency.
And because swig_add_library
-created target depends on external project in our CMakeLists.txt, it works fine prior to 3.11, because it does not trigger generation before external project is done.
~~The thing is that the target introduced in specified commit is internal -- it is not possible to get its' name outside the UseSWIG.cmake
, therefore it is not possible place an add_dependency
to it.~~It is possible to call add_dependencies
for swig_gen_target
outside the script, but this is undocumented. Solution proposed by @marc.chevrier
function (MYSWIG_ADD_LIBRARY target)
swig_add_library(${ARGV})
add_dependencies (${target} <ExternalProject_SWIG_target>)
endfunction()
does not solve the issue because the target in UseSWIG.cmake
remains unaffected.
This is example output after adding add_dependencies(irohajava swig swig_swig)
:
cmake --build build --target irohajava -- -j8
Scanning dependencies of target hyperledger_ed25519
Scanning dependencies of target generator
Scanning dependencies of target schema
Scanning dependencies of target iroha_amount
Scanning dependencies of target swig_swig
Scanning dependencies of target shared_model_cryptography_model
Scanning dependencies of target gen_irohajava_bindingsJAVA_wrap
[ 0%] Creating directories for 'swig_swig'
[ 2%] Creating directories for 'hyperledger_ed25519'
[ 4%] Swig source
[ 6%] Performing download step (git clone) for 'hyperledger_ed25519'
[ 8%] Performing download step (download, verify and extract) for 'swig_swig'
/bin/sh: ../../external/src/swig_swig/swig: No such file or directory
make[3]: *** [bindings/bindingsJAVA_wrap.stamp] Error 127
make[3]: *** Deleting file `bindings/bindingsJAVA_wrap.stamp'
make[2]: *** [bindings/CMakeFiles/gen_irohajava_bindingsJAVA_wrap.dir/all] Error 2
make[2]: *** Waiting for unfinished jobs....