Browse Source

Fix overlinking of EGL library in FindVideoCore.cmake module.
Remove hardcoding of indirect dependency libraries list in the FindUrho3D.cmake module. Instead we now rely on the linker to find those indirect dependencies automatically with our hint via "-runpath-link" linker flag, especially when cross-compiling.
Also setup GLESv2 (and GLESv1_CM) for Raspberry-Pi in the same manner as generic ARM and Android platforms.

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

+ 2 - 9
CMake/Modules/FindUrho3D.cmake

@@ -227,13 +227,7 @@ else ()
                 set (COMPILER_32BIT_FLAG -m32)
                 set (COMPILER_32BIT_FLAG -m32)
             endif ()
             endif ()
             # Below variables are loop invariant but there is no harm to keep them here
             # Below variables are loop invariant but there is no harm to keep them here
-            if (ANDROID)
-                # TODO - remove this hard-coding when we do the library dependency refactoring
-                set (DEP_LIBRARIES "log\;android\;GLESv1_CM\;GLESv2")
-            elseif (CMAKE_SYSTEM_NAME STREQUAL Linux AND ARM AND NOT RPI)
-                # TODO - remove this hard-coding when we do the library dependency refactoring
-                set (DEP_LIBRARIES "GLESv1_CM\;GLESv2")
-            elseif (WIN32)
+            if (WIN32)
                 set (CMAKE_TRY_COMPILE_CONFIGURATION_SAVED ${CMAKE_TRY_COMPILE_CONFIGURATION})
                 set (CMAKE_TRY_COMPILE_CONFIGURATION_SAVED ${CMAKE_TRY_COMPILE_CONFIGURATION})
                 if (URHO3D_LIBRARIES_REL)
                 if (URHO3D_LIBRARIES_REL)
                     set (CMAKE_TRY_COMPILE_CONFIGURATION Release)
                     set (CMAKE_TRY_COMPILE_CONFIGURATION Release)
@@ -264,9 +258,8 @@ else ()
             else ()
             else ()
                 set (COMPILER_FLAGS "${COMPILER_32BIT_FLAG} ${CMAKE_REQUIRED_FLAGS}")
                 set (COMPILER_FLAGS "${COMPILER_32BIT_FLAG} ${CMAKE_REQUIRED_FLAGS}")
                 while (NOT URHO3D_COMPILE_RESULT)
                 while (NOT URHO3D_COMPILE_RESULT)
-                    # VIDEOCORE_LIBRARIES variable is already set by FindVideoCore module on RPI platform
                     try_run (URHO3D_RUN_RESULT URHO3D_COMPILE_RESULT ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_LIST_DIR}/CheckUrho3DLibrary.cpp
                     try_run (URHO3D_RUN_RESULT URHO3D_COMPILE_RESULT ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_LIST_DIR}/CheckUrho3DLibrary.cpp
-                        CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${COMPILER_FLAGS} -DLINK_LIBRARIES:STRING=${URHO3D_LIBRARIES}\;${VIDEOCORE_LIBRARIES}\;${DEP_LIBRARIES} -DINCLUDE_DIRECTORIES:STRING=${URHO3D_INCLUDE_DIRS} ${COMPILER_STATIC_DEFINE} ${COMPILER_STATIC_RUNTIME_FLAGS}
+                        CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${COMPILER_FLAGS} -DLINK_LIBRARIES:STRING=${URHO3D_LIBRARIES} -DINCLUDE_DIRECTORIES:STRING=${URHO3D_INCLUDE_DIRS} ${COMPILER_STATIC_DEFINE} ${COMPILER_STATIC_RUNTIME_FLAGS}
                         COMPILE_OUTPUT_VARIABLE TRY_COMPILE_OUT RUN_OUTPUT_VARIABLE TRY_RUN_OUT)
                         COMPILE_OUTPUT_VARIABLE TRY_COMPILE_OUT RUN_OUTPUT_VARIABLE TRY_RUN_OUT)
                     if (MSVC AND NOT URHO3D_COMPILE_RESULT AND NOT COMPILER_STATIC_RUNTIME_FLAGS)
                     if (MSVC AND NOT URHO3D_COMPILE_RESULT AND NOT COMPILER_STATIC_RUNTIME_FLAGS)
                         # Give a second chance for MSVC to use static runtime flag
                         # Give a second chance for MSVC to use static runtime flag

