Browse Source

Minor refactor on CheckCompilerToolchain module.

Yao Wei Tjong 姚伟忠 9 years ago
parent
commit
f1ac8a80e9

+ 66 - 115
CMake/Modules/CheckCompilerToolchain.cmake

@@ -29,11 +29,9 @@
 #  ARM
 #  MIPS
 #  POWERPC
+#  WEB
 #  X86
 #
-# Compiler version in major.minor.patch format, except MSVC where it follows its own format:
-#  COMPILER_VERSION
-#
 # CPU SIMD instruction extensions support for x86/x86_64 archs:
 #  HAVE_MMX
 #  HAVE_3DNOW
@@ -56,9 +54,10 @@ if (EMSCRIPTEN AND CMAKE_HOST_WIN32)
     execute_process (COMMAND ${CMAKE_COMMAND} -E touch ${NULL_DEVICE${EMCC_FIX}})
 endif ()
 
+# Macro for checking if a predefined macro is emitted by the chosen compiler toolchain natively
 macro (check_native_define REGEX OUTPUT_VAR)
-    if (NOT DEFINED CCT_${OUTPUT_VAR})
-        string (REGEX MATCH "#define +${REGEX} +([^;]+)" matched "${CCT_NATIVE_PREDEFINED_MACROS}")
+    if (INVALIDATE_CCT OR NOT DEFINED ${OUTPUT_VAR})
+        string (REGEX MATCH "#define +${REGEX} +([^;]+)" matched "${NATIVE_PREDEFINED_MACROS}")
         if (matched)
             string (REGEX MATCH "\\(.*\\)" captured "${REGEX}")
             if (captured)
@@ -71,15 +70,15 @@ macro (check_native_define REGEX OUTPUT_VAR)
         else ()
             set (${OUTPUT_VAR} 0)
         endif ()
-        set (CCT_${OUTPUT_VAR} ${${OUTPUT_VAR}} CACHE INTERNAL "Compiler toolchain has predefined macros matching ${REGEX}")
+        set (${OUTPUT_VAR} ${${OUTPUT_VAR}} CACHE INTERNAL "Compiler toolchain has predefined macros matching ${REGEX}")
     endif ()
-    set (${OUTPUT_VAR} ${CCT_${OUTPUT_VAR}})
 endmacro ()
 
+# Macro for checking if a CPU instruction extension is supported by the chosen compiler toolchain
 macro (check_extension EXTENSION)
     string (TOUPPER "${EXTENSION}" UCASE_EXT_NAME)   # Stringify to guard against empty variable
     string (REGEX REPLACE [^=]+= "" UCASE_EXT_NAME "${UCASE_EXT_NAME}")
-    if (NOT DEFINED CCT_HAVE_${UCASE_EXT_NAME})
+    if (INVALIDATE_CCT OR NOT DEFINED HAVE_${UCASE_EXT_NAME})
         execute_process (COMMAND ${CMAKE_C_COMPILER} ${ARCH_FLAGS} -m${EXTENSION} -E -dM -xc ${NULL_DEVICE${EMCC_FIX}} RESULT_VARIABLE CC_EXIT_STATUS OUTPUT_VARIABLE PREDEFINED_MACROS ERROR_QUIET)
         if (NOT CC_EXIT_STATUS EQUAL 0)
             message (FATAL_ERROR "Could not check compiler toolchain CPU instruction extension as it does not handle '-E -dM' compiler flags correctly")
@@ -89,22 +88,21 @@ macro (check_extension EXTENSION)
         else ()
             set (EXPECTED_MACRO __${UCASE_EXT_NAME}__)
         endif ()
-        string (REGEX MATCH "#define +${EXPECTED_MACRO} +1" matched "${PREDEFINED_MACROS}")
-        if (matched)
+        if (PREDEFINED_MACROS MATCHES "#define +${EXPECTED_MACRO} +1")
             set (matched 1)
         else ()
             set (matched 0)
         endif ()
