ctkScriptWrapPythonQt_Light.cmake 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. ###########################################################################
  2. #
  3. # Library: CTK
  4. #
  5. # Copyright (c) Kitware Inc.
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License");
  8. # you may not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0.txt
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19. ###########################################################################
  20. #
  21. # ctkScriptWrapPythonQt_Light
  22. #
  23. #
  24. # This script should be invoked either as a CUSTOM_COMMAND
  25. # or from the command line using the following syntax:
  26. #
  27. # cmake -DWRAPPING_SCRIPT:FILEPATH=/path/to/ctkWrapPythonQt.py
  28. # -DWRAPPING_NAMESPACE:STRING=org.commontk -DTARGET:STRING=MyLib
  29. # -DSOURCES:STRING="file1^^file2"
  30. # -DOUTPUT_DIR:PATH=/path
  31. # -DPYTHON_EXECUTABLE:FILEPATH=/path/to/python
  32. # -DPYTHON_LIBRARY_PATH:PATH=/path/to/pythonlib
  33. # -P ctkScriptWrapPythonQt_Light.cmake
  34. #
  35. #
  36. # LOG FILE:
  37. # File ctkScriptWrapPythonQt_Light_log.txt will be created in the current directory.
  38. # It will contain the list of class and the constructor signature that will be wrapped.
  39. #
  40. # Check for non-defined var
  41. foreach(var WRAPPING_NAMESPACE TARGET SOURCES)
  42. if(NOT DEFINED ${var})
  43. message(FATAL_ERROR "${var} not specified when calling ctkScriptWrapPythonQt")
  44. endif()
  45. endforeach()
  46. # Check for non-existing ${var}
  47. foreach(var WRAPPING_SCRIPT OUTPUT_DIR PYTHON_EXECUTABLE PYTHON_LIBRARY_PATH)
  48. if(NOT EXISTS ${${var}})
  49. message(FATAL_ERROR "Failed to find ${var}=\"${${var}}\" when calling ctkScriptWrapPythonQt")
  50. endif()
  51. endforeach()
  52. # Convert ^^ separated string to list
  53. string(REPLACE "^^" ";" SOURCES "${SOURCES}")
  54. if(WIN32)
  55. set(ENV{PATH} ${PYTHON_LIBRARY_PATH};$ENV{PATH})
  56. elseif(APPLE)
  57. set(ENV{DYLD_LIBRARY_PATH} ${PYTHON_LIBRARY_PATH}:$ENV{DYLD_LIBRARY_PATH})
  58. else()
  59. set(ENV{LD_LIBRARY_PATH} ${PYTHON_LIBRARY_PATH}:$ENV{LD_LIBRARY_PATH})
  60. endif()
  61. set(verbose 0)
  62. set(extra_args)
  63. if(verbose)
  64. set(extra_args --extra-verbose)
  65. endif()
  66. execute_process(
  67. COMMAND ${PYTHON_EXECUTABLE} ${WRAPPING_SCRIPT}
  68. --target=${TARGET} --namespace=${WRAPPING_NAMESPACE} --output-dir=${OUTPUT_DIR} ${extra_args}
  69. ${SOURCES}
  70. RESULT_VARIABLE result
  71. OUTPUT_VARIABLE output
  72. ERROR_VARIABLE error
  73. OUTPUT_STRIP_TRAILING_WHITESPACE
  74. )
  75. if(NOT result EQUAL 0)
  76. message(FATAL_ERROR "Failed to wrap target: ${TARGET}\n${output}\n${error}")
  77. else()
  78. if(verbose)
  79. message(${output})
  80. endif()
  81. endif()