+ 9 - 13
CMake/Modules/FindVideoCore.cmake

@@ -24,29 +24,25 @@
 #
 #
 #  VIDEOCORE_FOUND
 #  VIDEOCORE_FOUND
 #  VIDEOCORE_INCLUDE_DIRS
 #  VIDEOCORE_INCLUDE_DIRS
+#  VIDEOCORE_LIBRARY_DIRS
 #  VIDEOCORE_LIBRARIES
 #  VIDEOCORE_LIBRARIES
-#  VIDEOCORE_BCM_HOST
-#  VIDEOCORE_EGL
-#  VIDEOCORE_GLES2
 #
 #
 
 
 # Only need to cater for raspbian as they are not in CMAKE_SYSTEM_PATH
 # Only need to cater for raspbian as they are not in CMAKE_SYSTEM_PATH
 set (VIDEOCORE_INC_SEARCH_PATH /opt/vc/include)
 set (VIDEOCORE_INC_SEARCH_PATH /opt/vc/include)
 set (VIDEOCORE_LIB_SEARCH_PATH /opt/vc/lib)
 set (VIDEOCORE_LIB_SEARCH_PATH /opt/vc/lib)
 
 
-# Assume all the other headers are installed at same relative path as bcm_host.h
 find_path (VIDEOCORE_INCLUDE_DIRS bcm_host.h PATHS ${VIDEOCORE_INC_SEARCH_PATH} PATH_SUFFIXES vc DOC "Broadcom VideoCore include directory")
 find_path (VIDEOCORE_INCLUDE_DIRS bcm_host.h PATHS ${VIDEOCORE_INC_SEARCH_PATH} PATH_SUFFIXES vc DOC "Broadcom VideoCore include directory")
-
-# Assume all the other libs are installed at the same relative path as libbcm_host.so
-find_library (VIDEOCORE_BCM_HOST bcm_host PATHS ${VIDEOCORE_LIB_SEARCH_PATH} PATH_SUFFIXES vc DOC "Broadcom VideoCore BCM_HOST library")
-find_library (VIDEOCORE_EGL EGL PATHS ${VIDEOCORE_LIB_SEARCH_PATH} PATH_SUFFIXES vc DOC "Broadcom VideoCore EGL library")
-find_library (VIDEOCORE_GLES2 GLESv2 PATHS ${VIDEOCORE_LIB_SEARCH_PATH} PATH_SUFFIXES vc DOC "Broadcom VideoCore GLESv2 library")
+find_library (VIDEOCORE_LIBRARIES bcm_host PATHS ${VIDEOCORE_LIB_SEARCH_PATH} PATH_SUFFIXES vc DOC "Broadcom VideoCore BCM_HOST library")
 
 
 include (FindPackageHandleStandardArgs)
 include (FindPackageHandleStandardArgs)
-find_package_handle_standard_args (VideoCore REQUIRED_VARS VIDEOCORE_BCM_HOST VIDEOCORE_EGL VIDEOCORE_GLES2 VIDEOCORE_INCLUDE_DIRS FAIL_MESSAGE "Could NOT find Broadcom VideoCore firmware")
+find_package_handle_standard_args (VideoCore REQUIRED_VARS VIDEOCORE_LIBRARIES VIDEOCORE_INCLUDE_DIRS FAIL_MESSAGE "Could NOT find Broadcom VideoCore firmware")
 if (VIDEOCORE_FOUND)
 if (VIDEOCORE_FOUND)