-        set (CCT_HAVE_${UCASE_EXT_NAME} ${matched} CACHE INTERNAL "Compiler toolchain supports ${UCASE_EXT_NAME} CPU instruction extension")
+        set (HAVE_${UCASE_EXT_NAME} ${matched} CACHE INTERNAL "Compiler toolchain supports ${UCASE_EXT_NAME} CPU instruction extension")
     endif ()
-    set (HAVE_${UCASE_EXT_NAME} ${CCT_HAVE_${UCASE_EXT_NAME}})
 endmacro ()
 
+# Macro for checking if a C++ feature is enabled by the configured CXX compiler flags
 macro (check_feature_enabled FEATURE)
-    if (NOT DEFINED CCT_${FEATURE})
+    if (INVALIDATE_CCT OR NOT DEFINED ${FEATURE})
         set (COMPILER_FLAGS ${CMAKE_CXX_FLAGS})
         separate_arguments (COMPILER_FLAGS)
-        execute_process (COMMAND ${CMAKE_CXX_COMPILER} ${COMPILER_FLAGS} -E -dM -xc++ ${NULL_DEVICE} RESULT_VARIABLE CXX_EXIT_STATUS OUTPUT_VARIABLE PREDEFINED_MACROS ERROR_QUIET)
+        execute_process (COMMAND ${CMAKE_CXX_COMPILER} ${COMPILER_FLAGS} -E -dM -xc++ ${NULL_DEVICE${EMCC_FIX}} RESULT_VARIABLE CXX_EXIT_STATUS OUTPUT_VARIABLE PREDEFINED_MACROS ERROR_QUIET)
         if (NOT CXX_EXIT_STATUS EQUAL 0)
             message (FATAL_ERROR "Could not check compiler toolchain CPU instruction extension as it does not handle '-E -dM' compiler flags correctly")
         endif ()
@@ -113,54 +111,59 @@ macro (check_feature_enabled FEATURE)
         else ()
             set (EXPECTED_MACRO __${FEATURE})
         endif ()
-        string (REGEX MATCH "#define +${EXPECTED_MACRO} +1" matched "${PREDEFINED_MACROS}")
-        if (matched)
+        if (PREDEFINED_MACROS MATCHES "#define +${EXPECTED_MACRO} +1")
             set (matched 1)
         else ()
             set (matched 0)
         endif ()
-        set (CCT_${FEATURE} ${matched} CACHE INTERNAL "Is ${FEATURE} enabled")
+        set (${FEATURE} ${matched} CACHE INTERNAL "Is ${FEATURE} enabled")
     endif ()
-    set (${FEATURE} ${CCT_${FEATURE}})
 endmacro ()
 
-if (INVALIDATE_CCT)
-    get_cmake_property (CACHE_VARIABLES CACHE_VARIABLES)
-    foreach (VAR ${CACHE_VARIABLES})
-        if (VAR MATCHES ^CCT_)
-            unset (${VAR} CACHE)
+# Macro for checking if a native compiler toolchain exists for building the host tool targets
+# This macro is designed to be used in cross-compiling build
+macro (check_native_compiler_exist)
+    if (NOT HAVE_NATIVE_COMPILER)
+        message (STATUS "Performing Test HAVE_NATIVE_COMPILER")
+        file (WRITE ${CMAKE_BINARY_DIR}/generated/CMakeLists.txt "message (\"Probing native compiler toolchain...\")\n")
+        execute_process (COMMAND ${CMAKE_COMMAND} -E env CC=${SAVED_CC} CXX=${SAVED_CXX} ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} .
+            WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/generated RESULT_VARIABLE EXIT_CODE ERROR_VARIABLE ERR_VAR OUTPUT_QUIET)
+        if (NOT EXIT_CODE EQUAL 0)
+            message (STATUS "Performing Test HAVE_NATIVE_COMPILER - Failed")
+            execute_process (COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_BINARY_DIR}/generated/CMakeCache.txt)
+            message (FATAL_ERROR "Could not find native compiler toolchain. This is usually caused by wrong PATH env-var value.\n${ERR_VAR}")
         endif ()
