swig.cmake 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. set(SWIG_EXECUTABLE ${PROJECT_BINARY_DIR}/bin/swig${CMAKE_EXECUTABLE_SUFFIX})
  2. set(SWIG_SOURCE_FILE_EXTENSIONS .swg)
  3. function(add_swig_jni_library TgtName)
  4. set(opts "")
  5. set(oneval_args GEN_JAVA_FILES_LIST)
  6. set(multival_args SOURCES)
  7. cmake_parse_arguments(SWIG_JNI_LIB
  8. "${opts}"
  9. "${oneval_args}"
  10. "${multival_args}"
  11. ${ARGN}
  12. )
  13. set_property(SOURCE
  14. ${SWIG_JNI_LIB_SOURCES}
  15. PROPERTY
  16. CPLUSPLUS On
  17. )
  18. file(RELATIVE_PATH PathInProject ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
  19. string(REPLACE "/" "." JVMPackageName ${PathInProject})
  20. string(REPLACE "-" "_" JVMPackageName ${JVMPackageName})
  21. string(PREPEND JVMPackageName "ru.yandex.")
  22. string(REPLACE "." "/" OutDir ${JVMPackageName})
  23. string(CONCAT OutDirAbs ${CMAKE_CURRENT_BINARY_DIR} "/java/" ${OutDir})
  24. swig_add_library(${TgtName}
  25. TYPE SHARED
  26. LANGUAGE java
  27. OUTPUT_DIR ${OutDirAbs}
  28. OUTFILE_DIR ${CMAKE_CURRENT_BINARY_DIR}/cpp
  29. SOURCES
  30. ${SWIG_JNI_LIB_SOURCES}
  31. )
  32. if(APPLE)
  33. # for some legacy reason swig_add_library uses '.jnilib' suffix which has been replaced with '.dylib' since JDK7
  34. set_target_properties(${TgtName} PROPERTIES SUFFIX ".dylib")
  35. endif()
  36. set_property(TARGET ${TgtName} PROPERTY SWIG_COMPILE_OPTIONS -package ${JVMPackageName})
  37. add_custom_command(TARGET
  38. ${TgtName}
  39. POST_BUILD COMMAND
  40. ${CMAKE_COMMAND} -DJAVA_SRC_DIR=${OutDirAbs} -DJAVA_LST=${CMAKE_CURRENT_BINARY_DIR}/swig_gen_java.lst -P ${PROJECT_SOURCE_DIR}/build/scripts/gather_swig_java.cmake
  41. BYPRODUCTS ${SWIG_JNI_LIB_GEN_JAVA_FILES_LIST}
  42. )
  43. endfunction()