-    list (APPEND VIDEOCORE_INCLUDE_DIRS ${VIDEOCORE_INCLUDE_DIRS}/interface/vcos/pthreads ${VIDEOCORE_INCLUDE_DIRS}/interface/vmcs_host/linux)  # Note: variable change to list context after this
-    set (VIDEOCORE_LIBRARIES ${VIDEOCORE_BCM_HOST} ${VIDEOCORE_EGL} ${VIDEOCORE_GLES2})
+    # Assume all the other headers are installed at same relative path as bcm_host.h
+    list (APPEND VIDEOCORE_INCLUDE_DIRS ${VIDEOCORE_INCLUDE_DIRS}/interface/vcos/pthreads ${VIDEOCORE_INCLUDE_DIRS}/interface/vmcs_host/linux)
+    # Assume all the other libraries are installed at same relative path as libbcm_host.so
+    get_filename_component (VIDEOCORE_LIBRARY_DIRS ${VIDEOCORE_LIBRARIES} PATH)
+    set (VIDEOCORE_LIBRARIES bcm_host)
 endif ()
 endif ()
 
 
-mark_as_advanced (VIDEOCORE_INCLUDE_DIRS VIDEOCORE_BCM_HOST VIDEOCORE_EGL VIDEOCORE_GLES2)
+mark_as_advanced (VIDEOCORE_INCLUDE_DIRS VIDEOCORE_LIBRARIES)

+ 15 - 11
CMake/Modules/Urho3D-CMake-common.cmake

@@ -79,16 +79,22 @@ elseif (XCODE)
     endif ()
     endif ()
 endif ()
 endif ()
 
 
-# Extra linker flags for linking against indirect dependencies (linking shared lib with dependencies) when in cross-compiling mode
+include (CheckHost)
+include (CheckCompilerToolchain)
+
+# Extra linker flags for linking against indirect dependencies (linking shared lib with dependencies)
+if (RPI)
+    # Extra linker flags for Raspbian because it installs VideoCore libraries in the "/opt/vc/lib" directory (no harm in doing so for other distros)
+    set (INDIRECT_DEPS_EXE_LINKER_FLAGS "${INDIRECT_DEPS_EXE_LINKER_FLAGS} -Wl,-rpath-link,\"${RPI_SYSROOT}/opt/vc/lib\"")      # RPI_SYSROOT is empty when not cross-compiling
+endif ()
 if (ARM AND CMAKE_SYSTEM_NAME STREQUAL Linux AND CMAKE_CROSSCOMPILING)
 if (ARM AND CMAKE_SYSTEM_NAME STREQUAL Linux AND CMAKE_CROSSCOMPILING)
     # Cannot do this in the toolchain file because CMAKE_LIBRARY_ARCHITECTURE is not yet defined when CMake is processing toolchain file
     # Cannot do this in the toolchain file because CMAKE_LIBRARY_ARCHITECTURE is not yet defined when CMake is processing toolchain file
-    set (ROOTED_EXE_LINKER_FLAGS "-Wl,-rpath-link,\"${ARM_SYSROOT}/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}\":\"${ARM_SYSROOT}/lib/${CMAKE_LIBRARY_ARCHITECTURE}\"")
-    set (CMAKE_REQUIRED_FLAGS ${ROOTED_EXE_LINKER_FLAGS})
+    set (INDIRECT_DEPS_EXE_LINKER_FLAGS "${INDIRECT_DEPS_EXE_LINKER_FLAGS} -Wl,-rpath-link,\"${ARM_SYSROOT}/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}\":\"${ARM_SYSROOT}/lib/${CMAKE_LIBRARY_ARCHITECTURE}\"")
 endif ()
 endif ()