-    endforeach ()
-endif ()
-
-if (NOT MSVC AND NOT DEFINED CCT_NATIVE_PREDEFINED_MACROS)
-    if (IOS OR TVOS)
-        # Assume arm64 is the native arch (this does not prevent our build system to target armv7 later in universal binary build)
-        set (ARCH_FLAGS -arch arm64)
-    elseif (ANDROID AND CMAKE_CXX_COMPILER_ID MATCHES Clang)
-        # Use the same target flag as configured by Android/CMake toolchain file
-        string (REGEX REPLACE "^.*-target ([^ ]+).*$" "-target;\\1" ARCH_FLAGS "${CMAKE_CXX_FLAGS}")
-    endif ()
-    execute_process (COMMAND ${CMAKE_C_COMPILER} ${ARCH_FLAGS} -E -dM -xc ${NULL_DEVICE} RESULT_VARIABLE CC_EXIT_STATUS OUTPUT_VARIABLE CCT_NATIVE_PREDEFINED_MACROS ERROR_QUIET)
-    if (NOT CC_EXIT_STATUS EQUAL 0)
-        message (FATAL_ERROR "Could not check compiler toolchain as it does not handle '-E -dM' compiler flags correctly")
+        message (STATUS "Performing Test HAVE_NATIVE_COMPILER - Success")
+        set (HAVE_NATIVE_COMPILER 1 CACHE INTERNAL "Check native compiler exist")
     endif ()
-    string (REPLACE \n ";" CCT_NATIVE_PREDEFINED_MACROS "${CCT_NATIVE_PREDEFINED_MACROS}")    # Stringify for string replacement
-    set (CCT_NATIVE_PREDEFINED_MACROS ${CCT_NATIVE_PREDEFINED_MACROS} CACHE INTERNAL "Compiler toolchain native predefined macros")
-endif ()
+endmacro ()
 
 if (MSVC)
     # TODO: revisit this later because VS may use Clang as compiler in the future
     # On MSVC compiler, use the chosen CMake/VS generator to determine the ABI
     set (NATIVE_64BIT ${CMAKE_CL_64})
-    # We only support one target arch when using MSVC for now
-    set (X86 1)
-    # Determine MSVC compiler version based on CMake informational variables
-    set (COMPILER_VERSION ${MSVC_VERSION})
-    # Assume all C++ features are ON
-    set (RTTI 1)
-    set (EXCEPTIONS 1)
+    # We only support one target arch when using MSVC for now and make certain assumptions as per documentation instead of querying the compiler
+    foreach (VAR X86 HAVE_MMX HAVE_SSE HAVE_SSE2 RTTI EXCEPTIONS)
+        set (${VAR} 1)
+    endforeach ()
 else ()
+    # The 'invalidate event' will be sent by toolchain file when it reconfigures the cross-compiler or compiler flags
+    if (INVALIDATE_CCT OR NOT DEFINED NATIVE_PREDEFINED_MACROS)
+        if (IOS OR TVOS)
+            # Assume arm64 is the native arch (this does not prevent our build system to target armv7 later in universal binary build)
+            set (ARCH_FLAGS -arch arm64)
+        elseif (ANDROID AND CMAKE_CXX_COMPILER_ID MATCHES Clang)
+            # Use the same target flag as configured by Android/CMake toolchain file
+            string (REGEX REPLACE "^.*-target ([^ ]+).*$" "-target;\\1" ARCH_FLAGS "${CMAKE_CXX_FLAGS}")
+        endif ()
+        execute_process (COMMAND ${CMAKE_C_COMPILER} ${ARCH_FLAGS} -E -dM -xc ${NULL_DEVICE} RESULT_VARIABLE CC_EXIT_STATUS OUTPUT_VARIABLE NATIVE_PREDEFINED_MACROS ERROR_QUIET)
+        if (NOT CC_EXIT_STATUS EQUAL 0)
+            message (FATAL_ERROR "Could not check compiler toolchain as it does not handle '-E -dM' compiler flags correctly")
+        endif ()
+        string (REPLACE \n ";" NATIVE_PREDEFINED_MACROS "${NATIVE_PREDEFINED_MACROS}")    # Stringify for string replacement
+        set (NATIVE_PREDEFINED_MACROS ${NATIVE_PREDEFINED_MACROS} CACHE INTERNAL "Compiler toolchain native predefined macros")
+    endif ()
+
     # Determine the native ABI based on the size of pointer
     check_native_define (__SIZEOF_POINTER__ SIZEOF_POINTER)
     if (SIZEOF_POINTER EQUAL 8)
