mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 02:08:27 +08:00
@@ -704,3 +704,22 @@ the next rules to make device + simulator configuration work:
|
||||
|
||||
- Use :command:`find_package` only for libraries installed with
|
||||
:variable:`CMAKE_IOS_INSTALL_COMBINED` feature
|
||||
|
||||
.. _`Cross Compiling for Emscripten`:
|
||||
|
||||
Cross Compiling for Emscripten
|
||||
------------------------------
|
||||
|
||||
.. versionadded:: 4.2
|
||||
|
||||
A toolchain file may configure cross-compiling for `Emscripten`_ by
|
||||
setting the :variable:`CMAKE_SYSTEM_NAME` variable to ``Emscripten``.
|
||||
For example, a toolchain file might contain:
|
||||
|
||||
.. code-block:: cmake
|
||||
|
||||
set(CMAKE_SYSTEM_NAME Emscripten)
|
||||
set(CMAKE_C_COMPILER /path/to/emcc)
|
||||
set(CMAKE_CXX_COMPILER /path/to/em++)
|
||||
|
||||
.. _`Emscripten`: https://emscripten.org/
|
||||
|
5
Help/release/dev/emscripten-platform.rst
Normal file
5
Help/release/dev/emscripten-platform.rst
Normal file
@@ -0,0 +1,5 @@
|
||||
emscripten-platform
|
||||
-------------------
|
||||
|
||||
* CMake now supports :ref:`Cross Compiling for Emscripten` with simple
|
||||
toolchain files.
|
@@ -219,6 +219,11 @@ else()
|
||||
list(PREPEND _CMAKE_LINKER_NAMES "armlink")
|
||||
endif()
|
||||
|
||||
if(EMSCRIPTEN)
|
||||
list(PREPEND _CMAKE_AR_NAMES "emar")
|
||||
list(PREPEND _CMAKE_RANLIB_NAMES "emranlib")
|
||||
endif()
|
||||
|
||||
list(APPEND _CMAKE_TOOL_VARS AR RANLIB STRIP LINKER NM OBJDUMP OBJCOPY READELF DLLTOOL ADDR2LINE TAPI)
|
||||
endif()
|
||||
|
||||
|
3
Modules/Platform/Emscripten-Clang-C.cmake
Normal file
3
Modules/Platform/Emscripten-Clang-C.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
include(Platform/Emscripten-Clang)
|
||||
|
||||
__emscripten_clang(C)
|
3
Modules/Platform/Emscripten-Clang-CXX.cmake
Normal file
3
Modules/Platform/Emscripten-Clang-CXX.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
include(Platform/Emscripten-Clang)
|
||||
|
||||
__emscripten_clang(CXX)
|
17
Modules/Platform/Emscripten-Clang.cmake
Normal file
17
Modules/Platform/Emscripten-Clang.cmake
Normal file
@@ -0,0 +1,17 @@
|
||||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
# file LICENSE.rst or https://cmake.org/licensing for details.
|
||||
|
||||
include_guard()
|
||||
|
||||
macro(__emscripten_clang lang)
|
||||
set(CMAKE_SHARED_LIBRARY_SONAME_${lang}_FLAG "-Wl,-soname,")
|
||||
set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-sSIDE_MODULE")
|
||||
|
||||
set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_LIBRARIES 1)
|
||||
set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_OBJECTS 1)
|
||||
set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_INCLUDES 1)
|
||||
set(CMAKE_${lang}_COMPILE_OBJECT
|
||||
"<CMAKE_${lang}_COMPILER> -c <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -fPIC")
|
||||
set(CMAKE_${lang}_LINK_EXECUTABLE
|
||||
"<CMAKE_${lang}_COMPILER> <FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -sMAIN_MODULE")
|
||||
endmacro()
|
2
Modules/Platform/Emscripten-Initialize.cmake
Normal file
2
Modules/Platform/Emscripten-Initialize.cmake
Normal file
@@ -0,0 +1,2 @@
|
||||
set(EMSCRIPTEN 1)
|
||||
set(UNIX 1)
|
6
Modules/Platform/Emscripten.cmake
Normal file
6
Modules/Platform/Emscripten.cmake
Normal file
@@ -0,0 +1,6 @@
|
||||
set(CMAKE_SHARED_LIBRARY_LINK_C_WITH_RUNTIME_PATH ON)
|
||||
|
||||
set(CMAKE_SHARED_LIBRARY_SUFFIX ".wasm")
|
||||
set(CMAKE_EXECUTABLE_SUFFIX ".js")
|
||||
|
||||
set(CMAKE_DL_LIBS "")
|
4
Modules/Platform/Linker/Emscripten-C.cmake
Normal file
4
Modules/Platform/Linker/Emscripten-C.cmake
Normal file
@@ -0,0 +1,4 @@
|
||||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
# file LICENSE.rst or https://cmake.org/licensing for details.
|
||||
|
||||
include(Platform/Linker/Emscripten-LLD-C)
|
4
Modules/Platform/Linker/Emscripten-CXX.cmake
Normal file
4
Modules/Platform/Linker/Emscripten-CXX.cmake
Normal file
@@ -0,0 +1,4 @@
|
||||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
# file LICENSE.rst or https://cmake.org/licensing for details.
|
||||
|
||||
include(Platform/Linker/Emscripten-LLD-CXX)
|
6
Modules/Platform/Linker/Emscripten-LLD-C.cmake
Normal file
6
Modules/Platform/Linker/Emscripten-LLD-C.cmake
Normal file
@@ -0,0 +1,6 @@
|
||||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
# file LICENSE.rst or https://cmake.org/licensing for details.
|
||||
|
||||
include(Platform/Linker/Emscripten-LLD)
|
||||
|
||||
__emscripten_linker_lld(C)
|
6
Modules/Platform/Linker/Emscripten-LLD-CXX.cmake
Normal file
6
Modules/Platform/Linker/Emscripten-LLD-CXX.cmake
Normal file
@@ -0,0 +1,6 @@
|
||||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
# file LICENSE.rst or https://cmake.org/licensing for details.
|
||||
|
||||
include(Platform/Linker/Emscripten-LLD)
|
||||
|
||||
__emscripten_linker_lld(CXX)
|
11
Modules/Platform/Linker/Emscripten-LLD.cmake
Normal file
11
Modules/Platform/Linker/Emscripten-LLD.cmake
Normal file
@@ -0,0 +1,11 @@
|
||||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
# file LICENSE.rst or https://cmake.org/licensing for details.
|
||||
|
||||
# This module is shared by multiple languages; use include blocker.
|
||||
include_guard()
|
||||
|
||||
macro(__emscripten_linker_lld lang)
|
||||
set(CMAKE_${lang}_LINK_LIBRARY_USING_WHOLE_ARCHIVE "-Wl,--whole-archive" "<LINK_ITEM>" "-Wl,--no-whole-archive")
|
||||
set(CMAKE_${lang}_LINK_LIBRARY_USING_WHOLE_ARCHIVE_SUPPORTED TRUE)
|
||||
set(CMAKE_${lang}_LINK_LIBRARY_WHOLE_ARCHIVE_ATTRIBUTES LIBRARY_TYPE=STATIC DEDUPLICATION=YES OVERRIDE=DEFAULT)
|
||||
endmacro()
|
@@ -1386,6 +1386,14 @@ void cmCoreTryCompile::FindOutputFile(std::string const& targetName)
|
||||
return;
|
||||
}
|
||||
|
||||
if (cmHasLiteralSuffix(outputFileLocation, ".js")) {
|
||||
std::string wasmOutputLocation = cmStrCat(
|
||||
outputFileLocation.substr(0, outputFileLocation.length() - 3), ".wasm");
|
||||
if (cmSystemTools::FileExists(wasmOutputLocation)) {
|
||||
outputFileLocation = wasmOutputLocation;
|
||||
}
|
||||
}
|
||||
|
||||
this->OutputFile = cmSystemTools::CollapseFullPath(outputFileLocation);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user