+set (CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${INDIRECT_DEPS_EXE_LINKER_FLAGS}")
+set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${INDIRECT_DEPS_EXE_LINKER_FLAGS}")
 
 
 # Define all supported build options
 # Define all supported build options
-include (CheckHost)
-include (CheckCompilerToolchain)
 include (CMakeDependentOption)
 include (CMakeDependentOption)
 option (URHO3D_C++11 "Enable C++11 standard")
 option (URHO3D_C++11 "Enable C++11 standard")
 cmake_dependent_option (IOS "Setup build for iOS platform" FALSE "XCODE" FALSE)
 cmake_dependent_option (IOS "Setup build for iOS platform" FALSE "XCODE" FALSE)
@@ -111,6 +117,7 @@ if (RPI)
     # TODO: this logic is earmarked to be moved into SDL's CMakeLists.txt when refactoring the library dependency handling
     # TODO: this logic is earmarked to be moved into SDL's CMakeLists.txt when refactoring the library dependency handling
     find_package (VideoCore REQUIRED)
     find_package (VideoCore REQUIRED)
     include_directories (${VIDEOCORE_INCLUDE_DIRS})
     include_directories (${VIDEOCORE_INCLUDE_DIRS})
+    link_directories (${VIDEOCORE_LIBRARY_DIRS})
 endif ()
 endif ()
 if (CMAKE_PROJECT_NAME STREQUAL Urho3D)
 if (CMAKE_PROJECT_NAME STREQUAL Urho3D)
     set (URHO3D_LIB_TYPE STATIC CACHE STRING "Specify Urho3D library type, possible values are STATIC (default) and SHARED")
     set (URHO3D_LIB_TYPE STATIC CACHE STRING "Specify Urho3D library type, possible values are STATIC (default) and SHARED")
@@ -722,7 +729,6 @@ else ()
             # Not Android and not Emscripten and not MinGW derivative
             # Not Android and not Emscripten and not MinGW derivative
             set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")     # This will emit '-DREENTRANT' to compiler and '-lpthread' to linker on Linux and Mac OSX platform
             set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")     # This will emit '-DREENTRANT' to compiler and '-lpthread' to linker on Linux and Mac OSX platform
             set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") # However, it may emit other equivalent compiler define and/or linker flag on other *nix platforms
             set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") # However, it may emit other equivalent compiler define and/or linker flag on other *nix platforms
-            set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${ROOTED_EXE_LINKER_FLAGS}")
         endif ()
         endif ()
         set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG -D_DEBUG")
         set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG -D_DEBUG")
         set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -D_DEBUG")
         set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -D_DEBUG")
@@ -857,7 +863,7 @@ macro (enable_pch HEADER_PATHNAME)
     # No op when PCH support is not enabled
     # No op when PCH support is not enabled
     if (URHO3D_PCH)
     if (URHO3D_PCH)
         # Get the optional LANG parameter to indicate whether the header should be treated as C or C++ header, default to C++
         # Get the optional LANG parameter to indicate whether the header should be treated as C or C++ header, default to C++
-        if ("${ARGN}" STREQUAL C)   # Stringigy as the LANG paramater could be empty
+        if ("${ARGN}" STREQUAL C)   # Stringify as the LANG paramater could be empty
             set (EXT c)
             set (EXT c)
             set (LANG C)
             set (LANG C)
             set (LANG_H c-header)
             set (LANG_H c-header)
@@ -1157,7 +1163,7 @@ macro (setup_executable)
         endif ()
         endif ()
     endif ()
     endif ()
     if (ARG_NODEPS)
     if (ARG_NODEPS)
-        set (CMAKE_EXE_LINKER_FLAGS "${ROOTED_EXE_LINKER_FLAGS} ${LUAJIT_EXE_LINKER_FLAGS}")    # Don't need other extra linker flags that are meant for main executable only
+        set (CMAKE_EXE_LINKER_FLAGS "${INDIRECT_DEPS_EXE_LINKER_FLAGS} ${LUAJIT_EXE_LINKER_FLAGS}")    # Don't need other extra linker flags that are meant for main executable only
     else ()
     else ()
         define_dependency_libs (Urho3D)
         define_dependency_libs (Urho3D)
     endif ()
     endif ()
@@ -1573,9 +1579,7 @@ macro (define_dependency_libs TARGET)
             elseif (WIN32)
             elseif (WIN32)
                 list (APPEND LIBS opengl32)
                 list (APPEND LIBS opengl32)
             elseif (ANDROID OR ARM)
             elseif (ANDROID OR ARM)
-                if (NOT RPI)
-                    list (APPEND LIBS GLESv1_CM GLESv2)
-                endif ()
+                list (APPEND LIBS GLESv1_CM GLESv2)
             else ()
             else ()
                 list (APPEND LIBS GL)
                 list (APPEND LIBS GL)
             endif ()
             endif ()

+ 5 - 7
CMake/Toolchains/android.toolchain.cmake

@@ -1454,15 +1454,13 @@ if( ARMEABI_V7A )
  set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--fix-cortex-a8" )
  set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--fix-cortex-a8" )
 endif()
 endif()
 
 
+# Urho3D - bug fix - fix the common linker problem as it may happen to all archs (not just MIPS) when ld.bfd is used
+if( NOT ANDROID_SYSROOT MATCHES "[ ;\"]" )
+  set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-rpath-link,${ANDROID_SYSROOT}/usr/lib" )
+endif()
+
 if( ANDROID_NO_UNDEFINED )
 if( ANDROID_NO_UNDEFINED )
- if( MIPS )
-  # there is some sysroot-related problem in mips linker...
-  if( NOT ANDROID_SYSROOT MATCHES "[ ;\"]" )
-   set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--no-undefined -Wl,-rpath-link,${ANDROID_SYSROOT}/usr/lib" )
-  endif()
- else()
   set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--no-undefined" )
   set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--no-undefined" )
- endif()
 endif()
 endif()
 
 
 if( ANDROID_SO_UNDEFINED )
 if( ANDROID_SO_UNDEFINED )

+ 2 - 3
Source/ThirdParty/SDL/CMakeLists.txt

@@ -179,15 +179,14 @@ set (SDL_CFLAGS)
 # restore back to that afterwards. For check_function_exists() to work in
 # restore back to that afterwards. For check_function_exists() to work in
 # Emscripten, this value must be at its default value.
 # Emscripten, this value must be at its default value.
 # Urho3D - also due to a CMake's try_compile() bug on iOS platform, the CMAKE_REQUIRED_FLAGS contains our SmileyHack-injection on iOS platform
 # Urho3D - also due to a CMake's try_compile() bug on iOS platform, the CMAKE_REQUIRED_FLAGS contains our SmileyHack-injection on iOS platform
-set(ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
+set (ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
 # Urho3D - save the original CMake global settings, do not leave them to chances
 # 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_INCLUDES ${CMAKE_REQUIRED_INCLUDES})
 set (ORIG_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
 set (ORIG_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
 
 
 if (RPI)
 if (RPI)
   # Urho3D - TODO - move the find_package(VideoCore REQUIRED) call from Urho3D common module to here later after we have refactored the library dependency handling
   # Urho3D - TODO - move the find_package(VideoCore REQUIRED) call from Urho3D common module to here later after we have refactored the library dependency handling
-  # Urho3D - bug fix - adjust the header search path for subsequent for pthread, EGL and OpenGLES2 checks
-  listtostr (VIDEOCORE_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I")
+  # Urho3D - bug fix - adjust the header search path for subsequent pthread, EGL and OpenGLES2 checks
   list (APPEND CMAKE_REQUIRED_INCLUDES ${VIDEOCORE_INCLUDE_DIRS})
   list (APPEND CMAKE_REQUIRED_INCLUDES ${VIDEOCORE_INCLUDE_DIRS})
 endif ()
 endif ()