@@ -168,84 +171,32 @@ else ()
     endif ()
     # Android arm64 compiler only emits __aarch64__ while iOS arm64 emits __aarch64__, __arm64__, and __arm__; for armv7a all emit __arm__
     check_native_define ("__(arm|aarch64)__" ARM)
-    # Compiler should emit __x86_64__, __i686__, or __i386__, etc when targeting archs using Intel or AMD processors
-    check_native_define ("__(i.86|x86_64)__" X86)
     # For completeness sake as currently we do not support MIPS and PowerPC (yet)
-    check_native_define ("__MIPSEL__" MIPS)
+    check_native_define (__MIPSEL__ MIPS)
     check_native_define ("__(ppc|PPC|powerpc|POWERPC)(64)*__" POWERPC)
-    # GCC/Clang and all their derivatives should understand this command line option to get the compiler version
-    if (NOT DEFINED COMPILER_VERSION)
-        if (EMSCRIPTEN)
-            set (COMPILER_VERSION ${EMSCRIPTEN_EMCC_VERSION})
-        else ()
-            execute_process (COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE COMPILER_VERSION ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
-        endif ()
-        set (COMPILER_VERSION ${COMPILER_VERSION} CACHE INTERNAL "GCC/Clang Compiler version")
-    endif ()
-    check_feature_enabled (RTTI __GXX_RTTI)
-    check_feature_enabled (EXCEPTIONS)
-endif ()
-
-if (ARM)
-    if (MSVC)
-        message (FATAL_ERROR "This build system does not support ARM build using MSVC compiler toolchain yet. Contribution is welcome.")
-    else ()
+    # For now we only support Emscripten compiler toolchain when targeting Web platform
+    check_native_define (__EMSCRIPTEN__ WEB)
+    # Compiler should emit __x86_64__, __i686__, or __i386__, etc when targeting archs using Intel or AMD processors
+    check_native_define ("__(i.86|x86_64)__" X86)
+    if (ARM)
         check_feature_enabled (NEON __ARM_NEON)
         if (NEON)
+            # NEON is enabled by default on aarch64 arch so its compiler emits __ARM_NEON by default even though it does not support '-mfpu' compiler flag
             set (HAVE_NEON 1)
         else ()
             check_extension (fpu=neon __ARM_NEON)
         endif ()
-    endif ()
-else ()
-    if (MSVC)
-        # In our documentation we have already declared that we only support CPU with SSE2 extension on Windows platform, so we can safely hard-code these for MSVC compiler
-        foreach (VAR HAVE_MMX HAVE_SSE HAVE_SSE2)
-            set (${VAR} 1)
-        endforeach ()
-    else ()
-        if (MINGW AND COMPILER_VERSION VERSION_LESS 4.9.1)
-            if (NOT DEFINED URHO3D_SSE)     # Only give the warning once during initial configuration
-                # Certain MinGW versions fail to compile SSE code. This is the initial guess for known "bad" version range, and can be tightened later
-                message (WARNING "Disabling SSE by default due to MinGW version. It is recommended to upgrade to MinGW with GCC >= 4.9.1. You can also try to re-enable SSE with CMake option -DURHO3D_SSE=1, but this may result in compile errors.")
-            endif ()
-        elseif (NOT EMSCRIPTEN)     # Emscripten does not support SSE/SSE2 (yet) now but erroneously responding positively to our probe, so skip them for Emscripten for now
-            check_extension (sse)
-            check_extension (sse2)
-        endif ()
-        if (NOT APPLE AND NOT WIN32)    # Linux only
+    elseif (POWERPC)
+        check_extension (altivec)
+    elseif (X86)
+        check_extension (sse)
+        check_extension (sse2)
+        if (CMAKE_SYSTEM_NAME STREQUAL Linux)
             check_extension (mmx)
             check_extension (3dnow __3dNOW__)
         endif ()
     endif ()
-    # For completeness sake as currently we do not support PowerPC (yet)
-    if (POWERPC)
-        check_extension (altivec)
-    endif ()
+    # Check if C++ feature is being turned on/off in the configured compiler flags
+    check_feature_enabled (RTTI __GXX_RTTI)
+    check_feature_enabled (EXCEPTIONS)
 endif ()
-
-# Explicitly set the variable to 1 when it is defined and truthy or 0 when it is not defined or falsy
-foreach (VAR NATIVE_64BIT HAVE_MMX HAVE_3DNOW HAVE_SSE HAVE_SSE2 HAVE_ALTIVEC HAVE_NEON NEON)
-    if (${VAR})
-        set (${VAR} 1)
-    else ()
-        set (${VAR} 0)
-    endif ()
-endforeach ()
-
-# When cross-compiling, this macro ensures that a native compiler toolchain also exists for building the host tool targets
-macro (check_native_compiler_exist)
-    if (NOT HAVE_NATIVE_COMPILER)
-        message (STATUS "Performing Test HAVE_NATIVE_COMPILER")
-        file (WRITE ${CMAKE_BINARY_DIR}/generated/CMakeLists.txt "message (\"Probing native compiler toolchain...\")\n")
-        execute_process (COMMAND ${CMAKE_COMMAND} -E env CC=${SAVED_CC} CXX=${SAVED_CXX} ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} .
-            WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/generated RESULT_VARIABLE EXIT_CODE ERROR_VARIABLE ERR_VAR OUTPUT_QUIET)
-        if (NOT EXIT_CODE EQUAL 0)
-            message (STATUS "Performing Test HAVE_NATIVE_COMPILER - Failed")
-            execute_process (COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_BINARY_DIR}/generated/CMakeCache.txt)
-            message (FATAL_ERROR "Could not find native compiler toolchain. This is usually caused by wrong PATH env-var value.\n${ERR_VAR}")
-        endif ()
-        message (STATUS "Performing Test HAVE_NATIVE_COMPILER - Success")
-        set (HAVE_NATIVE_COMPILER 1 CACHE INTERNAL "Check native compiler exist")
-    endif ()
-endmacro ()

