Explorar el Código

Only perform ccache configuration during initial project configuration.
Determine the Emscripten's emcc version and use it to determine whether ccache could be enabled without caveat.
The changes for adding new '--use-metadata' option for Emscripten' file-packager.py has just been submitted to Emscripten upstream as PR (https://github.com/kripken/emscripten/pull/3410) today. Not sure how long it will take to be reviewed and merged (if at all). Tentatively assume it will be in incoming 1.31.4. With the immutable jsoutput file, the linker does not retriggered unnecessarily after changing the resource dirs content.

Yao Wei Tjong 姚伟忠 hace 10 años
padre
commit
f9060b7831

+ 14 - 5
CMake/Modules/Urho3D-CMake-common.cmake

@@ -463,10 +463,16 @@ else ()
         endif ()
         if (EMSCRIPTEN)
             # Emscripten-specific setup
-            set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-warn-absolute-paths -Wno-unknown-warning-option")
-            # Temporarily add the C++ standard explicitly because currently Emscripten does not consistently add the standard in its internall processing
-            # and this may cause compilation problem when precompiled header is involved (See https://github.com/kripken/emscripten/issues/3365 for more detail)
-            set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-warn-absolute-paths -Wno-unknown-warning-option -std=c++03")
+            # Prior to version 1.31.4 emcc does not consistently add the cpp standard and remove Emscripten-specific compiler flags
+            # before passing on the work to the underlying LLVM/Clang compiler, this has resulted in preprocessing error when enabling the PCH and ccache
+            # (See https://github.com/kripken/emscripten/issues/3365 for more detail)
+            if (EMCC_VERSION VERSION_LESS 1.31.4)
+                set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-warn-absolute-paths -Wno-unknown-warning-option")
+                set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-warn-absolute-paths -Wno-unknown-warning-option -std=c++03")
+            else ()
+                set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-warn-absolute-paths")
+                set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-warn-absolute-paths")
+            endif ()
             set (CMAKE_C_FLAGS_RELEASE "-Oz -DNDEBUG")
             set (CMAKE_CXX_FLAGS_RELEASE "-Oz -DNDEBUG")
             if (DEFINED ENV{CI})
@@ -1107,8 +1113,11 @@ macro (setup_main_executable)
             get_filename_component (NAME ${FILE} NAME)
             list (APPEND PAK_NAMES ${NAME})
         endforeach ()
+        if (CMAKE_BUILD_TYPE STREQUAL Debug AND NOT EMCC_VERSION VERSION_LESS 1.31.4)
+            set (USE_METADATA --use-metadata)
+        endif ()
         add_custom_command (OUTPUT ${SHARED_RESOURCE_JS}.data
-            COMMAND ${EMPACKAGER} ${SHARED_RESOURCE_JS}.data --preload ${PAK_NAMES} --js-output=${SHARED_RESOURCE_JS} --use-preload-cache
+            COMMAND ${EMPACKAGER} ${SHARED_RESOURCE_JS}.data --preload ${PAK_NAMES} --js-output=${SHARED_RESOURCE_JS} --use-preload-cache ${USE_METADATA}
             DEPENDS RESOURCE_CHECK ${RESOURCE_PAKS}
             WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
             COMMENT "Generating shared data file")

+ 7 - 4
CMake/Toolchains/emscripten.toolchain.cmake

@@ -42,14 +42,17 @@ if (NOT EXISTS ${EMSCRIPTEN_ROOT_PATH}/emcc)
     message (FATAL_ERROR "Could not find Emscripten cross compilation tool. "
         "Use EMSCRIPTEN_ROOT_PATH environment variable or build option to specify the location of the toolchain.")
 endif ()
