python-config.cmake 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. # this file actually ingests the library and defines targets.
  9. set(MY "Python")
  10. set(TARGET_WITH_NAMESPACE "3rdParty::${MY}")
  11. if (TARGET ${TARGET_WITH_NAMESPACE})
  12. return()
  13. endif()
  14. # this FindPython file is designed to be compatible with the base FindPython
  15. # to at least some degree. As such, it uses the same variable names:
  16. # this script defines:
  17. # Python_EXECUTABLE - full path to executable
  18. # Python_INTERPRETER_ID - "Python"
  19. # Python_HOME - Where the python folder root is (ie, folder has subfolder of 'Lib')
  20. # Python_PATHS - Where sys.path should point at to find modules, libraries, etc.
  21. # Python_Development_FOUND - The platform we are cross compiling for can link to python
  22. # and a target called 3rdParty::Python that you can use to depend on
  23. set(${MY}_VERSION 3.7.10)
  24. set(${MY}_INTERPRETER_ID "Python")
  25. set(${MY}_EXECUTABLE ${CMAKE_CURRENT_LIST_DIR}/python/bin/python)
  26. set(${MY}_HOME ${CMAKE_CURRENT_LIST_DIR}/python)
  27. set(${MY}_PATHS ${CMAKE_CURRENT_LIST_DIR}/python/lib
  28. ${CMAKE_CURRENT_LIST_DIR}/python/lib/python3.7
  29. ${CMAKE_CURRENT_LIST_DIR}/python/lib/python3.7/lib-dynload
  30. ${CMAKE_CURRENT_LIST_DIR}/python/lib/python3.7/site-packages)
  31. # only if we're compiling FOR on one of the available platforms, add the target and libraries:
  32. if (${PAL_PLATFORM_NAME} STREQUAL "Linux" )
  33. set(${MY}_Development_FOUND TRUE)
  34. # Do not use these PYTHON_LIBRARY_* or other variables, instead, use the
  35. # target '3rdParty::Python'
  36. # note: we built the shared version of python, you must use the .so
  37. # in order to load it. If you don't, then python itself will load a module
  38. # from a .so and that module will try to load the dylib for python itself
  39. # and bad things will occur since there'll essentially be both the static
  40. # and dy version of python in one address space.
  41. # also, because the regular .so is a symlink, we actually skip that and link
  42. # to the real one, so that there's no conflict between what library we copy
  43. # and what library we link to.
  44. set(${MY}_LIBRARY_DEBUG ${CMAKE_CURRENT_LIST_DIR}/python/lib/libpython3.7m.so.1.0)
  45. set(${MY}_LIBRARY_RELEASE ${CMAKE_CURRENT_LIST_DIR}/python/lib/libpython3.7m.so.1.0)
  46. set(${MY}_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/python/include/python3.7m)
  47. # DYLIBS causes things to be copied to the bin folder to satisfy RPATH origin
  48. set(${MY}_DYLIBS_DEBUG ${CMAKE_CURRENT_LIST_DIR}/python/lib/libpython3.7m.so.1.0)
  49. set(${MY}_DYLIBS_RELEASE ${CMAKE_CURRENT_LIST_DIR}/python/lib/libpython3.7m.so.1.0)
  50. set(${MY}_COMPILE_DEFINITIONS DEFAULT_LY_PYTHONHOME="${CMAKE_CURRENT_LIST_DIR}/python")
  51. # the rest of this file could be reused for almost any target:
  52. # we set it to a generator expression for multi-config situations:
  53. set(${MY}_LIBRARY "$<IF:$<CONFIG:Debug>,${${MY}_LIBRARY_DEBUG},${${MY}_LIBRARY_RELEASE}>")
  54. set(${MY}_DYLIBS "$<IF:$<CONFIG:Debug>,${${MY}_DYLIBS_DEBUG},${${MY}_DYLIBS_RELEASE}>")
  55. # now set up the target using the above declarations....
  56. add_library(${TARGET_WITH_NAMESPACE} INTERFACE IMPORTED GLOBAL)
  57. ly_target_include_system_directories(TARGET ${TARGET_WITH_NAMESPACE} INTERFACE ${${MY}_INCLUDE_DIR})
  58. target_link_libraries(${TARGET_WITH_NAMESPACE} INTERFACE "${${MY}_LIBRARY}")
  59. target_compile_definitions(${TARGET_WITH_NAMESPACE} INTERFACE "${${MY}_COMPILE_DEFINITIONS}")
  60. # we also need to add the python dlls to be copied to the binaries folder...
  61. set_target_properties(${TARGET_WITH_NAMESPACE} PROPERTIES INTERFACE_IMPORTED_LOCATION "${${MY}_DYLIBS}")
  62. endif()
  63. set(${MY}_FOUND True)