+ 4 - 4
CMake/Modules/FindUrho3D.cmake

@@ -169,10 +169,6 @@ else ()
     endif ()
     set (URHO3D_LIB_TYPE_SAVED ${URHO3D_LIB_TYPE})  # We need this to reset the auto-discovered URHO3D_LIB_TYPE variable before looping
     foreach (ABI_64BIT RANGE ${URHO3D_64BIT} 0)
-        # Break if the compiler is not multilib-capable and the ABI is not its native
-        if ((MSVC OR ANDROID OR ARM OR WEB) AND NOT ABI_64BIT EQUAL NATIVE_64BIT)
-            break ()
-        endif ()
         # Set to search in 'lib' or 'lib64' based on the ABI being tested
         set_property (GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ${ABI_64BIT})    # Leave this global property setting afterwards, do not restore it to its previous value
         find_library (URHO3D_LIBRARIES NAMES Urho3D ${URHO3D_LIB_SEARCH_HINT} PATH_SUFFIXES ${PATH_SUFFIX} ${SEARCH_OPT} DOC "Urho3D library directory")
@@ -282,6 +278,10 @@ else ()
                 unset (URHO3D_LIBRARIES CACHE)
             endif ()
         endif ()
+        # Break if the compiler is not multilib-capable
+        if (MSVC OR ANDROID OR ARM OR WEB)
+            break ()
+        endif ()
     endforeach ()
     # If both the non-debug and debug version of the libraries are found on Windows platform then use them both
     if (URHO3D_LIBRARIES_REL AND URHO3D_LIBRARIES_DBG)

