Browse Source

Refactor the CPU instruction extensions detection mechanism.
Fix SDL build on the latest Raspbian Jessie release.

Yao Wei Tjong 姚伟忠 9 years ago
parent
commit
71efb146cb

+ 165 - 0
CMake/Modules/CheckCompilerToolchain.cmake

@@ -0,0 +1,165 @@
+#
+# Copyright (c) 2008-2016 the Urho3D project.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+
+# Check the chosen compiler toolchain in the build tree
+#
+# Native ABI:
+#  NATIVE_64BIT
+#
+# Target architecture:
+#  ARM
+#  RPI
+#  POWERPC
+#
+# Compiler version in major.minor.patch format:
+#  COMPILER_VERSION
+#
+# CPU SIMD instruction extensions support:
+#  HAVE_MMX
+#  HAVE_3DNOW
+#  HAVE_SSE
+#  HAVE_SSE2
+#  HAVE_ALTIVEC
+#
+
+if (NOT MSVC AND NOT DEFINED NATIVE_PREDEFINED_MACROS)
+    execute_process (COMMAND ${CMAKE_COMMAND} -E echo COMMAND ${CMAKE_C_COMPILER} -E -dM - OUTPUT_VARIABLE NATIVE_PREDEFINED_MACROS ERROR_QUIET)
+    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 ()
+
+macro (check_native_define REGEX OUTPUT_VAR)
+    if (NOT DEFINED ${OUTPUT_VAR})
+        string (REGEX MATCH "#define +${REGEX} +1" matched "${NATIVE_PREDEFINED_MACROS}")
+        if (matched)
+            set (${OUTPUT_VAR} 1)
+        else ()
+            set (${OUTPUT_VAR} 0)
+        endif ()
+        set (${OUTPUT_VAR} ${${OUTPUT_VAR}} CACHE INTERNAL "Compiler toolchain has predefined macros matching ${REGEX}")
+    endif ()
+endmacro ()
+
+if (MSVC)
+    # On MSVC compiler, use the chosen CMake/VS generator to determine the ABI
+    # TODO: revisit this later because VS may use Clang as compiler in the future
+    if (CMAKE_GENERATOR MATCHES Win64)
+        set (NATIVE_64BIT 1)
+    else ()
+        set (NATIVE_64BIT 0)
+    endif ()
+    # Determine MSVC compiler version based on CMake informational variables
+    if (NOT DEFINED COMPILER_VERSION)
+        # TODO: fix this ugly hardcoding that needs to be constantly maintained
+        if (MSVC_VERSION EQUAL 1200)
+            set (COMPILER_VERSION 6.0)
+        elseif (MSVC_VERSION EQUAL 1300)
+            set (COMPILER_VERSION 7.0)
+        elseif (MSVC_VERSION EQUAL 1310)
+            set (COMPILER_VERSION 7.1)
+        elseif (MSVC_VERSION EQUAL 1400)
+            set (COMPILER_VERSION 8.0)
+        elseif (MSVC_VERSION EQUAL 1500)
+            set (COMPILER_VERSION 9.0)
+        elseif (MSVC_VERSION EQUAL 1600)
+            set (COMPILER_VERSION 10.0)
+        elseif (MSVC_VERSION EQUAL 1700)
+            set (COMPILER_VERSION 11.0)
+        elseif (MSVC_VERSION EQUAL 1800)
+            set (COMPILER_VERSION 12.0)
+        elseif (MSVC_VERSION EQUAL 1900)
+            set (COMPILER_VERSION 14.0)
+        elseif (MSVC_VERSION GREATER 1900)
+            set (COMPILER_VERSION 14.0+)
+        else ()
+            set (COMPILER_VERSION 6.0-)
+        endif ()
+        set (COMPILER_VERSION ${COMPILER_VERSION} CACHE INTERNAL "MSVC Compiler version")
+    endif ()
+else ()
+    # On non-MSVC compiler, default to build using native ABI of the chosen compiler toolchain in the build tree
+    check_native_define ("__(x86_|aarch|ppc|PPC|powerpc|POWERPC)64__" NATIVE_64BIT)
+    # 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)
+    # For completeness sake as currently we do not support PowerPC (yet)
+    check_native_define ("__(ppc|PPC|powerpc|POWERPC)(64)*__" POWERPC)
+    # Check if the target arm platform is currently supported
+    if (ARM AND NOT ANDROID AND NOT RPI AND NOT IOS AND NOT TVOS)
+        # TODO: check the uname of the host system for the telltale sign of RPI, just in case this is a native build on the device itself
+        message (FATAL_ERROR "Unsupported arm target architecture")
+    endif ()
+    # GCC/Clang and all their derivatives should understand this command line option to get the compiler version
+    if (NOT DEFINED COMPILER_VERSION)
+        execute_process (COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE COMPILER_VERSION ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
+        set (COMPILER_VERSION ${COMPILER_VERSION} CACHE INTERNAL "GCC/Clang Compiler version")
+    endif ()
+endif ()
+
+macro (check_extension CPU_INSTRUCTION_EXTENSION)
+    string (TOUPPER "${CPU_INSTRUCTION_EXTENSION}" UCASE_EXT_NAME)   # Stringify to guard against empty variable
+    if (NOT DEFINED HAVE_${UCASE_EXT_NAME})
+        execute_process (COMMAND ${CMAKE_COMMAND} -E echo COMMAND ${CMAKE_C_COMPILER} -m${CPU_INSTRUCTION_EXTENSION} -E -dM - OUTPUT_VARIABLE PREDEFINED_MACROS ERROR_QUIET)
+        if (NOT ${ARGN} STREQUAL "")
+            set (EXPECTED_MACRO ${ARGN})
+        else ()
+            set (EXPECTED_MACRO __${UCASE_EXT_NAME}__)
+        endif ()
+        string (REGEX MATCH "#define +${EXPECTED_MACRO} +1" matched "${PREDEFINED_MACROS}")
+        if (matched)
+            set (matched 1)
+        else ()
+            set (matched 0)
+        endif ()
+        set (HAVE_${UCASE_EXT_NAME} ${matched} CACHE INTERNAL "Compiler toolchain supports ${UCASE_EXT_NAME} CPU instruction extension")
+    endif ()
+endmacro ()
+
+if (NOT ARM)
+    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 ()
+        check_extension (mmx)
+        check_extension (sse)
+        check_extension (sse2)
+     endif ()
+    # As newer CPUs from AMD do not support 3DNow! anymore, we cannot make any assumption for 3DNow! extension check
+    # Don't bother with this check on AppleClang and MSVC compiler toolchains (Urho3D only supports CPU with SSE2 on the asscoiated platforms anyway)
+    if (NOT APPLE AND NOT MSVC)
+        check_extension (3dnow __3dNOW__)
+    endif ()
+    # For completeness sake as currently we do not support PowerPC (yet)
+    if (POWERPC)
+        check_extension (altivec)
+    endif ()
+endif ()
+
+# Explicitly set the variable to 1 when it is defined and truthy or 0 when it is not defined or falsy
+foreach (VAR HAVE_MMX HAVE_3DNOW HAVE_SSE HAVE_SSE2 HAVE_ALTIVEC)
+    if (${VAR})
+        set (${VAR} 1)
+    else ()
+        set (${VAR} 0)
+    endif ()
+endforeach ()

+ 0 - 148
CMake/Modules/CheckCpuInstructionExtensions.cmake

@@ -1,148 +0,0 @@
-#
-# Copyright (c) 2008-2016 the Urho3D project.
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
-#
-
-# Check CPU SIMD instruction extensions support
-#
-#  HAVE_MMX
-#  HAVE_3DNOW
-#  HAVE_SSE
-#  HAVE_SSE2
-#  HAVE_ALTIVEC_H
-#  HAVE_ALTIVEC
-#
-
-if (NOT ARM)
-    include (CheckCSourceCompiles)
-    set (ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
-    if (MSVC OR URHO3D_64BIT)
-        # 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} TRUE)
-        endforeach ()
-        # As newer CPUs from AMD do not support 3DNow! anymore, we cannot make any assumption for 3DNow! extension check
-        if (NOT APPLE AND NOT MSVC)  # Don't bother with this check on AppleClang and MSVC compiler toolchains
-            set (CMAKE_REQUIRED_FLAGS "-m3dnow")
-            check_c_source_compiles ("
-                #include <mm3dnow.h>
-                #ifndef __3dNOW__
-                #error Assembler CPP flag not enabled
-                #endif
-                int main(int argc, char **argv) {
-                void *p = 0;
-                _m_prefetch(p);
-                }" HAVE_3DNOW)
-        endif ()
-    else ()
-        # Windows platform using MinGW compiler toolchain may or may not pass these checks depends on the MinGW compiler version being used
-        # Credit - the following CPU instruction extension checks are shamefully copied from SDL's CMakeLists.txt
-        # MMX extension check
-        set (CMAKE_REQUIRED_FLAGS "-mmmx")
-        check_c_source_compiles ("
-            #ifdef __MINGW32__
-            #include <_mingw.h>
-            #ifdef __MINGW64_VERSION_MAJOR
-            #include <intrin.h>
-            #else
-            #include <mmintrin.h>
-            #endif
-            #else
-            #include <mmintrin.h>
-            #endif
-            #ifndef __MMX__
-            #error Assembler CPP flag not enabled
-            #endif
-            int main(int argc, char **argv) { }" HAVE_MMX)
-        # 3DNow! extension check
-        if (NOT APPLE)
-            set (CMAKE_REQUIRED_FLAGS "-m3dnow")
-            check_c_source_compiles ("
-                #include <mm3dnow.h>
-                #ifndef __3dNOW__
-                #error Assembler CPP flag not enabled
-                #endif
-                int main(int argc, char **argv) {
-                void *p = 0;
-                _m_prefetch(p);
-                }" HAVE_3DNOW)
-        endif ()
-        # SSE extension check
-        set (CMAKE_REQUIRED_FLAGS -msse)
-        check_c_source_compiles ("
-            #ifdef __MINGW32__
-            #include <_mingw.h>
-            #ifdef __MINGW64_VERSION_MAJOR
-            #include <intrin.h>
-            #else
-            #include <xmmintrin.h>
-            #endif
-            #else
-            #include <xmmintrin.h>
-            #endif
-            #ifndef __SSE__
-            #error Assembler CPP flag not enabled
-            #endif
-            int main(int argc, char **argv) { }" HAVE_SSE)
-        # SSE2 extension check
-        set (CMAKE_REQUIRED_FLAGS "-msse2")
-        check_c_source_compiles ("
-            #ifdef __MINGW32__
-            #include <_mingw.h>
-            #ifdef __MINGW64_VERSION_MAJOR
-            #include <intrin.h>
-            #else
-            #include <emmintrin.h>
-            #endif
-            #else
-            #include <emmintrin.h>
-            #endif
-            #ifndef __SSE2__
-            #error Assembler CPP flag not enabled
-            #endif
-            int main(int argc, char **argv) { }" HAVE_SSE2)
-    endif ()
-    # AltiVec extension check - for completeness sake as currently we do not support PowerPC
-    if (POWERPC)    # This variable is always FALSE for now until we support cross-compiling to target PowerPC platform
-        set(CMAKE_REQUIRED_FLAGS "-maltivec")
-        check_c_source_compiles ("
-                #include <altivec.h>
-                vector unsigned int vzero() {
-                    return vec_splat_u32(0);
-                }
-                int main(int argc, char **argv) { }" HAVE_ALTIVEC_H)
-        check_c_source_compiles ("
-                vector unsigned int vzero() {
-                    return vec_splat_u32(0);
-                }
-                int main(int argc, char **argv) { }" HAVE_ALTIVEC)
-        if (HAVE_ALTIVEC_H AND NOT HAVE_ALTIVEC)
-            set (HAVE_ALTIVEC TRUE) # if only HAVE_ALTIVEC_H is set
-        endif ()
-    endif ()
-    set (CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
-endif ()
-
-# Explicitly set the variable to FALSE when it is not defined or falsy
-foreach (VAR HAVE_MMX HAVE_3DNOW HAVE_SSE HAVE_SSE2 HAVE_ALTIVEC_H HAVE_ALTIVEC)
-    if (NOT ${VAR})
-        set (${VAR} FALSE)
-    endif ()
-endforeach ()

+ 7 - 1
CMake/Modules/FindEsound.cmake

@@ -27,8 +27,14 @@
 #  ESOUND_LIBRARIES
 #
 
+if (URHO3D_64BIT)
+    set (ESOUND_LIB_SEARCH_PATH /usr/lib/x86_64-linux-gnu)
+else ()
+    set (ESOUND_LIB_SEARCH_PATH /usr/lib/i386-linux-gnu)
+endif ()
+
 find_path (ESOUND_INCLUDE_DIRS NAMES esd.h DOC "Esound include directory")
-find_library (ESOUND_LIBRARIES NAMES esd DOC "Esound library")
+find_library (ESOUND_LIBRARIES NAMES esd PATHS ${ESOUND_LIB_SEARCH_PATH} DOC "Esound library")
 
 include (FindPackageHandleStandardArgs)
 find_package_handle_standard_args (Esound REQUIRED_VARS ESOUND_LIBRARIES ESOUND_INCLUDE_DIRS FAIL_MESSAGE "Could NOT find Esound development library")

+ 42 - 0
CMake/Modules/FindNetworkAudioSystem.cmake

@@ -0,0 +1,42 @@
+#
+# Copyright (c) 2008-2016 the Urho3D project.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+
+# Find NetworkAudioSystem development library
+#
+#  NAS_FOUND
+#  NAS_INCLUDE_DIRS
+#  NAS_LIBRARIES
+#
+
+if (URHO3D_64BIT)
+    set (NAS_LIB_SEARCH_PATH /usr/lib/x86_64-linux-gnu)
+else ()
+    set (NAS_LIB_SEARCH_PATH /usr/lib/i386-linux-gnu)
+endif ()
+
+find_path (NAS_INCLUDE_DIRS NAMES audio/audiolib.h nas/audiolib.h DOC "NetworkAudioSystem include directory")
+find_library (NAS_LIBRARIES NAMES audio PATHS ${NAS_LIB_SEARCH_PATH} DOC "NetworkAudioSystem library")
+
+include (FindPackageHandleStandardArgs)
+find_package_handle_standard_args (NetworkAudioSystem REQUIRED_VARS NAS_LIBRARIES NAS_INCLUDE_DIRS FAIL_MESSAGE "Could NOT find NetworkAudioSystem development library")
+
+mark_as_advanced (NAS_INCLUDE_DIRS NAS_LIBRARIES)

+ 2 - 2
CMake/Modules/FindReadline.cmake

@@ -31,13 +31,13 @@ if (APPLE AND NOT READLINE_INCLUDE_DIRS AND NOT READLINE_LIBRARIES)
     # Assuming GNU Readline development library is installed using Homebrew (keg-only - prebuilt universal binary)
     execute_process (COMMAND find /usr/local/Cellar/readline -type d -name include OUTPUT_VARIABLE INC_HINTS ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
     execute_process (COMMAND find /usr/local/Cellar/readline -type d -name lib OUTPUT_VARIABLE LIB_HINTS ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
-elseif (URHO3D_DEFAULT_64BIT AND NOT URHO3D_64BIT)
+elseif (NATIVE_64BIT AND NOT URHO3D_64BIT)
     # To cater for 32-bit build on 64-bit host system using Debian-based distros; no special handling required for Redhat-based distros but no harm done in doing below
     set (LIB_HINTS /usr/lib32)
 endif ()
 find_path (READLINE_INCLUDE_DIRS NAMES readline.h HINTS ${INC_HINTS} PATH_SUFFIXES readline DOC "Readline include directory")
 find_library (READLINE_LIBRARIES NAMES readline HINTS ${LIB_HINTS} DOC "Readline library")
-if (NOT APPLE AND URHO3D_DEFAULT_64BIT AND NOT URHO3D_64BIT AND READLINE_LIBRARIES MATCHES 64)
+if (NOT APPLE AND NATIVE_64BIT AND NOT URHO3D_64BIT AND READLINE_LIBRARIES MATCHES 64)
     unset (READLINE_LIBRARIES CACHE)    # Nullify the search result if the ABI is not matched
     unset (READLINE_LIBRARIES)
 endif ()

+ 42 - 0
CMake/Modules/FindRoarAudio.cmake

@@ -0,0 +1,42 @@
+#
+# Copyright (c) 2008-2016 the Urho3D project.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+
+# Find RoarAudio development library
+#
+#  SNDIO_FOUND
+#  SNDIO_INCLUDE_DIRS
+#  SNDIO_LIBRARIES
+#
+
+if (URHO3D_64BIT)
+    set (SNDIO_LIB_SEARCH_PATH /usr/lib/x86_64-linux-gnu)
+else ()
+    set (SNDIO_LIB_SEARCH_PATH /usr/lib/i386-linux-gnu)
+endif ()
+
+find_path (SNDIO_INCLUDE_DIRS NAMES RoarAudio.h DOC "RoarAudio include directory")
+find_library (SNDIO_LIBRARIES NAMES RoarAudio PATHS ${SNDIO_LIB_SEARCH_PATH} DOC "RoarAudio library")
+
+include (FindPackageHandleStandardArgs)
+find_package_handle_standard_args (RoarAudio REQUIRED_VARS SNDIO_LIBRARIES SNDIO_INCLUDE_DIRS FAIL_MESSAGE "Could NOT find RoarAudio development library")
+
+mark_as_advanced (SNDIO_INCLUDE_DIRS SNDIO_LIBRARIES)

+ 1 - 1
CMake/Modules/FindUrho3D.cmake

@@ -170,7 +170,7 @@ else ()
     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 MINGW OR ANDROID OR RPI OR WEB) AND NOT ABI_64BIT EQUAL URHO3D_DEFAULT_64BIT)
+        if ((MSVC OR MINGW OR ANDROID OR RPI OR WEB) AND NOT ABI_64BIT EQUAL NATIVE_64BIT)
             break ()
         endif ()
         # Set to search in 'lib' or 'lib64' based on the ABI being tested

+ 22 - 52
CMake/Modules/Urho3D-CMake-common.cmake

@@ -41,7 +41,7 @@ if (CMAKE_GENERATOR STREQUAL Xcode)
     set (XCODE TRUE)
 endif ()
 
-# Rightfully we could have performed this inside a CMake/iOS toolchain file but we don't have one nor need for one
+# Rightfully we could have performed this inside a CMake/iOS toolchain file but we don't have one nor need for one for now
 if (IOS)
     set (CMAKE_CROSSCOMPILING TRUE)
     set (CMAKE_XCODE_EFFECTIVE_PLATFORMS -iphoneos -iphonesimulator)
@@ -56,8 +56,8 @@ if (IOS)
     endif ()
     set (CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES)
     if (DEFINED ENV{TRAVIS})
-        # TODO: recheck this again later
-        # Ensure the CMAKE_OSX_DEPLOYMENT_TARGET is set to empty, something is wrong with Travis-CI OSX worker
+        # TODO: recheck this again and remove this workaround later
+        # Ensure the CMAKE_OSX_DEPLOYMENT_TARGET is set to empty, something is wrong with Travis-CI OSX CI environment at the moment
         set (CMAKE_OSX_DEPLOYMENT_TARGET)
         unset (CMAKE_OSX_DEPLOYMENT_TARGET CACHE)
     endif ()
@@ -72,45 +72,12 @@ elseif (XCODE)
 endif ()
 
 # Define all supported build options
+include (CheckCompilerToolchain)
 include (CMakeDependentOption)
 option (URHO3D_C++11 "Enable C++11 standard")
 mark_as_advanced (URHO3D_C++11)
 cmake_dependent_option (IOS "Setup build for iOS platform" FALSE "XCODE" FALSE)
-if (NOT DEFINED URHO3D_DEFAULT_64BIT)  # Only do this once in the initial configure step
-    if (MSVC)
-        # On MSVC compiler, use the chosen CMake/VS generator to determine the ABI
-        if (CMAKE_GENERATOR MATCHES Win64)
-            set (URHO3D_DEFAULT_64BIT 1)
-        else ()
-            set (URHO3D_DEFAULT_64BIT 0)
-        endif ()
-    else ()
-        # On non-MSVC compiler, default to build 64-bit when the chosen compiler toolchain in the build tree has a 64-bit build environment
-        execute_process (COMMAND ${CMAKE_COMMAND} -E echo COMMAND ${CMAKE_C_COMPILER} -E -dM - OUTPUT_VARIABLE PREDEFINED_MACROS ERROR_QUIET)
-        string (REGEX MATCH "#define +__(x86_64|aarch64)__ +1" matched "${PREDEFINED_MACROS}")
-        if (matched)
-            set (URHO3D_DEFAULT_64BIT 1)
-        else ()
-            set (URHO3D_DEFAULT_64BIT 0)
-        endif ()
-        # The 'ANDROID' CMake variable is already set by android.toolchain.cmake when it is being used for cross-compiling Android
-        # When ANDROID is true and ARM is not then we are targeting Android on Intel Atom
-        string (REGEX MATCH "#define +__(arm|aarch64)__ +1" matched "${PREDEFINED_MACROS}")
-        if (matched OR IOS)     # Assume iOS is always on ARM for now
-            set (ARM TRUE)
-        else ()
-            set (ARM FALSE)
-        endif ()
-        set (ARM ${ARM} CACHE INTERNAL "Targeting ARM platform")
-        # The other arm platform that Urho3D supports that is not Android/iOS is Raspberry Pi at the moment
-        if (ARM AND NOT ANDROID AND NOT IOS)
-            # Set the CMake variable here instead of in raspberrypi.toolchain.cmake because Raspberry Pi can be built natively too on the Raspberry-Pi device itself
-            set (RPI TRUE CACHE INTERNAL "Setup build for Raspberry Pi platform")
-        endif ()
-    endif ()
-    set (URHO3D_DEFAULT_64BIT ${URHO3D_DEFAULT_64BIT} CACHE INTERNAL "Default value for URHO3D_64BIT build option")
-endif ()
-cmake_dependent_option (URHO3D_64BIT "Enable 64-bit build, the default is set based on the native ABI of the chosen compiler toolchain" ${URHO3D_DEFAULT_64BIT} "NOT MSVC AND NOT MINGW AND NOT ANDROID AND NOT RPI AND NOT WEB" ${URHO3D_DEFAULT_64BIT})
+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 MINGW AND NOT ANDROID AND NOT RPI AND NOT WEB AND NOT POWERPC" ${NATIVE_64BIT})
 cmake_dependent_option (URHO3D_ANGELSCRIPT "Enable AngelScript scripting support" TRUE "NOT WEB" FALSE)
 option (URHO3D_LUA "Enable additional Lua scripting support" TRUE)
 option (URHO3D_NAVIGATION "Enable navigation support" TRUE)
@@ -149,8 +116,6 @@ if (RPI)
     find_package (VideoCore REQUIRED)
     include_directories (${VIDEOCORE_INCLUDE_DIRS})
 endif ()
-# Need to perform the CPU SIMD instruction extensions check for Urho3D project as well as downstream projects using this common module
-include (CheckCpuInstructionExtensions)
 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
@@ -170,16 +135,21 @@ if (CMAKE_PROJECT_NAME STREQUAL Urho3D)
     # Set the default to true for all the platforms that support SSE extension except specificially stated otherwise below
     if (HAVE_SSE OR HAVE_SSE2)
         set (URHO3D_DEFAULT_SSE TRUE)
+        if (MINGW)
+            # Certain MinGW versions fail to compile SSE code. This is the initial guess for known "bad" version range, and can be tightened later
+            if (COMPILER_VERSION VERSION_LESS 4.9.1)
+                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.")
+                set (URHO3D_DEFAULT_SSE FALSE)
+            endif ()
+        endif ()
     else ()
-        # The older MinGW compiler versions should automatically fail the SSE/SSE extension check, so does the Emscripten compiler toolchain
-        # TODO: Revisit this again for Emscripten when the SIMD.js specification is already widely adopted by browsers
         set (URHO3D_DEFAULT_SSE FALSE)
     endif ()
     cmake_dependent_option (URHO3D_SSE "Enable SSE/SSE2 instruction set (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" ${URHO3D_DEFAULT_SSE} "NOT ARM" 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} "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)
-    option (URHO3D_ALTIVEC "Enable AltiVec instruction set" ${HAVE_ALTIVEC})
-    mark_as_advanced (URHO3D_ALTIVEC)   # For completeness sake - this option is intentionally not documented as we do not officially support PowerPC (probably never will)
+    # 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_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 OR URHO3D_LUAJIT" FALSE)
@@ -518,8 +488,7 @@ if (URHO3D_C++11)
                 endif ()
             endforeach ()
             if (NOT GCC_EXIT_CODE EQUAL 0)
-                execute_process (COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
-                message (FATAL_ERROR "Your GCC version ${GCC_VERSION} is too old to enable C++11 standard")
+                message (FATAL_ERROR "Your GCC version ${COMPILER_VERSION} is too old to enable C++11 standard")
             endif ()
         endif ()
     elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang)
@@ -592,6 +561,7 @@ else ()
     set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-offsetof")
     if (NOT ANDROID)    # Most of the flags are already setup in android.toolchain.cmake module
         if (RPI)
+            # The configuration is done here instead of in raspberrypi.toolchain.cmake file because we also support native build which does not use that file at all
             add_definitions (-DRPI)
             set (RPI_CFLAGS "-pipe -mfloat-abi=hard -Wno-psabi")    # We only support armhf distros, so turn on hard-float by default
             if (RPI_ABI MATCHES ^armeabi-v7a)
@@ -630,7 +600,7 @@ else ()
                     endif ()
                     # Not the compiler native ABI, this could only happen on multilib-capable compilers
                     # We don't add the ABI flag for Xcode because it automatically passes '-arch i386' compiler flag when targeting 32 bit which does the same thing as '-m32'
-                    if (URHO3D_DEFAULT_64BIT)
+                    if (NATIVE_64BIT)
                         set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
                         set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
                     endif ()
@@ -656,11 +626,11 @@ else ()
                     set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DISABLE_SSE_FLAG} -m3dnow")
                     set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DISABLE_SSE_FLAG} -m3dnow")
                 endif ()
-            endif ()
-            # For completeness sake only as we do not support PowerPC
-            if (URHO3D_ALTIVEC)
-                set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maltivec")
-                set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maltivec")
+                # For completeness sake only as we do not support PowerPC (yet)
+                if (URHO3D_ALTIVEC)
+                    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maltivec")
+                    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maltivec")
+                endif ()
             endif ()
         endif ()
         if (WEB)

+ 2 - 0
CMake/Toolchains/raspberrypi.toolchain.cmake

@@ -94,3 +94,5 @@ set (CMAKE_FIND_ROOT_PATH ${RPI_SYSROOT})
 set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
 set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
 set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+
+set (RPI 1)

+ 20 - 4
Docs/GettingStarted.dox

@@ -12,9 +12,25 @@ Although all required third-party libraries are included as source code, there a
 
 - For Windows, the June 2010 DirectX SDK needs to be installed. This is not necessary if building on Visual Studio 2012 or newer, which install the Windows SDK with the necessary DirectX files.
 
-- For Linux, the following development packages need to be installed: libx11-dev, libxrandr-dev, libasound2-dev on Debian-based distros; libX11-devel, libXrandr-devel, alsa-lib-devel on RedHat-based distros. Optionally install libpulse-dev (Deb) or pulseaudio-libs-devel (RH) to enable SDL support for PulseAudio. Building as 32-bit on a 64-bit system requires installing also the 32-bit versions of the development libraries.
-
-- For Raspberry Pi, the following development packages need to be installed. On Raspbian: libasound2-dev, libudev-dev. On Pidora: alsa-lib-devel, systemd-devel.
+- For Linux, the following development packages need to be installed: libx11-dev, libxrandr-dev, libasound2-dev on Debian-based distros; libX11-devel, libXrandr-devel, alsa-lib-devel on RedHat-based distros. Building as 32-bit on a 64-bit system requires installing also the 32-bit versions of the development libraries. Optionally install the following development libraries to enable support for the corresponding software components:
+  + %Database server (disabled by default even when installed, use URHO3D_DATABASE_ODBC build option to enable):
+    - libiodbc2-dev (Debian-based) or libiodbc-devel (RedHat-based) for iODBC driver manager.
+    - unixodbc-dev (Debian-based) unixODBC-devel (RedHat-based) for ODBC driver manager. *Recommended*
+  + Display server:
+    - libdirectfb-dev (DB-based only) for direct frame buffer (DirectFB).
+    - mir-client-platform-mesa-dev and mircommon-dev (Ubuntu only) for Mir.
+    - libwayland-client-devel, libwayland-cursor-devel, and mesa-libwayland-egl-devel (RedHat-based only, pre-installed on Fedora 22+) for Wayland.
+  + %Sound server:
+    - arts-devel (RedHat-based only) for analog real time synthesizer (aRts).
+    - libaudio-dev (Debian-based only) for network audio system (NAS).
+    - libesd0-dev (Debian-based) or esound-devel (RedHat-based) for enlightened sound daemon (ESounD).
+    - libfusionsound-dev (DB-based only, not available on Ubuntu) for FusionSound. Disabled by default even when installed, use SDL_OPT_FUSIONSOUND(_SHARED) build option to enable.
+    - libpulse-dev (Debian-based) or pulseaudio-libs-devel (RedHat-based) for PulseAudio. *Recommended*
+    - libroar-dev (Debian-based only) for RoarAudio (SNDIO).
+  + Misc.:
+    - libts-dev (Debian-based) or tslib-devel (RedHat-based) for touchscreen input.
+
+- For Raspberry Pi, the following development packages need to be installed. On Raspbian: libevdev2, libasound2-dev, and libudev-dev. On Pidora: libevdev, alsa-lib-devel, and systemd-devel. The same list of optional development libraries listed above for Linux can also be installed on Raspberry Pi system to enable support for the corresponding software components.
 
 - For Mac OS X, the Xcode developer tools package should include everything necessary. Make sure that the Xcode command line tools are also installed.
 
@@ -216,7 +232,7 @@ To run from Xcode on iPhone/iPad Simulator, edit the Product Scheme to set "Run"
 
 For native build on Raspberry Pi itself, use the similar process for \ref Building_Native "Native build process" described above.
 
-For cross-compiling build on an Linux host system, firstly set the RPI_PREFIX environment variable or build option to point to your Raspberry Pi Cross-Compiling tool are located. You can setup the tool using <a href="http://crosstool-ng.org/">crosstool-NG</a> or just download one from https://github.com/raspberrypi/tools. Secondly, set the RPI_SYSROOT environment variable or build option to point to your Raspbian or Pidora system root. You must install the Urho3D prerequisites software development packages for Raspberry Pi (see \ref Building_Prerequisites) in the system root before attempting to do the Urho3D cross-compiling build. You are recommended to download the Raspbian system root with Urho3D prerequisite software installed from https://github.com/urho3d/rpi-sysroot. You can just download from the "strip" branch to cut down the download time and size. Alternatively, if you have a fast LAN connection then you can also opt to mount the system root on your actual Raspberry Pi device to your host system via SSHFS and set the RPI_SYSROOT to use the mount point.
+For cross-compiling build on an Linux host system, firstly set the RPI_PREFIX environment variable or build option to point to your Raspberry Pi Cross-Compiling tool are located. You can setup the tool using <a href="http://crosstool-ng.org/">crosstool-NG</a> or just download one from https://github.com/raspberrypi/tools. Secondly, set the RPI_SYSROOT environment variable or build option to point to your Raspbian or Pidora system root. You must install the Urho3D prerequisites software development packages for Raspberry Pi (see \ref Building_Prerequisites) in the system root before attempting to do the Urho3D cross-compiling build. You are recommended to download the Raspbian system root with Urho3D prerequisite software installed from https://github.com/urho3d/rpi-sysroot. Alternatively, if you have a fast LAN connection then you can also opt to mount the system root on your actual Raspberry Pi device to your host system via SSHFS and set the RPI_SYSROOT to use the mount point.
 
 Execute cmake_raspi.sh then go to the build tree to execute make command. You may pass the optional RPI_ABI build option to specifically target for the Raspberry Pi 2. After the build is complete, the ARM executables can be found in the build tree's "bin" subdirectory.
 

+ 1 - 1
Source/ThirdParty/LuaJIT/CMakeLists.txt

@@ -423,7 +423,7 @@ if (WIN32)
 else ()
     set (LJVM_BOUT lj_vm.S)
     enable_language (ASM)
-    if (URHO3D_DEFAULT_64BIT AND NOT URHO3D_64BIT)  # Not the compiler native ABI, this could only happen on multilib-capable compilers
+    if (NATIVE_64BIT AND NOT URHO3D_64BIT)  # Not the compiler native ABI, this could only happen on multilib-capable compilers
         set (CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -m32")
     endif ()
     if (APPLE)

+ 119 - 134
Source/ThirdParty/SDL/CMakeLists.txt

@@ -46,15 +46,10 @@
 # Urho3D - define target name
 set (TARGET_NAME SDL)
 
-# Urho3D - commented out as we support both out-of- and in- source tree builds
-#if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
-#  message(FATAL_ERROR "Prevented in-tree built. Please create a build directory outside of the SDL source code and call cmake from there")
-#endif()
-
-# Urho3D - commented out as we want SDL sub-library to remain within Urho3D "umbrella" project
-#cmake_minimum_required(VERSION 2.8)
-#project(SDL2 C)
-# Urho3D - instead, just enable the required language support and set the extra variables associated with project() command
+# Urho3D - commented out in-source tree build prevention as Urho3D supports both out-of-source and in-source tree builds
+
+# Urho3D - commented out setting SDL2 as project name as we want SDL sub-library to remain within Urho3D "umbrella" project
+#          instead, just enable the required language support and set the extra variables associated with project() command
 enable_language (C)
 set (SDL2_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
 set (SDL2_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
@@ -69,7 +64,6 @@ include(CheckTypeSize)
 include(CheckStructHasMember)
 include(CMakeDependentOption)
 # Urho3D - bug fix - do not use pkg-config tool for detection as it only works for host environment and not for rooted environment when cross-compiling
-#include(FindPkgConfig)
 # Urho3D - append SDL's CMake module directory into our global module search path
 list (APPEND CMAKE_MODULE_PATH ${SDL2_SOURCE_DIR}/cmake)
 include(${SDL2_SOURCE_DIR}/cmake/macros.cmake)
@@ -98,13 +92,11 @@ set(LT_REVISION "${SDL_INTERFACE_AGE}")
 set(LT_RELEASE "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}")
 set(LT_VERSION "${LT_MAJOR}.${LT_AGE}.${LT_REVISION}")
 
-# Urho3D - no debug print
-#message(STATUS "${LT_VERSION} :: ${LT_AGE} :: ${LT_REVISION} :: ${LT_CURRENT} :: ${LT_RELEASE}")
+# Urho3D - commented out debug print
 
 # General settings & flags
 # Urho3D - commented out LIBRARY_OUTPUT_DIRECTORY configuration so that it does not mess up with our global configuration setup
 # Check for 64 or 32 bit
-set(SIZEOF_VOIDP ${CMAKE_SIZEOF_VOID_P})
 # Urho3D - bug fix - using CMAKE_SIZEOF_VOID_P is not accurate in a situation where a multilib-capable compiler is chosen and user has opted to use non-native ABI; instead using URHO3D_64BIT build option as it also captures the user intention
 if(URHO3D_64BIT)
   set(ARCH_64 TRUE)
@@ -201,39 +193,7 @@ else()
   set(OPT_DEF_ASM FALSE)
 endif()
 
-# Default flags, if not set otherwise
-if("$ENV{CFLAGS}" STREQUAL "")
-# Urho3D - commented out as we have configured compiler flags as we want globally
-#  if(USE_GCC OR USE_CLANG)
-#    set(CMAKE_C_FLAGS "-g -O3")
-#  endif()
-else()
-#  set(CMAKE_C_FLAGS "$ENV{CFLAGS}")
-  list(APPEND EXTRA_CFLAGS "$ENV{CFLAGS}")
-endif()
-if(NOT ("$ENV{CFLAGS}" STREQUAL "")) # Hackish, but does the trick on Win32
-  list(APPEND EXTRA_LDFLAGS "$ENV{LDFLAGS}")
-endif()
-
-#if(MSVC)
-#  option(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
-#  if(FORCE_STATIC_VCRT)
-#    foreach(flag_var
-#        CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
-#        CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
-#      if(${flag_var} MATCHES "/MD")
-#        string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
-#      endif()
-#    endforeach()
-#  endif()
-#
-#  # Make sure /RTC1 is disabled, otherwise it will use functions from the CRT
-#  foreach(flag_var
-#      CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
-#      CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
-#    string(REGEX REPLACE "/RTC(su|[1su])" "" ${flag_var} "${${flag_var}}")
-#  endforeach(flag_var)
-#endif()
+# Urho3D - commented out compiler/linker flags setup as we have configured all our compiler/linker flags as we want globally
 
 # Those are used for pkg-config and friends, so that the SDL2.pc, sdl2-config,
 # etc. are created correctly.
@@ -245,8 +205,9 @@ set(SDL_CFLAGS "")
 # restore back to that afterwards. For check_function_exists() to work in
 # Emscripten, this value must be at its default value.
 set(ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
-# Urho3D - safe the original CMake global settings
-set(ORIG_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES})
+# Urho3D - save the original CMake global settings, do not leave them to chances
+set (ORIG_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES})
+set (ORIG_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
 
 if(CYGWIN)
   # We build SDL on cygwin without the UNIX emulation layer
@@ -264,13 +225,12 @@ endif()
 
 add_definitions(-DUSING_GENERATED_CONFIG_H)
 # General includes
-# Urho3D - use 'generated' path suffix for generated config header file (need the suffix as we support both out-of-source in-source build tree)
+# Urho3D - use 'generated' path suffix for generated config header file, the suffic prevents overwriting the header file with the same name in the source tree in case of non out-of-source build tree is being used
 set (INCLUDE_DIRS ${SDL2_BINARY_DIR}/include/generated ${SDL2_SOURCE_DIR}/include)
 
 # All these ENABLED_BY_DEFAULT vars will default to ON if not specified, so
 #  you only need to have a platform override them if they are disabling.
-# Urho3D - it looks like a bug[?] because this variable is already initialized properly in "Compiler info" section above
-#set(OPT_DEF_ASM TRUE)
+# Urho3D - bug fix - commented out double initialization of the OPT_DEF_ASM variable, it has been initialized properly in "Compiler info" section above
 if(EMSCRIPTEN)
   # Set up default values for the currently supported set of subsystems:
   # Emscripten/Javascript does not have assembly support, a dynamic library
@@ -302,6 +262,7 @@ foreach(_SUB ${SDL_SUBSYSTEMS})
   option(SDL_${_OPT} "Enable the ${_SUB} subsystem" ${SDL_${_OPT}_ENABLED_BY_DEFAULT})
 endforeach()
 
+# Urho3D - TODO - put all these options into SDL-specific namespace group, they are littering CMake-gui all over the place as it is now
 option_string(ASSERTIONS "Enable internal sanity checks (auto/disabled/release/enabled/paranoid)" "auto")
 #set_option(DEPENDENCY_TRACKING "Use gcc -MMD -MT dependency tracking" ON)
 set_option(LIBC                "Use the system C library" ${OPT_DEF_LIBC})
@@ -341,15 +302,13 @@ set_option(RPATH               "Use an rpath when linking SDL" ${UNIX_SYS})
 set_option(CLOCK_GETTIME       "Use clock_gettime() instead of gettimeofday()" OFF)
 set_option(INPUT_TSLIB         "Use the Touchscreen library for input" ${UNIX_SYS})
 set_option(VIDEO_X11           "Use X11 video driver" ${UNIX_SYS})
-# Urho3D - hide Wayland option for Android and RPI platforms
-dep_option(VIDEO_WAYLAND       "Use Wayland video driver" ON "UNIX_SYS AND NOT ANDROID AND NOT RPI" OFF)
+dep_option(VIDEO_WAYLAND       "Use Wayland video driver" ON UNIX_SYS OFF)
 dep_option(WAYLAND_SHARED      "Dynamically load Wayland support" ON "VIDEO_WAYLAND" OFF)
 dep_option(VIDEO_WAYLAND_QT_TOUCH  "QtWayland server support for Wayland video driver" ON "VIDEO_WAYLAND" OFF)
-# Urho3D - hide Mir option for Android and RPI platforms
-dep_option(VIDEO_MIR           "Use Mir video driver" ON "UNIX_SYS AND NOT ANDROID AND NOT RPI" OFF)
+dep_option(VIDEO_MIR           "Use Mir video driver" ON UNIX_SYS OFF)
 dep_option(MIR_SHARED          "Dynamically load Mir support" ON "VIDEO_MIR" OFF)
 # Urho3D - only enable VIDEO_RPI on Raspberry-Pi platform
-dep_option(VIDEO_RPI           "Use Raspberry Pi video driver" ON "RPI" OFF)
+dep_option(VIDEO_RPI           "Use Raspberry Pi video driver" ON RPI OFF)
 dep_option(X11_SHARED          "Dynamically load X11 support" ON "VIDEO_X11" OFF)
 set(SDL_X11_OPTIONS Xcursor Xinerama XInput Xrandr Xscrnsaver XShape Xvm)
 foreach(_SUB ${SDL_X11_OPTIONS})
@@ -367,12 +326,12 @@ set(SDL_SHARED ${SDL_SHARED_ENABLED_BY_DEFAULT} CACHE BOOL "Build a shared versi
 set(SDL_STATIC ON CACHE BOOL "Build a static version of the library")
 
 # General source files
-# Urho3D - exclude source files from disabled subsystems
 set (SOURCE_FILE_PATTERNS
   ${SDL2_SOURCE_DIR}/src/*.c
-#  ${SDL2_SOURCE_DIR}/src/dynapi/*.c  # Urho3D - disabled dynamic API
+# Urho3D - we always disable dynamic API, so commented out ${SDL2_SOURCE_DIR}/src/dynapi/*.c
   ${SDL2_SOURCE_DIR}/src/libm/*.c
   ${SDL2_SOURCE_DIR}/src/stdlib/*.c)
+# Urho3D - exclude source files from disabled subsystems
 foreach (_SUB ATOMIC AUDIO CPUINFO EVENTS FILE RENDER THREADS TIMERS VIDEO)
   string (TOLOWER ${_SUB} _DIR)
   if (${SDL_${_SUB}})
@@ -437,12 +396,14 @@ if(USE_GCC OR USE_CLANG)
     HAVE_GCC_PREFERRED_STACK_BOUNDARY)
   set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
 
-# Urho3D - we rely on GenerateExportHeader CMake module for configuring GCC/Clang visibility support
+# Urho3D - we rely on GenerateExportHeader CMake module for configuring GCC/Clang visibility attribute support
 
   check_c_compiler_flag(-Wall HAVE_GCC_WALL)
   if(HAVE_GCC_WALL)
     list(APPEND EXTRA_CFLAGS "-Wall")
     if(HAIKU)
+      # Urho3D - TODO - since we do not support HAIKU for now, we can leave the cflags configuration here
+      #          However, when we do then it must be moved to our common module and/or just commented out
       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-multichar")
     endif()
   endif()
@@ -468,7 +429,7 @@ if(ASSEMBLY)
 
     # Urho3D - move the altivec, mmx, 3dnow, sse and sse2 checks to Urho3D common module which then configure the compiler flags globally
 
-    # Urho3D - bug fix - do not use "-mfpmath=387" in EXTRA_CFLAGS, instead let the compiler to choose what's the best by itself (i.e. '387' for x86 and 'sse' for x86_64) and also to keep SDL library being built with the same option as all the other Urho3D software; besides the '387' is invalid when targeting arm64
+    # Urho3D - bug fix - do not use "-mfpmath=387" in EXTRA_CFLAGS, instead let the compiler to choose what's the best by itself (i.e. '387' for x86 and 'sse' for x86_64) and also to keep SDL library being built with the same option as Urho3D library and all the other 3rd-party sub-libraries; besides the '387' is invalid when targeting arm64
 
     # Urho3D - commented out the HAVE_SSEMATH variable as it is not being used anywhere currently; furthermore compiler already emits __SSE_MATH__ or __SSE2_MATH__ as necessary on x86_64 ABI only; so instead of using HAVE_SSEMATH variable, we should actually use the __SSE_MATH__ or __SSE2_MATH__ compiler define if that is the original intention of having this variable
 
@@ -510,7 +471,26 @@ if(LIBC)
     set(STDC_HEADERS 1)
   else()
     set(HAVE_LIBC TRUE)
+    # Urho3D - bug fix - starting since Raspbian Jessie the __USE_EXTERN_INLINE is defined in <features.h> causing stdlib.h to look for <bits/stdlib-bsearch.h> which is not in the system header search path on Raspberry-Pi platform
+    if (RPI)
+      find_path (STDLIB_BITS_INCLUDE_DIR NAMES bits/stdlib-bsearch.h PATH_SUFFIXES arm-linux-gnueabihf DOC "Raspberry-Pi stdlib's bits include directory")
+      if (STDLIB_BITS_INCLUDE_DIR)
+        include_directories (${STDLIB_BITS_INCLUDE_DIR})
+      endif ()
+    endif ()
+    # Urho3D - bug fix - when cross-compiling the headers are rooted, either use "--sysroot" compiler flag or use CMAKE_REQUIRED_INCLUDES (e.g. on RPI) to cater for it
+    set (CMAKE_REQUIRED_INCLUDES_SYS_TYPES_SAVED ${CMAKE_REQUIRED_INCLUDES})
+    if (CMAKE_CROSSCOMPILING AND NOT "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}" MATCHES sysroot)
+      find_path (SYS_TYPES_H_INCLUDE_DIRS NAMES sys/types.h)
+      if (SYS_TYPES_H_INCLUDE_DIRS)
+        # Assume the header search path has not been adjusted elsewhere yet, there is no harm anyway when a same entry is added twice into the list
+        list (APPEND CMAKE_REQUIRED_INCLUDES ${SYS_TYPES_H_INCLUDE_DIRS})
+      endif ()
+    endif ()
     check_include_file(sys/types.h HAVE_SYS_TYPES_H)
+    set (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_SYS_TYPES_SAVED})
+    # Urho3D - no fix required - it seems all the compiler toolchains (native and X-compiling) that have been tested are able to find these headers correctly
+    #          Android NDK is able to find these headers with the help of "--sysroot" compiler flags, while others like MinGW and Linaro GCC for RPI work out of box
     foreach(_HEADER
             stdio.h stdlib.h stddef.h stdarg.h malloc.h memory.h string.h
             strings.h inttypes.h stdint.h ctype.h math.h iconv.h signal.h)
@@ -518,14 +498,16 @@ if(LIBC)
       string(REPLACE "." "_" _HAVE_H ${_UPPER})
       check_include_file("${_HEADER}" ${_HAVE_H})
     endforeach()
-
-    check_include_files("dlfcn.h;stdint.h;stddef.h;inttypes.h;stdlib.h;strings.h;string.h;float.h" STDC_HEADERS)
+    # Urho3D - bug fix - MinGW has standard-C headers, except dlfcn.h
+    set (CHECK_STDC_HEADERS stdint.h stddef.h inttypes.h stdlib.h strings.h string.h float.h)
+    if (NOT MINGW)
+      list (APPEND CHECK_STDC_HEADERS dlfcn.h)
+    endif ()
+    check_include_files("${CHECK_STDC_HEADERS}" STDC_HEADERS)   # Stringify the INCLUDE list variable as this macro does not expect to receive a list
     check_type_size("size_t" SIZEOF_SIZE_T)
     check_symbol_exists(M_PI math.h HAVE_M_PI)
-    # TODO: refine the mprotect check
-    check_c_source_compiles("#include <sys/types.h>
-                             #include <sys/mman.h>
-                             int main() { }" HAVE_MPROTECT)
+    # Urho3D - for consistency sake use check_include_file() to check for HAVE_MPROTECT
+    check_include_file (sys/mman.h HAVE_MPROTECT)
     foreach(_FN
             strtod malloc calloc realloc free getenv setenv putenv unsetenv
             qsort abs bcopy memset memcpy memmove memcmp strlen strlcpy strlcat
@@ -560,13 +542,13 @@ if(LIBC)
       set(HAVE_ICONV 1)
     endif()
 
-    if(NOT APPLE)
-      check_include_file(alloca.h HAVE_ALLOCA_H)
-      check_function_exists(alloca HAVE_ALLOCA)
-    else()
-      set(HAVE_ALLOCA_H 1)
-      set(HAVE_ALLOCA 1)
-    endif()
+    # Urho3D - bug fix - cannot use check_function_exists() with alloca; with this bug fixed, the same check should work on Apple too so no more hardcoding
+    check_include_file(alloca.h HAVE_ALLOCA_H)
+    if (HAVE_ALLOCA_H)
+      check_c_source_compiles ("
+        #include <alloca.h>
+        int main(int argc, char** argv) { alloca(0); }" HAVE_ALLOCA)
+    endif ()
 
     check_struct_has_member("struct sigaction" "sa_sigaction" "signal.h" HAVE_SA_SIGACTION)
   endif()
@@ -644,8 +626,6 @@ if(ANDROID)
   file(GLOB ANDROID_CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/android/*.c)
   set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_CORE_SOURCES})
   # Urho3D - bug fix - SDL_android_main.c will be added later when setting up actual Android targets
-#  file(GLOB ANDROID_MAIN_SOURCES ${SDL2_SOURCE_DIR}/src/main/android/*.c)
-#  set(SOURCE_FILES ${SOURCE_FILES} ${ANDROID_MAIN_SOURCES})
   if(SDL_AUDIO)
     set(SDL_AUDIO_DRIVER_ANDROID 1)
     file(GLOB ANDROID_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/android/*.c)
@@ -770,7 +750,9 @@ elseif(UNIX AND NOT APPLE)
     CheckVivante()
   endif()
 
-  if(LINUX)
+  # Urho3D - bug fix - CMake only supports 'Android' as a platform since 3.1.0, prior to that version the CMake/Android toolchain has to masquerade it as 'Linux' platform
+  #          So, we have to make sure Linux input event handling is not being enabled for Android platform when older CMake is used
+  if(LINUX AND NOT ANDROID)
     check_c_source_compiles("
         #include <linux/input.h>
         #ifndef EVIOCGNAME
@@ -807,34 +789,60 @@ elseif(UNIX AND NOT APPLE)
       set(SDL_INPUT_LINUXKD 1)
     endif()
 
-    # Urho3D - bug fix - do not use check_include_file() command for detection as it only works for host environment and not for rooted environment when cross-compiling
-    find_path (HAVE_LIBUDEV_H NAMES libudev.h)
-    find_path (HAVE_DBUS_DBUS_H NAMES dbus/dbus.h PATH_SUFFIXES dbus-1.0)
-    if (URHO3D_64BIT)   # Cater for both 32/64bit Redhat-based and Debian-based distros
+    # Urho3D - bug fix - when cross-compiling the headers are rooted, either use "--sysroot" compiler flag or use CMAKE_REQUIRED_INCLUDES (e.g. on RPI) to cater for it
+    set (CMAKE_REQUIRED_INCLUDES_UDEV_DBUS_SAVED ${CMAKE_REQUIRED_INCLUDES})
+    if (CMAKE_CROSSCOMPILING AND NOT "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}" MATCHES sysroot)
+      find_path (UDEV_H_INCLUDE_DIRS libudev.h)
+      if (UDEV_H_INCLUDE_DIRS)
+        list (APPEND CMAKE_REQUIRED_INCLUDES ${UDEV_H_INCLUDE_DIRS} ${SYS_TYPES_H_INCLUDE_DIRS})
+      endif ()
+    endif ()
+    check_include_file("libudev.h" HAVE_LIBUDEV_H)
+    if (HAVE_LIBUDEV_H AND UDEV_H_INCLUDE_DIRS)
+      include_directories (${UDEV_H_INCLUDE_DIRS})
+    endif ()
+    # Urho3D - bug fix - dbus/dbus.h is installed under path suffix 'dbus-1.0', so the following find_path() is needed even when not cross-compiling
+    find_path (DBUS_H_INCLUDE_DIRS NAMES dbus/dbus.h PATH_SUFFIXES dbus-1.0)
+    # Cater for both 32/64bit Redhat-based/Debian-based distros and 32-bit Raspberry-Pi as dbus-arch-deps header search paths are a little bit unusual
+    # FIXME: Is there a better way than hardcoding these?
+    if (URHO3D_64BIT)
       set (DBUS_INC_SEARCH_PATH /usr/lib64/dbus-1.0/include /usr/lib/x86_64-linux-gnu/dbus-1.0/include)
     else ()
-      set (DBUS_INC_SEARCH_PATH /usr/lib/dbus-1.0/include /usr/lib/i386-linux-gnu/dbus-1.0/include)
+      set (DBUS_INC_SEARCH_PATH /usr/lib/dbus-1.0/include /usr/lib/i386-linux-gnu/dbus-1.0/include /usr/lib/arm-linux-gnueabihf/dbus-1.0/include)
     endif ()
-    find_path (HAVE_DBUS_DBUS_ARCH_DEPS_H NAMES dbus/dbus-arch-deps.h PATHS ${DBUS_INC_SEARCH_PATH})
-    if (HAVE_LIBUDEV_H AND HAVE_DBUS_DBUS_H AND HAVE_DBUS_DBUS_ARCH_DEPS_H)
-      # All or nothing
-      include_directories (${HAVE_LIBUDEV_H} ${HAVE_DBUS_DBUS_H} ${HAVE_DBUS_DBUS_ARCH_DEPS_H})
-    else ()
-      foreach (VAR HAVE_LIBUDEV_H HAVE_DBUS_DBUS_H HAVE_DBUS_DBUS_ARCH_DEPS_H)
-        unset (${VAR} CACHE)
-        unset (${VAR})
-      endforeach()
+    find_path (DBUS_ARCH_DEPS_H_INCLUDE_DIRS NAMES dbus/dbus-arch-deps.h PATHS ${DBUS_INC_SEARCH_PATH})
+    set (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_UDEV_DBUS_SAVED} ${DBUS_H_INCLUDE_DIRS} ${DBUS_ARCH_DEPS_H_INCLUDE_DIRS})
+    check_include_file("dbus/dbus.h" HAVE_DBUS_DBUS_H)
+    if (HAVE_DBUS_DBUS_H AND DBUS_H_INCLUDE_DIRS AND DBUS_ARCH_DEPS_H_INCLUDE_DIRS)
+      include_directories (${DBUS_H_INCLUDE_DIRS} ${DBUS_ARCH_DEPS_H_INCLUDE_DIRS})
     endif ()
+    set (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_UDEV_DBUS_SAVED})
+
+    # Urho3D - bug fix - moved below logic from generic Unix block to Linux-specific block; this also prevents Linux power management from being enabled for Android platform when CMake prior to 3.1.0 is used
+    if(SDL_POWER)
+      set(SDL_POWER_LINUX 1)
+      file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/linux/*.c)
+      set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
+      set(HAVE_SDL_POWER TRUE)
+    endif()
   endif()
 
   if(INPUT_TSLIB)
-    check_c_source_compiles("
-        #include \"tslib.h\"
-        int main(int argc, char** argv) { }" HAVE_INPUT_TSLIB)
+    # Urho3D - bug fix - when cross-compiling the headers are rooted, either use "--sysroot" compiler flag or use CMAKE_REQUIRED_INCLUDES (e.g. on RPI) to cater for it
+    set (CMAKE_REQUIRED_INCLUDES_TSLIB_SAVED ${CMAKE_REQUIRED_INCLUDES})
+    if (CMAKE_CROSSCOMPILING AND NOT "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}" MATCHES sysroot)
+      find_path (TSLIB_H_INCLUDE_DIRS NAMES tslib.h)
+      if (TSLIB_H_INCLUDE_DIRS)
+        # Assume the header search path has not been adjusted elsewhere yet, there is no harm anyway when a same entry is added twice into the list
+        list (APPEND CMAKE_REQUIRED_INCLUDES ${TSLIB_H_INCLUDE_DIRS})
+      endif ()
+    endif ()
+    check_include_file (tslib.h HAVE_INPUT_TSLIB)
     if(HAVE_INPUT_TSLIB)
       set(SDL_INPUT_TSLIB 1)
       list(APPEND EXTRA_LIBS ts)
     endif()
+    set (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_TSLIB_SAVED})
   endif()
 
   if(SDL_JOYSTICK)
@@ -862,19 +870,7 @@ elseif(UNIX AND NOT APPLE)
     endif()
   endif()
 
-  check_include_file(linux/version.h HAVE_LINUX_VERSION_H)
-  if(HAVE_LINUX_VERSION_H)
-    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_LINUX_VERSION_H")
-  endif()
-
-  if(SDL_POWER)
-    if(LINUX)
-      set(SDL_POWER_LINUX 1)
-      file(GLOB POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/linux/*.c)
-      set(SOURCE_FILES ${SOURCE_FILES} ${POWER_SOURCES})
-      set(HAVE_SDL_POWER TRUE)
-    endif()
-  endif()
+  # Urho3D - commented out setting of HAVE_LINUX_VERSION_H compiler define via cflags as that define is not being used at all, besides we prefer add_definitions()
 
   # Urho3D - bug fix - do not use Unix filesystem for Android platform
   if(SDL_FILESYSTEM AND NOT ANDROID)
@@ -898,17 +894,22 @@ elseif(UNIX AND NOT APPLE)
     elseif(SOLARIS)
       set(SDL_RLD_FLAGS "-R\${libdir}")
     endif()
-    # Urho3D - commented out as we have configured our RPATH setup globally
-    #set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
+    # Urho3D - commented out RPATH setup as we have configured ours globally
     set(HAVE_RPATH TRUE)
   endif()
 
 elseif(WINDOWS)
-  find_program(WINDRES windres)
+  # Urho3D - bug fix - when using MinGW in cross-compiling build, the windres tool is being prefixed as other GCC cross-compiling tools
+  if (MINGW)
+    if (CMAKE_CROSSCOMPILING)
+      set (WINDRES ${CMAKE_RC_COMPILER})  # The CMAKE_RC_COMPILER variable is already initialized in our CMake/MinGW toolchain file
+    else ()
+      find_program(WINDRES windres)
+    endif ()
+  endif ()
 
-  check_c_source_compiles("
-    #include <windows.h>
-    int main(int argc, char **argv) { }" HAVE_WIN32_CC)
+  # Urho3D - replace the windows.h check by using check_include_file() instead of check_c_source_files()
+  check_include_file (windows.h HAVE_WIN32_CC)
 
   file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
   set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
@@ -927,16 +928,8 @@ elseif(WINDOWS)
       set(CMAKE_REQUIRED_FLAGS "/I\"$ENV{DXSDK_DIR}\\Include\"")
     endif()
 
-    if(HAVE_WIN32_CC)
-      # xinput.h may need windows.h, but doesn't include it itself.
-      check_c_source_compiles("
-        #include <windows.h>
-        #include <xinput.h>
-        int main(int argc, char **argv) { }" HAVE_XINPUT_H)
-    else()
-      check_include_file(xinput.h HAVE_XINPUT_H)
-    endif()
-
+    # Urho3D - simplify the check for xinput.h
+    check_include_file(xinput.h HAVE_XINPUT_H)
     check_include_file(d3d9.h HAVE_D3D_H)
     check_include_file(d3d11_1.h HAVE_D3D11_H)
     check_include_file(ddraw.h HAVE_DDRAW_H)
@@ -1319,9 +1312,7 @@ set(EXTRA_CFLAGS ${_EXTRA_CFLAGS})
 
 # Compat helpers for the configuration files
 if(NOT WINDOWS OR CYGWIN)
-# Urho3D - the script won't work on Linux too as it assumes hg to be the version source control which is not the case in our case
-#  # TODO: we need a Windows script, too
-#  execute_process(COMMAND sh ${SDL2_SOURCE_DIR}/build-scripts/updaterev.sh)
+# Urho3D - commeted out the call to updaterev.sh script as it won't work on any platform as it assumes hg to be the version source control which is not the case in our case
 
   set(prefix ${CMAKE_INSTALL_PREFIX})
   set(exec_prefix "\${prefix}")
@@ -1356,18 +1347,12 @@ if(NOT WINDOWS OR CYGWIN)
   # MESSAGE(STATUS "SDL_STATIC_LIBS: ${SDL_STATIC_LIBS}")
 
 # Urho3D - commented out pkg-config configuration file generation
-#  configure_file("${SDL2_SOURCE_DIR}/sdl2.pc.in"
-#    "${SDL2_BINARY_DIR}/sdl2.pc" @ONLY)
-#  configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
-#    "${SDL2_BINARY_DIR}/sdl2-config")
-#  configure_file("${SDL2_SOURCE_DIR}/sdl2-config.in"
-#    "${SDL2_BINARY_DIR}/sdl2-config" @ONLY)
-#  configure_file("${SDL2_SOURCE_DIR}/SDL2.spec.in"
-#    "${SDL2_BINARY_DIR}/SDL2.spec" @ONLY)
 endif()
 
 # Urho3D - restore the original CMake global settings
-set(CMAKE_REQUIRED_INCLUDES ${ORIG_CMAKE_REQUIRED_INCLUDES})
+set (CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
+set (CMAKE_REQUIRED_INCLUDES ${ORIG_CMAKE_REQUIRED_INCLUDES})
+set (CMAKE_REQUIRED_LIBRARIES ${ORIG_CMAKE_REQUIRED_LIBRARIES})
 
 # Urho3D - only echo the status once during initial configuration
 if (NOT SDL_INFO_ECHOED_STATUS)

+ 64 - 64
Source/ThirdParty/SDL/cmake/sdlchecks.cmake

@@ -161,6 +161,7 @@ macro(CheckALSA)
       get_filename_component (ALSA_INCLUDE_DIRS ${ALSA_INCLUDE_DIRS} PATH)
     endif ()
     if(ALSA_FOUND)
+      include_directories (${ALSA_INCLUDE_DIRS})
       set(HAVE_ALSA TRUE)
       file(GLOB ALSA_SOURCES ${SDL2_SOURCE_DIR}/src/audio/alsa/*.c)
       set(SOURCE_FILES ${SOURCE_FILES} ${ALSA_SOURCES})
@@ -191,11 +192,12 @@ macro(CheckPulseAudio)
     # Urho3D - bug fix - do not use pkg-config tool for detection as it only works for host environment and not for rooted environment when cross-compiling
     find_package (PulseAudio)
     if(PULSEAUDIO_FOUND)
+      include_directories (${PULSEAUDIO_INCLUDE_DIRS})
       set(HAVE_PULSEAUDIO TRUE)
       file(GLOB PULSEAUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/pulseaudio/*.c)
       set(SOURCE_FILES ${SOURCE_FILES} ${PULSEAUDIO_SOURCES})
       set(SDL_AUDIO_DRIVER_PULSEAUDIO 1)
-      # Urho3D - commented out appending EXTRA_CFLAGS for compiling PulseAudio, there should not be any except "-D_REENTRANT" which is also redundant for our configuration setup as we use '-pthread' compiler flags to do the right things automatically
+      # Urho3D - commented out appending EXTRA_CFLAGS for compiling with PulseAudio, there should not be any except "-D_REENTRANT" which is also redundant for our configuration setup as we use '-pthread' compiler flags to do the right things automatically
       if(PULSEAUDIO_SHARED)
         if(NOT HAVE_DLOPEN)
           message_warn("You must have SDL_LoadObject() support for dynamic PulseAudio loading")
@@ -205,10 +207,9 @@ macro(CheckPulseAudio)
           set(HAVE_PULSEAUDIO_SHARED TRUE)
         endif()
       else()
-        list(APPEND EXTRA_LIBS pulse-simple pulse)
+        list (APPEND EXTRA_LIBS pulse-simple pulse)
       endif()
       set(HAVE_SDL_AUDIO TRUE)
-      include_directories (${PULSEAUDIO_INCLUDE_DIRS})
     endif()
   endif()
 endmacro()
@@ -223,11 +224,11 @@ macro(CheckESD)
     # Urho3D - bug fix - do not use pkg-config tool for detection as it only works for host environment and not for rooted environment when cross-compiling
     find_package (Esound)
     if(ESOUND_FOUND)
+      include_directories (${ESOUND_INCLUDE_DIRS})
       set(HAVE_ESD TRUE)
       file(GLOB ESD_SOURCES ${SDL2_SOURCE_DIR}/src/audio/esd/*.c)
       set(SOURCE_FILES ${SOURCE_FILES} ${ESD_SOURCES})
       set(SDL_AUDIO_DRIVER_ESD 1)
-      # Urho3D - commented out appending EXTRA_CFLAGS for compiling ESD, there should not be any anyway
       if(ESD_SHARED)
         if(NOT HAVE_DLOPEN)
           message_warn("You must have SDL_LoadObject() support for dynamic ESD loading")
@@ -237,10 +238,9 @@ macro(CheckESD)
           set(HAVE_ESD_SHARED TRUE)
         endif()
       else()
-        list(APPEND EXTRA_LIBS esd)
+        list (APPEND EXTRA_LIBS esd)
       endif()
       set(HAVE_SDL_AUDIO TRUE)
-      include_directories (${ESOUND_INCLUDE_DIRS})
     endif()
   endif()
 endmacro()
@@ -255,7 +255,7 @@ macro(CheckARTS)
     # Urho3D - bug fix - do not use (host) arts-config tool for detection as it only works for host environment and not for rooted environment when cross-compiling
     find_package (aRts)
     if(ARTS_FOUND)
-      # Urho3D - commented out appending EXTRA_CFLAGS for compiling aRts, there should not be any anyway
+      include_directories (${ARTS_INCLUDE_DIRS})
       file(GLOB ARTS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/arts/*.c)
       set(SOURCE_FILES ${SOURCE_FILES} ${ARTS_SOURCES})
       set(SDL_AUDIO_DRIVER_ARTS 1)
@@ -269,10 +269,9 @@ macro(CheckARTS)
           set(HAVE_ARTS_SHARED TRUE)
         endif()
       else()
-        list(APPEND EXTRA_LIBS artsc)
+        list (APPEND EXTRA_LIBS artsc)
       endif()
       set(HAVE_SDL_AUDIO TRUE)
-      include_directories (${ARTS_INCLUDE_DIRS}/artsc)
     endif()
   endif()
 endmacro()
@@ -284,10 +283,10 @@ endmacro()
 # - HAVE_DLOPEN opt
 macro(CheckNAS)
   if(NAS)
-    # TODO: set include paths properly, so the NAS headers are found
-    check_include_file(audio/audiolib.h HAVE_NAS_H)
-    find_library(D_NAS_LIB audio)
-    if(HAVE_NAS_H AND D_NAS_LIB)
+    # Urho3D - bug fix - do not use check_include_file() for detection as it only works for host environment and not for rooted environment when cross-compiling
+    find_package (NetworkAudioSystem)
+    if(NAS_FOUND)
+      include_directories (${NAS_INCLUDE_DIRS})
       set(HAVE_NAS TRUE)
       file(GLOB NAS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/nas/*.c)
       set(SOURCE_FILES ${SOURCE_FILES} ${NAS_SOURCES})
@@ -296,12 +295,12 @@ macro(CheckNAS)
         if(NOT HAVE_DLOPEN)
           message_warn("You must have SDL_LoadObject() support for dynamic NAS loading")
         else()
-          FindLibraryAndSONAME("audio")
+          get_filename_component (AUDIO_LIB_SONAME ${NAS_LIBRARIES} NAME)
           set(SDL_AUDIO_DRIVER_NAS_DYNAMIC "\"${AUDIO_LIB_SONAME}\"")
           set(HAVE_NAS_SHARED TRUE)
         endif()
       else()
-        list(APPEND EXTRA_LIBS ${D_NAS_LIB})
+        list (APPEND EXTRA_LIBS audio)
       endif()
       set(HAVE_SDL_AUDIO TRUE)
     endif()
@@ -315,10 +314,10 @@ endmacro()
 # - HAVE_DLOPEN opt
 macro(CheckSNDIO)
   if(SNDIO)
-    # TODO: set include paths properly, so the sndio headers are found
-    check_include_file(sndio.h HAVE_SNDIO_H)
-    find_library(D_SNDIO_LIB sndio)
-    if(HAVE_SNDIO_H AND D_SNDIO_LIB)
+    # Urho3D - bug fix - do not use check_include_file() for detection as it only works for host environment and not for rooted environment when cross-compiling
+    find_package (RoarAudio)
+    if(SNDIO_FOUND)
+      include_directories (${SNDIO_INCLUDE_DIRS})
       set(HAVE_SNDIO TRUE)
       file(GLOB SNDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sndio/*.c)
       set(SOURCE_FILES ${SOURCE_FILES} ${SNDIO_SOURCES})
@@ -327,12 +326,12 @@ macro(CheckSNDIO)
         if(NOT HAVE_DLOPEN)
           message_warn("You must have SDL_LoadObject() support for dynamic sndio loading")
         else()
-          FindLibraryAndSONAME("sndio")
+          get_filename_component (SNDIO_LIB_SONAME ${SNDIO_LIBRARIES} NAME)
           set(SDL_AUDIO_DRIVER_SNDIO_DYNAMIC "\"${SNDIO_LIB_SONAME}\"")
           set(HAVE_SNDIO_SHARED TRUE)
         endif()
       else()
-        list(APPEND EXTRA_LIBS ${D_SNDIO_LIB})
+        list(APPEND EXTRA_LIBS sndio)
       endif()
       set(HAVE_SDL_AUDIO TRUE)
     endif()
@@ -349,6 +348,7 @@ macro(CheckFusionSound)
     # Urho3D - bug fix - do not use pkg-config tool for detection as it only works for host environment and not for rooted environment when cross-compiling
     find_package (FusionSound 1.0.0)
     if(FUSIONSOUND_FOUND)
+      include_directories (${FUSIONSOUND_INCLUDE_DIRS})
       set(HAVE_FUSIONSOUND TRUE)
       file(GLOB FUSIONSOUND_SOURCES ${SDL2_SOURCE_DIR}/src/audio/fusionsound/*.c)
       set(SOURCE_FILES ${SOURCE_FILES} ${FUSIONSOUND_SOURCES})
@@ -362,10 +362,9 @@ macro(CheckFusionSound)
           set(HAVE_FUSIONSOUND_SHARED TRUE)
         endif()
       else()
-        list(APPEND EXTRA_LIBS fusionsound)
+        list (APPEND EXTRA_LIBS fusionsound)
       endif()
       set(HAVE_SDL_AUDIO TRUE)
-      include_directories (${FUSIONSOUND_INCLUDE_DIRS})
     endif()
   endif()
 endmacro()
@@ -377,6 +376,7 @@ endmacro()
 # - HAVE_DLOPEN opt
 macro(CheckX11)
   if(VIDEO_X11)
+    # Urho3D - no fix required - all these checks below work on native Linux build only, e.g. they would not work on RPI (native or X-compile) which is fortunately a good thing
     foreach(_LIB X11 Xext Xcursor Xinerama Xi Xrandr Xrender Xss Xxf86vm)
         FindLibraryAndSONAME("${_LIB}")
     endforeach()
@@ -435,7 +435,8 @@ macro(CheckX11)
           set(SDL_VIDEO_DRIVER_X11_DYNAMIC "\"${X11_LIB_SONAME}\"")
           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "\"${XEXT_LIB_SONAME}\"")
         else()
-          list(APPEND EXTRA_LIBS ${X11_LIB} ${XEXT_LIB})
+          # Urho3D - bug fix - the EXTRA_LIBS is list of library names (not the fully-qualified path to the library itself)
+          list (APPEND EXTRA_LIBS X11 Xext)
         endif()
       endif()
 
@@ -473,7 +474,7 @@ macro(CheckX11)
         if(HAVE_X11_SHARED AND XCURSOR_LIB)
           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "\"${XCURSOR_LIB_SONAME}\"")
         else()
-          list(APPEND EXTRA_LIBS ${XCURSOR_LIB})
+          list (APPEND EXTRA_LIBS Xcursor)
         endif()
         set(SDL_VIDEO_DRIVER_X11_XCURSOR 1)
       endif()
@@ -483,7 +484,7 @@ macro(CheckX11)
         if(HAVE_X11_SHARED AND XINERAMA_LIB)
           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "\"${XINERAMA_LIB_SONAME}\"")
         else()
-          list(APPEND EXTRA_LIBS ${XINERAMA_LIB})
+          list (APPEND EXTRA_LIBS Xinerama)
         endif()
         set(SDL_VIDEO_DRIVER_X11_XINERAMA 1)
       endif()
@@ -493,7 +494,7 @@ macro(CheckX11)
         if(HAVE_X11_SHARED AND XI_LIB)
           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "\"${XI_LIB_SONAME}\"")
         else()
-          list(APPEND EXTRA_LIBS ${XI_LIB})
+          list (APPEND EXTRA_LIBS Xi)
         endif()
         set(SDL_VIDEO_DRIVER_X11_XINPUT2 1)
 
@@ -518,7 +519,7 @@ macro(CheckX11)
         if(HAVE_X11_SHARED AND XRANDR_LIB)
           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "\"${XRANDR_LIB_SONAME}\"")
         else()
-          list(APPEND EXTRA_LIBS ${XRANDR_LIB})
+          list (APPEND EXTRA_LIBS Xrandr)
         endif()
         set(SDL_VIDEO_DRIVER_X11_XRANDR 1)
         set(HAVE_VIDEO_X11_XRANDR TRUE)
@@ -528,7 +529,7 @@ macro(CheckX11)
         if(HAVE_X11_SHARED AND XSS_LIB)
           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "\"${XSS_LIB_SONAME}\"")
         else()
-          list(APPEND EXTRA_LIBS ${XSS_LIB})
+          list (APPEND EXTRA_LIBS Xss)
         endif()
         set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1)
         set(HAVE_VIDEO_X11_XSCRNSAVER TRUE)
@@ -543,7 +544,7 @@ macro(CheckX11)
         if(HAVE_X11_SHARED AND XXF86VM_LIB)
           set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "\"${XXF86VM_LIB_SONAME}\"")
         else()
-          list(APPEND EXTRA_LIBS ${XXF86VM_LIB})
+          list (APPEND EXTRA_LIBS Xxf86vm)
         endif()
         set(SDL_VIDEO_DRIVER_X11_XVIDMODE 1)
         set(HAVE_VIDEO_X11_XVM TRUE)
@@ -565,6 +566,7 @@ macro(CheckMir)
         # Urho3D - bug fix - do not use pkg-config tool for detection as it only works for host environment and not for rooted environment when cross-compiling
         find_package (Mir)
         if (MIR_FOUND)
+            include_directories (${MIR_INCLUDE_DIRS})
             set(HAVE_VIDEO_MIR TRUE)
             set(HAVE_SDL_VIDEO TRUE)
 
@@ -585,7 +587,6 @@ macro(CheckMir)
             else()
                 list (APPEND EXTRA_LIBS mirclient xkbcommon)
             endif()
-            include_directories (${MIR_INCLUDE_DIRS})
         endif()
     endif()
 endmacro()
@@ -601,12 +602,7 @@ macro(CheckWayland)
     # Urho3D - bug fix - do not use pkg-config tool for detection as it only works for host environment and not for rooted environment when cross-compiling
     find_package (Wayland)
     if(WAYLAND_FOUND)
-      link_directories(
-          ${WAYLAND_LIBRARY_DIRS}
-      )
-      include_directories(
-          ${WAYLAND_INCLUDE_DIRS}
-      )
+      include_directories (${WAYLAND_INCLUDE_DIRS})
       set(HAVE_VIDEO_WAYLAND TRUE)
       set(HAVE_SDL_VIDEO TRUE)
 
@@ -636,7 +632,6 @@ macro(CheckWayland)
       endif()
 
       set(SDL_VIDEO_DRIVER_WAYLAND 1)
-      include_directories (${WAYLAND_INCLUDE_DIRS})
     endif()
   endif()
 endmacro()
@@ -669,6 +664,7 @@ macro(CheckDirectFB)
     # Urho3D - bug fix - do not use pkg-config tool for detection as it only works for host environment and not for rooted environment when cross-compiling
     find_package (DirectFB 1.0.0)
     if(DIRECTFB_FOUND)
+      include_directories (${DIRECTFB_INCLUDE_DIRS})
       set(HAVE_VIDEO_DIRECTFB TRUE)
       file(GLOB DIRECTFB_SOURCES ${SDL2_SOURCE_DIR}/src/video/directfb/*.c)
       set(SOURCE_FILES ${SOURCE_FILES} ${DIRECTFB_SOURCES})
@@ -686,7 +682,6 @@ macro(CheckDirectFB)
         list(APPEND EXTRA_LIBS directfb)
       endif()
       set(HAVE_SDL_VIDEO TRUE)
-      include_directories (${DIRECTFB_INCLUDE_DIRS})
     endif()
   endif()
 endmacro()
@@ -695,6 +690,15 @@ endmacro()
 # - n/a
 macro(CheckVivante)
   if(VIDEO_VIVANTE)
+    # Urho3D - bug fix - when cross-compiling the headers are rooted, either use "--sysroot" compiler flag or use CMAKE_REQUIRED_INCLUDES (e.g. on RPI) to cater for it
+    set (CMAKE_REQUIRED_INCLUDES_VIVANTE_SAVED ${CMAKE_REQUIRED_INCLUDES})
+    if (CMAKE_CROSSCOMPILING AND NOT "${CMAKE_C_FLAGS} ${CMAKE_REQUIRED_FLAGS}" MATCHES sysroot)
+      find_path (VIVANTE_INCLUDE_DIRS NAMES gc_vdk.h EGL/eglvivante.h)
+      if (VIVANTE_INCLUDE_DIRS)
+        # Assume the header search path has not been adjusted elsewhere yet, there is no harm anyway when a same entry is added twice into the list
+        list (APPEND CMAKE_REQUIRED_INCLUDES ${VIVANTE_INCLUDE_DIRS})
+      endif ()
+    endif ()
     check_c_source_compiles("
         #include <gc_vdk.h>
         int main(int argc, char** argv) {}" HAVE_VIDEO_VIVANTE_VDK)
@@ -718,6 +722,7 @@ macro(CheckVivante)
         list(APPEND EXTRA_LIBS EGL)
       endif(HAVE_VIDEO_VIVANTE_VDK)
     endif(HAVE_VIDEO_VIVANTE_VDK OR HAVE_VIDEO_VIVANTE_EGL_FB)
+    set (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_VIVANTE_SAVED})
   endif(VIDEO_VIVANTE)
 endmacro(CheckVivante)
 
@@ -725,6 +730,10 @@ endmacro(CheckVivante)
 # - nada
 macro(CheckOpenGLX11)
   if(VIDEO_OPENGL)
+    # Urho3D - bug fix - when cross-compiling the headers are rooted, either use "--sysroot" option or use CMAKE_REQUIRED_INCLUDES (e.g. on RPI) to cater for it
+    if (CMAKE_CROSSCOMPILING AND SYSROOT AND NOT CMAKE_REQUIRED_INCLUDES)
+      set (CMAKE_REQUIRED_FLAGS "--sysroot=${SYSROOT}")
+    endif ()
     check_c_source_compiles("
         #include <GL/gl.h>
         #include <GL/glx.h>
@@ -737,6 +746,7 @@ macro(CheckOpenGLX11)
       set(SDL_VIDEO_RENDER_OGL 1)
       list(APPEND EXTRA_LIBS GL)
     endif()
+    set (CMAKE_REQUIRED_FLAGS)
   endif()
 endmacro()
 
@@ -744,7 +754,7 @@ endmacro()
 # - nada
 macro(CheckOpenGLESX11)
   if(VIDEO_OPENGLES)
-    # Urho3D - bug fix - when cross-compiling the headers are rooted, either use "--sysroot" option or use CMAKE_REQUIRED_INCLUDES (on RPI) to cater for it
+    # Urho3D - bug fix - when cross-compiling the headers are rooted, either use "--sysroot" option or use CMAKE_REQUIRED_INCLUDES (e.g. on RPI) to cater for it
     if (CMAKE_CROSSCOMPILING AND SYSROOT AND NOT CMAKE_REQUIRED_INCLUDES)
       set (CMAKE_REQUIRED_FLAGS "--sysroot=${SYSROOT}")
     endif ()
@@ -787,6 +797,7 @@ endmacro()
 # PTHREAD_LIBS
 macro(CheckPTHREAD)
   if(PTHREADS)
+    # Urho3D - TODO - below hardcoding is ugly and should be refactored/removed, however, we/I don't have all the necessary means to verify the changes
     if(LINUX)
       set(PTHREAD_CFLAGS "-D_REENTRANT")
       set(PTHREAD_LDFLAGS "-pthread")
@@ -829,7 +840,7 @@ macro(CheckPTHREAD)
 
     # Run some tests
     set(CMAKE_REQUIRED_FLAGS "${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
-    # Urho3D - bug fix - when cross-compiling the headers are rooted, either use "--sysroot" option or use CMAKE_REQUIRED_INCLUDES (on RPI) to cater for it
+    # Urho3D - bug fix - when cross-compiling the headers are rooted, either use "--sysroot" option or use CMAKE_REQUIRED_INCLUDES (e.g. on RPI) to cater for it
     if(CMAKE_CROSSCOMPILING)
       if (SYSROOT AND NOT CMAKE_REQUIRED_INCLUDES)
         set (CMAKE_REQUIRED_FLAGS "--sysroot=${SYSROOT}")
@@ -852,11 +863,9 @@ macro(CheckPTHREAD)
     endif()
     if(HAVE_PTHREADS)
       set(SDL_THREAD_PTHREAD 1)
-      # Urho3D - we only use "-pthread" compiler flags and expect the respective compiler toolchains to do the right things automatically
-#      list(APPEND EXTRA_CFLAGS ${PTHREAD_CFLAGS})
-#      list(APPEND EXTRA_LDFLAGS ${PTHREAD_LDFLAGS})
-#      set(SDL_CFLAGS "${SDL_CFLAGS} ${PTHREAD_CFLAGS}")
-#      list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
+      # Urho3D - we configure to use "-pthread" compiler flags globally (when it is supported) and expect the respective compiler toolchain to do the right things automatically
+      set(SDL_CFLAGS "${SDL_CFLAGS} ${PTHREAD_CFLAGS}")
+      list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
 
       check_c_source_compiles("
         #include <pthread.h>
@@ -881,10 +890,6 @@ macro(CheckPTHREAD)
       endif()
 
       if(PTHREADS_SEM)
-        # Urho3D - bug fix - when cross-compiling the headers are rooted, either use "--sysroot" option or use CMAKE_REQUIRED_INCLUDES (on RPI) to cater for it
-        if (CMAKE_CROSSCOMPILING AND SYSROOT AND NOT CMAKE_REQUIRED_INCLUDES)
-          set (CMAKE_REQUIRED_FLAGS "--sysroot=${SYSROOT}")
-        endif ()
         check_c_source_compiles("#include <pthread.h>
                                  #include <semaphore.h>
                                  int main(int argc, char **argv) { return 0; }" HAVE_PTHREADS_SEM)
@@ -932,6 +937,8 @@ endmacro()
 # USB_LIBS
 # USB_CFLAGS
 macro(CheckUSBHID)
+  # Urho3D - no fix required - all these checks appear to be for BSD only, assume only native build
+  #          Cannot fix them for X-compiling anyway as we/I don't have the necessary means to verify the changes
   check_library_exists(usbhid hid_init "" LIBUSBHID)
   if(LIBUSBHID)
     check_include_file(usbhid.h HAVE_USBHID_H)
@@ -1068,18 +1075,11 @@ endmacro()
 # - n/a
 macro(CheckRPI)
   if(VIDEO_RPI)
-    set(VIDEO_RPI_INCLUDE_DIRS "/opt/vc/include" "/opt/vc/include/interface/vcos/pthreads" "/opt/vc/include/interface/vmcs_host/linux/" )
-    set(VIDEO_RPI_LIBRARY_DIRS "/opt/vc/lib" )
-    set(VIDEO_RPI_LIBS bcm_host )
     # Urho3D - bug fix - when cross-compiling the headers are rooted
-    if (CMAKE_CROSSCOMPILING)
-      listtostr (VIDEOCORE_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I")
-      listtostr (VIDEOCORE_LIBRARIES VIDEO_RPI_LIBRARY_FLAGS "-L")
-    else ()
-      listtostr(VIDEO_RPI_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I")
-      listtostr(VIDEO_RPI_LIBRARY_DIRS VIDEO_RPI_LIBRARY_FLAGS "-L")
-    endif ()
-    set(CMAKE_REQUIRED_FLAGS "${SYSROOT_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
+    # Urho3D - TODO - move the find_package(VideoCore REQUIRED) call from Urho3D common module to here
+    listtostr (VIDEOCORE_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I")
+    listtostr (VIDEOCORE_LIBRARIES VIDEO_RPI_LIBRARY_FLAGS "-L")
+    set(CMAKE_REQUIRED_FLAGS "${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}")
     # Urho3D - bug fix - commented out CMAKE_REQUIRED_LIBRARIES as it actually causes the detection to fail
     check_c_source_compiles("
         #include <bcm_host.h>
@@ -1091,9 +1091,9 @@ macro(CheckRPI)
       set(SDL_VIDEO_DRIVER_RPI 1)
       file(GLOB VIDEO_RPI_SOURCES ${SDL2_SOURCE_DIR}/src/video/raspberry/*.c)
       set(SOURCE_FILES ${SOURCE_FILES} ${VIDEO_RPI_SOURCES})
-      list(APPEND EXTRA_LIBS ${VIDEO_RPI_LIBS})
-      # Urho3D - commented out CMAKE_C_FLAGS setup as we have already configured our compiler flags globally, instead just adjust the header search path
-      set (CMAKE_REQUIRED_INCLUDES ${VIDEOCORE_INCLUDE_DIRS})   # This is needed for subsequent checks for EGL and OpenGLES2 detection
+      list (APPEND EXTRA_LIBS bcm_host)
+      # Urho3D - bug fix - adjust the header search path for subsequent for EGL and OpenGLES2 checks
+      list (APPEND CMAKE_REQUIRED_INCLUDES ${VIDEOCORE_INCLUDE_DIRS})   # This global setting will be reset later to its previous value in SDL/CMakeLists.txt
     endif(SDL_VIDEO AND HAVE_VIDEO_RPI)
   endif(VIDEO_RPI)
 endmacro(CheckRPI)

+ 5 - 1
Source/ThirdParty/SDL/src/audio/arts/SDL_artsaudio.h

@@ -18,12 +18,16 @@
      misrepresented as being the original software.
   3. This notice may not be removed or altered from any source distribution.
 */
+
+// Modified by Yao Wei Tjong for Urho3D
+
 #include "../../SDL_internal.h"
 
 #ifndef _SDL_artscaudio_h
 #define _SDL_artscaudio_h
 
-#include <artsc.h>
+// Urho3D - bug fix - use the correct include path to avoid adding artsc-specific include directory into header search path
+#include <artsc/artsc.h>
 
 #include "../SDL_sysaudio.h"