CMakeLists.txt 5.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #
  2. # Copyright (c) 2008-2020 the Urho3D project.
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"), to deal
  6. # in the Software without restriction, including without limitation the rights
  7. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. # copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in
  12. # all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. # THE SOFTWARE.
  21. #
  22. # Set project name
  23. project (Urho3D-Tools)
  24. # Find Urho3D library
  25. find_package (Urho3D REQUIRED)
  26. include_directories (${URHO3D_INCLUDE_DIRS})
  27. # Urho3DPlayer target is rather special, although it is here, it is not a tool because it is built into target platform binary as opposed to host platform
  28. # In order to test the player on Web platform built using Emscripten, the request parameters need to be parsed into Module['argument'] (see https://github.com/kripken/emscripten/blob/master/src/emrun_prejs.js for inspiration)
  29. # The CTest could "run" the Urho3DPlayer.html with script name as parameter, thanks to emrun performing this parsing automatically
  30. # In a production environment, however, the request parameters parsing has to be done by the application itself one way or another
  31. if (URHO3D_ANGELSCRIPT OR URHO3D_LUA)
  32. # Add Urho3DPlayer as target only when one of the supported scripting subsystems is enabled
  33. add_subdirectory (Urho3DPlayer)
  34. endif ()
  35. # Build host-tools using host compiler toolchain
  36. if (CMAKE_CROSSCOMPILING)
  37. check_native_compiler_exist ()
  38. # When cross-compiling, build the host tool as external project
  39. include (ExternalProject)
  40. if (IOS OR TVOS)
  41. # When cross-compiling for iOS/tvOS the host environment has been altered by xcodebuild for the said platform, the following fix is required to reset the host environment before spawning another process to configure/generate project file for external project
  42. # Also workaround a known CMake/Xcode generator bug which prevents it from installing native tool binaries correctly
  43. set (ALTERNATE_COMMAND CMAKE_COMMAND /usr/bin/env -i PATH=$ENV{PATH} CC=${SAVED_CC} CXX=${SAVED_CXX} CI=$ENV{CI} ${CMAKE_COMMAND} BUILD_COMMAND bash -c "sed -i '' 's/\$$\(EFFECTIVE_PLATFORM_NAME\)//g' CMakeScripts/install_postBuildPhase.make*")
  44. else ()
  45. set (ALTERNATE_COMMAND CMAKE_COMMAND ${CMAKE_COMMAND} -E env CC=${SAVED_CC} CXX=${SAVED_CXX} CI=$ENV{CI} ${CMAKE_COMMAND})
  46. endif ()
  47. if (URHO3D_PACKAGING)
  48. ExternalProject_Add (PackageTool
  49. SOURCE_DIR ${CMAKE_SOURCE_DIR}/Source/Tools/PackageTool
  50. CMAKE_ARGS -D URHO3D_DEPLOYMENT_TARGET=generic -D DEST_RUNTIME_DIR=${CMAKE_BINARY_DIR}/bin/tool -D BAKED_CMAKE_SOURCE_DIR=${CMAKE_SOURCE_DIR} -D BAKED_CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR} -D CMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
  51. ${ALTERNATE_COMMAND})
  52. add_make_clean_files (${CMAKE_BINARY_DIR}/bin/tool/PackageTool)
  53. if (CMAKE_HOST_WIN32 AND NOT HAS_MKLINK)
  54. add_dependencies (PackageTool Urho3D) # Ensure Urho3D headers are fresh when building PackageTool externally on Windows host system without MKLINK
  55. endif ()
  56. install (PROGRAMS ${CMAKE_BINARY_DIR}/bin/tool/PackageTool DESTINATION ${DEST_RUNTIME_DIR}/tool)
  57. endif ()
  58. if (URHO3D_GENERATEBINDINGS)
  59. ExternalProject_Add (BindingGenerator
  60. SOURCE_DIR ${CMAKE_SOURCE_DIR}/Source/Tools/BindingGenerator
  61. CMAKE_ARGS -D URHO3D_DEPLOYMENT_TARGET=generic -D DEST_RUNTIME_DIR=${CMAKE_BINARY_DIR}/bin/tool -D BAKED_CMAKE_SOURCE_DIR=${CMAKE_SOURCE_DIR} -D BAKED_CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR} -D CMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
  62. ${ALTERNATE_COMMAND})
  63. add_make_clean_files (${CMAKE_BINARY_DIR}/bin/tool/BindingGenerator)
  64. if (CMAKE_HOST_WIN32 AND NOT HAS_MKLINK)
  65. add_dependencies (BindingGenerator Urho3D)
  66. endif ()
  67. install (PROGRAMS ${CMAKE_BINARY_DIR}/bin/tool/BindingGenerator DESTINATION ${DEST_RUNTIME_DIR}/tool)
  68. endif ()
  69. endif ()
  70. if (URHO3D_TOOLS)
  71. # Urho3D tools
  72. add_subdirectory (AssetImporter)
  73. add_subdirectory (OgreImporter)
  74. add_subdirectory (PackageTool)
  75. add_subdirectory (RampGenerator)
  76. add_subdirectory (SpritePacker)
  77. if (URHO3D_ANGELSCRIPT)
  78. add_subdirectory (ScriptCompiler)
  79. endif ()
  80. elseif (NOT CMAKE_CROSSCOMPILING AND URHO3D_PACKAGING)
  81. # PackageTool target is required but we are not cross-compiling, so build it as per normal
  82. add_subdirectory (PackageTool)
  83. endif ()
  84. if (NOT CMAKE_CROSSCOMPILING AND URHO3D_GENERATEBINDINGS)
  85. add_subdirectory (BindingGenerator)
  86. endif ()