+ 22 - 22
CMake/Modules/UrhoCommon.cmake

@@ -102,7 +102,7 @@ set (CMAKE_EXE_LINKER_FLAGS "${INDIRECT_DEPS_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKE
 include (CMakeDependentOption)
 option (URHO3D_C++11 "Enable C++11 standard")
 cmake_dependent_option (IOS "Setup build for iOS platform" FALSE "XCODE" FALSE)
-cmake_dependent_option (URHO3D_64BIT "Enable 64-bit build, the default is set based on the native ABI of the chosen compiler toolchain" ${NATIVE_64BIT} "NOT MSVC AND NOT ANDROID AND NOT (ARM AND NOT IOS) AND NOT WEB AND NOT POWERPC" ${NATIVE_64BIT})     # Intentionally only enable the option for iOS but not for tvOS as the latter is 64-bit only
+cmake_dependent_option (URHO3D_64BIT "Enable 64-bit build, the default is set based on the native ABI of the chosen compiler toolchain" "${NATIVE_64BIT}" "NOT MSVC AND NOT ANDROID AND NOT (ARM AND NOT IOS) AND NOT WEB AND NOT POWERPC" "${NATIVE_64BIT}")     # Intentionally only enable the option for iOS but not for tvOS as the latter is 64-bit only
 option (URHO3D_ANGELSCRIPT "Enable AngelScript scripting support" TRUE)
 option (URHO3D_LUA "Enable additional Lua scripting support" TRUE)
 option (URHO3D_NAVIGATION "Enable navigation support" TRUE)
@@ -126,41 +126,41 @@ if (RPI)
 endif ()
 if (CMAKE_PROJECT_NAME STREQUAL Urho3D)
     set (URHO3D_LIB_TYPE STATIC CACHE STRING "Specify Urho3D library type, possible values are STATIC (default) and SHARED")
-    # The URHO3D_OPENGL option is not available on non-Windows platforms as they should always use OpenGL, i.e. URHO3D_OPENGL variable will always be forced to TRUE
-    if (MSVC)
-        # On MSVC compiler, default to false (i.e. prefers Direct3D)
-        # OpenGL can be manually enabled with -DURHO3D_OPENGL=1, but Windows graphics card drivers are usually better optimized for Direct3D
-        set (DEFAULT_OPENGL FALSE)
-    else ()
-        # On non-MSVC compiler on Windows platform, default to true to enable use of OpenGL instead of Direct3D
-        # Direct3D can be manually enabled with -DURHO3D_OPENGL=0, but it is likely to fail unless the MinGW-w64 distribution is used due to dependency to Direct3D headers and libs
+    # Non-Windows platforms always use OpenGL, the URHO3D_OPENGL variable will always be forced to TRUE, i.e. it is not an option at all
+    # Windows platform has URHO3D_OPENGL as an option, MSVC compiler default to FALSE (i.e. prefers Direct3D) while MinGW compiler default to TRUE
+    if (MINGW)
         set (DEFAULT_OPENGL TRUE)
     endif ()
-    cmake_dependent_option (URHO3D_OPENGL "Use OpenGL instead of Direct3D (Windows platform only)" ${DEFAULT_OPENGL} "WIN32" TRUE)      # Force the variable to TRUE when not WIN32
+    cmake_dependent_option (URHO3D_OPENGL "Use OpenGL instead of Direct3D (Windows platform only)" "${DEFAULT_OPENGL}" WIN32 TRUE)
     # On Windows platform Direct3D11 can be optionally chosen
     # Using Direct3D11 on non-MSVC compiler may require copying and renaming Microsoft official libraries (.lib to .a), else link failures or non-functioning graphics may result
     cmake_dependent_option (URHO3D_D3D11 "Use Direct3D11 instead of Direct3D9 (Windows platform only); overrides URHO3D_OPENGL option" FALSE "WIN32" FALSE)
-    if (NOT ARM)
+    if (MINGW AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.1)
+        if (NOT DEFINED URHO3D_SSE)     # Only give the warning once during initial configuration
+            # Certain MinGW versions fail to compile SSE code. This is the initial guess for known "bad" version range, and can be tightened later
+            message (WARNING "Disabling SSE by default due to MinGW version. It is recommended to upgrade to MinGW with GCC >= 4.9.1. "
+                "You can also try to re-enable SSE with CMake option -DURHO3D_SSE=1, but this may result in compile errors.")
+        endif ()
+    endif ()
+    if (X86 OR WEB)
         # It is not possible to turn SSE off on 64-bit MSVC and it appears it is also not able to do so safely on 64-bit GCC
-        cmake_dependent_option (URHO3D_SSE "Enable SSE/SSE2 instruction set (32-bit Web and Intel platforms only, including Android on Intel Atom); default to true on Intel and false on Web platform; the effective SSE level could be higher, see also URHO3D_DEPLOYMENT_TARGET and CMAKE_OSX_DEPLOYMENT_TARGET build options" ${HAVE_SSE2} "NOT URHO3D_64BIT" TRUE)
+        cmake_dependent_option (URHO3D_SSE "Enable SSE/SSE2 instruction set (32-bit Web and Intel platforms only, including Android on Intel Atom); default to true on Intel and false on Web platform; the effective SSE level could be higher, see also URHO3D_DEPLOYMENT_TARGET and CMAKE_OSX_DEPLOYMENT_TARGET build options" "${HAVE_SSE2}" "NOT URHO3D_64BIT" TRUE)
     endif ()
-    cmake_dependent_option (URHO3D_3DNOW "Enable 3DNow! instruction set (Linux platform only); should only be used for older CPU with (legacy) 3DNow! support" ${HAVE_3DNOW} "NOT WIN32 AND NOT APPLE AND NOT WEB AND NOT ARM AND NOT URHO3D_SSE" FALSE)
-    cmake_dependent_option (URHO3D_MMX "Enable MMX instruction set (32-bit Linux platform only); the MMX is effectively enabled when 3DNow! or SSE is enabled; should only be used for older CPU with MMX support" ${HAVE_MMX} "NOT WIN32 AND NOT APPLE AND NOT WEB AND NOT ARM AND NOT URHO3D_64BIT AND NOT URHO3D_SSE AND NOT URHO3D_3DNOW" FALSE)
+    cmake_dependent_option (URHO3D_3DNOW "Enable 3DNow! instruction set (Linux platform only); should only be used for older CPU with (legacy) 3DNow! support" "${HAVE_3DNOW}" "X86 AND CMAKE_SYSTEM_NAME STREQUAL Linux AND NOT URHO3D_SSE" FALSE)
+    cmake_dependent_option (URHO3D_MMX "Enable MMX instruction set (32-bit Linux platform only); the MMX is effectively enabled when 3DNow! or SSE is enabled; should only be used for older CPU with MMX support" "${HAVE_MMX}" "X86 AND CMAKE_SYSTEM_NAME STREQUAL Linux AND NOT URHO3D_64BIT AND NOT URHO3D_SSE AND NOT URHO3D_3DNOW" FALSE)
     # For completeness sake - this option is intentionally not documented as we do not officially support PowerPC (yet)
-    cmake_dependent_option (URHO3D_ALTIVEC "Enable AltiVec instruction set (PowerPC only)" ${HAVE_ALTIVEC} POWERPC FALSE)
+    cmake_dependent_option (URHO3D_ALTIVEC "Enable AltiVec instruction set (PowerPC only)" "${HAVE_ALTIVEC}" POWERPC FALSE)
     cmake_dependent_option (URHO3D_LUAJIT "Enable Lua scripting support using LuaJIT (check LuaJIT's CMakeLists.txt for more options)" FALSE "NOT WEB" FALSE)
     cmake_dependent_option (URHO3D_LUAJIT_AMALG "Enable LuaJIT amalgamated build (LuaJIT only)" FALSE URHO3D_LUAJIT FALSE)
     cmake_dependent_option (URHO3D_SAFE_LUA "Enable Lua C++ wrapper safety checks (Lua/LuaJIT only)" FALSE URHO3D_LUA FALSE)
-    if (CMAKE_BUILD_TYPE STREQUAL Release OR CMAKE_CONFIGURATION_TYPES)
-        set (URHO3D_DEFAULT_LUA_RAW FALSE)
-    else ()
-        set (URHO3D_DEFAULT_LUA_RAW TRUE)
+    if (NOT CMAKE_BUILD_TYPE STREQUAL Release AND NOT CMAKE_CONFIGURATION_TYPES)
+        set (DEFAULT_LUA_RAW TRUE)
     endif ()
-    cmake_dependent_option (URHO3D_LUA_RAW_SCRIPT_LOADER "Prefer loading raw script files from the file system before falling back on Urho3D resource cache. Useful for debugging (e.g. breakpoints), but less performant (Lua/LuaJIT only)" ${URHO3D_DEFAULT_LUA_RAW} URHO3D_LUA FALSE)
+    cmake_dependent_option (URHO3D_LUA_RAW_SCRIPT_LOADER "Prefer loading raw script files from the file system before falling back on Urho3D resource cache. Useful for debugging (e.g. breakpoints), but less performant (Lua/LuaJIT only)" "${DEFAULT_LUA_RAW}" URHO3D_LUA FALSE)
     option (URHO3D_SAMPLES "Build sample applications" TRUE)
     option (URHO3D_UPDATE_SOURCE_TREE "Enable commands to copy back some of the generated build artifacts from build tree to source tree to facilitate devs to push them as part of a commit (for library devs with push right only)")
     option (URHO3D_BINDINGS "Enable API binding generation support for script subystems")
-    cmake_dependent_option (URHO3D_CLANG_TOOLS "Build Clang tools (native on host system only)" FALSE "NOT ANDROID AND NOT ARM AND NOT WEB" FALSE)
+    cmake_dependent_option (URHO3D_CLANG_TOOLS "Build Clang tools (native on host system only)" FALSE "NOT CMAKE_CROSSCOMPILING" FALSE)
     mark_as_advanced (URHO3D_UPDATE_SOURCE_TREE URHO3D_BINDINGS URHO3D_CLANG_TOOLS)
     cmake_dependent_option (URHO3D_TOOLS "Build tools (native, RPI, and ARM on Linux only)" TRUE "NOT IOS AND NOT ANDROID AND NOT WEB" FALSE)
     cmake_dependent_option (URHO3D_EXTRAS "Build extras (native, RPI, and ARM on Linux only)" FALSE "NOT IOS AND NOT ANDROID AND NOT WEB" FALSE)
@@ -445,7 +445,7 @@ if (URHO3D_C++11)
                 endif ()
             endforeach ()
             if (NOT GCC_EXIT_CODE EQUAL 0)
-                message (FATAL_ERROR "Your GCC version ${COMPILER_VERSION} is too old to enable C++11 standard")
+                message (FATAL_ERROR "Your GCC version ${CMAKE_CXX_COMPILER_VERSION} is too old to enable C++11 standard")
             endif ()
         endif ()
     elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang)

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

@@ -149,6 +149,7 @@ foreach (LANG C CXX)
     # Since currently CMake does not able to identify Emscripten compiler toolchain, set the compiler identification explicitly
     set (CMAKE_${LANG}_COMPILER_ID_RUN TRUE)
     set (CMAKE_${LANG}_COMPILER_ID Clang)
+    set (CMAKE_${LANG}_COMPILER_VERSION ${EMSCRIPTEN_EMCC_VERSION})
     # 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}_SIZEOF_DATA_PTR 4)   # Assume it is always 32-bit for now (we could have used our CheckCompilerToolChains.cmake module here)
@@ -184,5 +185,4 @@ if (NOT IN_TRY_COMPILE)
     set (ENV{VARS} "${VARS}")   # Stringify to keep the list together
 endif ()
 
-set (WEB 1)
 set (EMSCRIPTEN 1)