فهرست منبع

Use "SmileyHack" to inject CMake vars to get the right output suffix.
This fixes known issues with output binary suffix in the custom emscripten.toolchain.cmake and FindUrho3D.cmake modules.

Yao Wei Tjong 姚伟忠 9 سال پیش
والد
کامیت
f7e2303cab
3فایلهای تغییر یافته به همراه8 افزوده شده و 10 حذف شده
  1. 1 0
      CMake/Modules/FindUrho3D.cmake
  2. 0 4
      CMake/Modules/UrhoCommon.cmake
  3. 7 6
      CMake/Toolchains/emscripten.toolchain.cmake

+ 1 - 0
CMake/Modules/FindUrho3D.cmake

@@ -236,6 +236,7 @@ else ()
                 endif ()
                 endif ()
             endif ()
             endif ()
             set (COMPILER_FLAGS "${COMPILER_32BIT_FLAG} ${CMAKE_REQUIRED_FLAGS}")
             set (COMPILER_FLAGS "${COMPILER_32BIT_FLAG} ${CMAKE_REQUIRED_FLAGS}")
+            string (REPLACE .js ";" COMPILER_FLAGS "${COMPILER_FLAGS}")     # Emscripten-specific - revise SmileyHack to inject empty suffix to keep try_compile() happy
             # FIXME: For yet an unknown reason, CMake seems to fail to setup the sysroot as expected here, so we have to set it manually
             # FIXME: For yet an unknown reason, CMake seems to fail to setup the sysroot as expected here, so we have to set it manually
             if (ANDROID)
             if (ANDROID)
                 set (COMPILER_FLAGS "${COMPILER_FLAGS} --sysroot=\"${CMAKE_SYSROOT}\"")
                 set (COMPILER_FLAGS "${COMPILER_FLAGS} --sysroot=\"${CMAKE_SYSROOT}\"")

+ 0 - 4
CMake/Modules/UrhoCommon.cmake

@@ -627,10 +627,6 @@ else ()
                 endif ()
                 endif ()
                 set (CMAKE_C_FLAGS_RELEASE "-Oz -DNDEBUG")
                 set (CMAKE_C_FLAGS_RELEASE "-Oz -DNDEBUG")
                 set (CMAKE_CXX_FLAGS_RELEASE "-Oz -DNDEBUG")
                 set (CMAKE_CXX_FLAGS_RELEASE "-Oz -DNDEBUG")
-                # CMake does not treat Emscripten as a valid platform yet, certain platform-specific variables cannot be set in the
-                # toolchain file as they get overwritten by CMake internally as per Linux platform default, so set them here for now
-                set (CMAKE_EXECUTABLE_SUFFIX_C .html)
-                set (CMAKE_EXECUTABLE_SUFFIX_CXX .html)
                 # Linker flags
                 # Linker flags
                 if (EMSCRIPTEN_ALLOW_MEMORY_GROWTH)
                 if (EMSCRIPTEN_ALLOW_MEMORY_GROWTH)
                     set (MEMORY_LINKER_FLAGS "-s ALLOW_MEMORY_GROWTH=1")
                     set (MEMORY_LINKER_FLAGS "-s ALLOW_MEMORY_GROWTH=1")

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

@@ -138,14 +138,15 @@ foreach (LANG C CXX)
     # The ABI info could not be checked as per normal as CMake does not understand the test build output from Emscripten, so bypass it also
     # The ABI info could not be checked as per normal as CMake does not understand the test build output from Emscripten, so bypass it also
     set (CMAKE_${LANG}_ABI_COMPILED TRUE)
     set (CMAKE_${LANG}_ABI_COMPILED TRUE)
     set (CMAKE_${LANG}_SIZEOF_DATA_PTR 4)   # Assume it is always 32-bit for now (we could have used our CheckCompilerToolChains.cmake module here)
     set (CMAKE_${LANG}_SIZEOF_DATA_PTR 4)   # Assume it is always 32-bit for now (we could have used our CheckCompilerToolChains.cmake module here)
-    # There could be a bug in CMake itself where setting CMAKE_EXECUTABLE_SUFFIX variable outside of the scope, where it processes the platform configuration files, does not being honored by try_compile() command and as a result all the check macros that depend on try_compile() do not work properly when the CMAKE_EXECUTABLE_SUFFIX variable is only being set later further down the road; At least one of the CMake devs has the opinion that this is the intended behavior but it is an unconvincing explanation because setting CMAKE_EXECUTABLE_SUFFIX variable later does have the desired effect everywhere else EXCEPT the try_compile() command
-    # We are forced to set CMAKE_EXECUTABLE_SUFFIX_C and CMAKE_EXECUTABLE_SUFFIX_CXX here as a workaround; we could not just set CMAKE_EXECUTABLE_SUFFIX directly because CMake processes platform configuration files after the toolchain file and since we tell CMake that we are cross-compiling for 'Linux' platform via CMAKE_SYSTEM_NAME variable, CMake initializes the CMAKE_EXECUTABLE_SUFFIX to empty string (as expected for Linux platform); the workaround avoids our setting from being overwritten by platform configuration files by using the C and CXX language variants of the variable
-    # The executable suffix needs to be .js for the below Emscripten-specific compiler setting to be effective
-    set (CMAKE_EXECUTABLE_SUFFIX_${LANG} .js)
+    # We could not set CMAKE_EXECUTABLE_SUFFIX directly because CMake processes platform configuration files after the toolchain file and since we tell CMake that we are cross-compiling for 'Linux' platform (Emscripten is not a valid platform yet in CMake) via CMAKE_SYSTEM_NAME variable, as such CMake force initializes the CMAKE_EXECUTABLE_SUFFIX to empty string (as expected for Linux platform); To workaround it we have to use CMAKE_EXECUTABLE_SUFFIX_C and CMAKE_EXECUTABLE_SUFFIX_CXX instead, which are fortunately not being touched by platform configuration files
+    if (NOT DEFINED CMAKE_EXECUTABLE_SUFFIX_${LANG})
+        set (CMAKE_EXECUTABLE_SUFFIX_${LANG} .html)
+    endif ()
 endforeach ()
 endforeach ()
 
 
-# Set required compiler flags for internal CMake various check_xxx() macros which rely on the error to occur for the check to be performed correctly
-set (CMAKE_REQUIRED_FLAGS "-s ERROR_ON_UNDEFINED_SYMBOLS=1")
+# Set required compiler flags for various internal CMake checks which rely on the compiler/linker error to be occured for the check to be performed correctly
+# The executable suffix needs to be .js for the below Emscripten-specific compiler setting to be effective
+set (CMAKE_REQUIRED_FLAGS "-s ERROR_ON_UNDEFINED_SYMBOLS=1;-DSmileyHack=byYaoWT;-DCMAKE_EXECUTABLE_SUFFIX_C=.js;-DCMAKE_EXECUTABLE_SUFFIX_CXX=.js")
 
 
 # Use response files on Windows host
 # Use response files on Windows host
 if (CMAKE_HOST_WIN32)
 if (CMAKE_HOST_WIN32)