+if (NOT EMCC_VERSION AND NOT CMAKE_HOST_WIN32)
+    execute_process (COMMAND ${EMSCRIPTEN_ROOT_PATH}/emcc --version COMMAND grep -oP \\d+\\.\\d+\\.\\d+ RESULT_VARIABLE EXIT_CODE OUTPUT_VARIABLE EMCC_VERSION ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
+    set (EMCC_VERSION ${EMCC_VERSION} CACHE STRING "emcc version on Unix-alike host system")
+endif ()
 if (CMAKE_HOST_WIN32)
     set (TOOL_EXT .bat)
 endif ()
 set (COMPILER_PATH ${EMSCRIPTEN_ROOT_PATH})
-# For now enable ccache support only when the CCACHE_CPP2 env var is also set to 1, until Emscripten has fixed https://github.com/kripken/emscripten/issues/3365
-# This ccache's option tells ccache to fallback to use original input source file instead of preprocessed source file which Emscripten does not support currently
-# TODO: Remove this temporary workaround once Emscripten incoming has been pushed to master in its next release
-if ("$ENV{USE_CCACHE}" AND NOT CMAKE_HOST_WIN32 AND ("$ENV{CCACHE_CPP2}" OR EMSCRIPTEN_ROOT_PATH MATCHES /incoming$))
+# ccache support could only be enabled for emcc prior to 1.31.4 when the CCACHE_CPP2 env var is also set to 1, newer emcc version could enable ccache support without this caveat (see https://github.com/kripken/emscripten/issues/3365 for more detail)
+# The CCACHE_CPP2 env var tells ccache to fallback to use original input source file instead of preprocessed one when passing on the compilation task to the compiler proper
+if (NOT CMAKE_C_COMPILER AND "$ENV{USE_CCACHE}" AND NOT CMAKE_HOST_WIN32 AND ("$ENV{CCACHE_CPP2}" OR NOT EMCC_VERSION VERSION_LESS 1.31.4))
     if (NOT $ENV{PATH} MATCHES ${EMSCRIPTEN_ROOT_PATH})
         message (FATAL_ERROR "The bin directory containing the compiler toolchain (${EMSCRIPTEN_ROOT_PATH}) has not been added in the PATH environment variable. "
             "This is required to enable ccache support for Emscripten compiler toolchain.")

+ 1 - 1
CMake/Toolchains/mingw.toolchain.cmake

@@ -41,7 +41,7 @@ if (NOT EXISTS ${MINGW_PREFIX}-gcc)
         "Use MINGW_PREFIX environment variable or build option to specify the location of the toolchain.")
 endif ()
 set (COMPILER_PREFIX ${MINGW_PREFIX})
-if ($ENV{USE_CCACHE})
+if (NOT CMAKE_C_COMPILER AND "$ENV{USE_CCACHE}")
     get_filename_component (NAME ${MINGW_PREFIX} NAME)
     execute_process (COMMAND whereis -b ccache COMMAND grep -o \\S*lib\\S* RESULT_VARIABLE EXIT_CODE OUTPUT_VARIABLE CCACHE_SYMLINK ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
     if (EXIT_CODE EQUAL 0 AND EXISTS ${CCACHE_SYMLINK}/${NAME}-gcc AND EXISTS ${CCACHE_SYMLINK}/${NAME}-g++)

+ 1 - 1
CMake/Toolchains/raspberrypi.toolchain.cmake

@@ -41,7 +41,7 @@ if (NOT EXISTS ${RPI_PREFIX}-gcc)
         "Use RPI_PREFIX environment variable or build option to specify the location of the toolchain.")
 endif ()
 set (COMPILER_PREFIX ${RPI_PREFIX})
-if ($ENV{USE_CCACHE})
+if (NOT CMAKE_C_COMPILER AND "$ENV{USE_CCACHE}")
     get_filename_component (NAME ${RPI_PREFIX} NAME)
     execute_process (COMMAND whereis -b ccache COMMAND grep -o \\S*lib\\S* RESULT_VARIABLE EXIT_CODE OUTPUT_VARIABLE CCACHE_SYMLINK ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
     if (EXIT_CODE EQUAL 0 AND EXISTS ${CCACHE_SYMLINK}/${NAME}-gcc AND EXISTS ${CCACHE_SYMLINK}/${NAME}-g++)