emscripten.toolchain.cmake 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #
  2. # Copyright (c) 2008-2015 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. # Based on cmake/Modules/Platform/Emscripten.cmake from https://github.com/kripken/emscripten
  23. cmake_minimum_required (VERSION 2.6.3)
  24. if (CMAKE_TOOLCHAIN_FILE)
  25. # Reference toolchain variable to suppress "unused variable" warning
  26. mark_as_advanced (CMAKE_TOOLCHAIN_FILE)
  27. endif ()
  28. # this one is important
  29. set (CMAKE_SYSTEM_NAME Linux)
  30. # this one not so much
  31. set (CMAKE_SYSTEM_VERSION 1)
  32. # specify the cross compiler
  33. if (NOT EMSCRIPTEN_ROOT_PATH AND DEFINED ENV{EMSCRIPTEN})
  34. file (TO_CMAKE_PATH $ENV{EMSCRIPTEN} EMSCRIPTEN_ROOT_PATH)
  35. endif ()
  36. if (NOT EXISTS ${EMSCRIPTEN_ROOT_PATH}/emcc)
  37. message (FATAL_ERROR "Could not find Emscripten cross compilation tool. "
  38. "Use EMSCRIPTEN_ROOT_PATH environment variable or build option to specify the location of the toolchain.")
  39. endif ()
  40. if (CMAKE_HOST_WIN32)
  41. set (TOOL_EXT .bat)
  42. endif ()
  43. set (CMAKE_C_COMPILER ${EMSCRIPTEN_ROOT_PATH}/emcc${TOOL_EXT} CACHE PATH "C compiler")
  44. set (CMAKE_CXX_COMPILER ${EMSCRIPTEN_ROOT_PATH}/em++${TOOL_EXT} CACHE PATH "C++ compiler")
  45. set (CMAKE_AR ${EMSCRIPTEN_ROOT_PATH}/emar${TOOL_EXT} CACHE PATH "archive")
  46. set (CMAKE_RANLIB ${EMSCRIPTEN_ROOT_PATH}/emranlib${TOOL_EXT} CACHE PATH "ranlib")
  47. # specify the system root
  48. if (NOT EMSCRIPTEN_SYSROOT)
  49. if (DEFINED ENV{EMSCRIPTEN_SYSROOT})
  50. file (TO_CMAKE_PATH $ENV{EMSCRIPTEN_SYSROOT} EMSCRIPTEN_SYSROOT)
  51. else ()
  52. set (EMSCRIPTEN_SYSROOT ${EMSCRIPTEN_ROOT_PATH}/system)
  53. endif ()
  54. if (NOT EXISTS ${EMSCRIPTEN_SYSROOT})
  55. message (FATAL_ERROR "Could not find Emscripten system root. "
  56. "Use EMSCRIPTEN_SYSROOT environment variable or build option to specify the location of system root.")
  57. endif ()
  58. set (EMSCRIPTEN_ROOT_PATH ${EMSCRIPTEN_ROOT_PATH} CACHE STRING "Root path to Emscripten cross-compiler tools (Emscripten cross-compiling build only)" FORCE)
  59. set (EMSCRIPTEN_SYSROOT ${EMSCRIPTEN_SYSROOT} CACHE PATH "Path to Emscripten system root (Emscripten cross-compiling build only)" FORCE)
  60. endif ()
  61. set (CMAKE_FIND_ROOT_PATH ${EMSCRIPTEN_SYSROOT})
  62. # only search libraries, and headers in the target directories
  63. set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  64. set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  65. set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  66. # Don't do compiler autodetection, since we are cross-compiling.
  67. include (CMakeForceCompiler)
  68. CMAKE_FORCE_C_COMPILER ("${CMAKE_C_COMPILER}" Clang)
  69. CMAKE_FORCE_CXX_COMPILER ("${CMAKE_CXX_COMPILER}" Clang)
  70. # Hardwire support for cmake-2.8/Modules/CMakeBackwardsCompatibilityC.cmake without having CMake to try complex things
  71. # to autodetect these:
  72. set (CMAKE_SKIP_COMPATIBILITY_TESTS 1)
  73. set (CMAKE_SIZEOF_CHAR 1)
  74. set (CMAKE_SIZEOF_UNSIGNED_SHORT 2)
  75. set (CMAKE_SIZEOF_SHORT 2)
  76. set (CMAKE_SIZEOF_INT 4)
  77. set (CMAKE_SIZEOF_UNSIGNED_LONG 4)
  78. set (CMAKE_SIZEOF_UNSIGNED_INT 4)
  79. set (CMAKE_SIZEOF_LONG 4)
  80. set (CMAKE_SIZEOF_VOID_P 4)
  81. set (CMAKE_SIZEOF_FLOAT 4)
  82. set (CMAKE_SIZEOF_DOUBLE 8)
  83. set (CMAKE_C_SIZEOF_DATA_PTR 4)
  84. set (CMAKE_CXX_SIZEOF_DATA_PTR 4)
  85. set (CMAKE_HAVE_LIMITS_H 1)
  86. set (CMAKE_HAVE_UNISTD_H 1)
  87. set (CMAKE_HAVE_PTHREAD_H 1)
  88. set (CMAKE_HAVE_SYS_PRCTL_H 1)
  89. set (CMAKE_WORDS_BIGENDIAN 0)
  90. set (CMAKE_DL_LIBS)
  91. # In order for check_function_exists() detection to work, we must signal it to pass an additional flag, which causes the compilation
  92. # to abort if linking results in any undefined symbols. The CMake detection mechanism depends on the undefined symbol error to be raised.
  93. set (CMAKE_REQUIRED_FLAGS "-s ERROR_ON_UNDEFINED_SYMBOLS=1")
  94. # Use response files on Windows host
  95. if (CMAKE_HOST_WIN32)
  96. foreach (lang C CXX)
  97. foreach (cat LIBRARIES OBJECTS INCLUDES)
  98. set (CMAKE_${lang}_USE_RESPONSE_FILE_FOR_${cat} 1)
  99. endforeach ()
  100. set (CMAKE_${lang}_CREATE_STATIC_LIBRARY "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS>")
  101. endforeach ()
  102. endif ()
  103. set (EMSCRIPTEN 1)