Bläddra i källkod

Fix Urho3D.pc file for Windows and Raspberry Pi platforms.

Document cross-compiling example using pkg-config for Raspberry Pi platform.
Disable Urho3D.pc file generation for Android and iOS platform.
Yao Wei Tjong 姚伟忠 12 år sedan
förälder
incheckning
e83d98f016

+ 8 - 2
Docs/GettingStarted.dox

@@ -358,13 +358,19 @@ If for some reason you could not use CMake in your project, you could configure
 # To get installed Urho3D version
 # To get installed Urho3D version
 PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig pkg-config --modversion Urho3D
 PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig pkg-config --modversion Urho3D
 
 
-# To compile and link in one liner
+# To compile and link natively in one liner
 c++ -o Urho3DPlayer Urho3DPlayer.cpp `PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig pkg-config --cflags --libs Urho3D`
 c++ -o Urho3DPlayer Urho3DPlayer.cpp `PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig pkg-config --cflags --libs Urho3D`
 
 
-# To compile and link separately
+# To compile and link natively but in separate steps
 export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig
 export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig
 c++ -c Urho3DPlayer.cpp `pkg-config --cflags Urho3D`
 c++ -c Urho3DPlayer.cpp `pkg-config --cflags Urho3D`
 c++ -o Urho3DPlayer Urho3DPlayer.o `pkg-config --libs Urho3D`
 c++ -o Urho3DPlayer Urho3DPlayer.o `pkg-config --libs Urho3D`
+
+# To cross-compile and link for Raspberry Pi platform
+export CC=${RASPI_TOOL}/arm-linux-gnueabihf-c++
+export PKG_CONFIG_SYSROOT_DIR=${RASPI_ROOT}
+export PKG_CONFIG_PATH=${RASPI_ROOT}/usr/local/lib/pkgconfig
+$CC -o Urho3DPlayer Urho3DPlayer.cpp `pkg-config --cflags --libs Urho3D`
 \endcode
 \endcode
 
 
 \page Structure Overall structure
 \page Structure Overall structure

+ 6 - 2
Source/CMake/Modules/Urho3D-CMake-magic.cmake

@@ -562,7 +562,11 @@ macro (define_dependency_libs TARGET)
                 list (APPEND LINK_LIBS_ONLY GL)
                 list (APPEND LINK_LIBS_ONLY GL)
             endif ()
             endif ()
         else ()
         else ()
-            list (APPEND ABSOLUTE_PATH_LIBS ${DIRECT3D_LIBRARY})
+            if (IS_ABSOLUTE ${DIRECT3D_LIBRARY})
+                list (APPEND ABSOLUTE_PATH_LIBS ${DIRECT3D_LIBRARY})
+            else ()
+                list (APPEND LINK_LIBS_ONLY ${DIRECT3D_LIBRARY})
+            endif ()
         endif ()
         endif ()
 
 
         # This variable value can either be 'Urho3D' target or an absolute path to an actual static/shared Urho3D library
         # This variable value can either be 'Urho3D' target or an absolute path to an actual static/shared Urho3D library
@@ -572,7 +576,7 @@ macro (define_dependency_libs TARGET)
         endif ()
         endif ()
 
 
         # GCC-specific executable linker flag for LuaJIT
         # GCC-specific executable linker flag for LuaJIT
-        if (ENABLE_LUAJIT AND NOT WIN32 AND NOT APPLE)
+        if (ENABLE_LUAJIT AND NOT WIN32 AND NOT APPLE AND NOT ANDROID)
             set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-E")
             set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-E")
         endif ()
         endif ()
     endif ()
     endif ()

+ 0 - 3
Source/CMakeLists.txt

@@ -43,9 +43,6 @@ if (HAVE_STDINT_H)
     add_definitions (-DHAVE_STDINT_H)
     add_definitions (-DHAVE_STDINT_H)
 endif ()
 endif ()
 
 
-# Add global include directories for export header and SDL header
-include_directories (${CMAKE_BINARY_DIR}/Engine ThirdParty/SDL/include)
-
 # Setup SDK install destinations
 # Setup SDK install destinations
 if (WIN32)
 if (WIN32)
     set (PATH_PREFIX "Urho3D SDK")
     set (PATH_PREFIX "Urho3D SDK")

+ 21 - 9
Source/Engine/CMakeLists.txt

@@ -158,15 +158,24 @@ endif ()
 install (FILES ${CMAKE_CURRENT_BINARY_DIR}/Urho3D.h DESTINATION ${DEST_INCLUDE_DIR})
 install (FILES ${CMAKE_CURRENT_BINARY_DIR}/Urho3D.h DESTINATION ${DEST_INCLUDE_DIR})
 
 
 # Generate platform specific pkg-config file for the benefit of Urho3D library users via SDK without CMake
 # Generate platform specific pkg-config file for the benefit of Urho3D library users via SDK without CMake
-get_directory_property (URHO3D_COMPILE_DEFINITIONS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_DEFINITIONS)
-list (REMOVE_ITEM URHO3D_COMPILE_DEFINITIONS HAVE_STDINT_H GLEW_STATIC GLEW_NO_GLU)     # Remove those defines that are only used for building the library and not needed by library user
-string (REPLACE ";" " -D" URHO3D_COMPILE_DEFINITIONS ";${URHO3D_COMPILE_DEFINITIONS}")
-set (URHO3D_LIBS ${LINK_LIBS_ONLY})
-string (REPLACE ";" " -l" URHO3D_LIBS "-lUrho3D;${URHO3D_LIBS}")
-set (URHO3D_INCLUDE_DIRS ${INSTALL_INCLUDE_DIRS})
-string (REPLACE ";" " -I\${includedir}/" URHO3D_INCLUDE_DIRS "-I\${includedir};${URHO3D_INCLUDE_DIRS}")
-configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Urho3D.pc.in ${CMAKE_CURRENT_BINARY_DIR}/Urho3D.pc @ONLY)
-install (FILES ${CMAKE_CURRENT_BINARY_DIR}/Urho3D.pc DESTINATION ${DEST_PKGCONFIG_DIR})
+if (NOT ANDROID AND NOT IOS)
+    set (SYSROOT ${RASPI_SYSROOT})  # SYSROOT is empty for native build
+    string (REPLACE "${SYSROOT}" "" DEST_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
+    get_directory_property (URHO3D_COMPILE_DEFINITIONS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_DEFINITIONS)
+    list (REMOVE_ITEM URHO3D_COMPILE_DEFINITIONS HAVE_STDINT_H GLEW_STATIC GLEW_NO_GLU)     # Remove those defines that are only used for building the library and not needed by library user
+    string (REPLACE ";" " -D" URHO3D_COMPILE_DEFINITIONS ";${URHO3D_COMPILE_DEFINITIONS}")
+    string (REPLACE ";" " " URHO3D_ABS_PATH_LIBS "${ABSOLUTE_PATH_LIBS}")   # Note: need to always "stringify" a variable in list context for replace to work correctly, besides the list could be empty
+    string (REPLACE "${SYSROOT}" "\${pc_sysrootdir}" URHO3D_ABS_PATH_LIBS "${URHO3D_ABS_PATH_LIBS}") 
+    string (REPLACE ";" " -l" URHO3D_LIBS "-lUrho3D;${LINK_LIBS_ONLY}")
+    get_directory_property (GLOBAL_INCLUDE_DIRS DIRECTORY ${CMAKE_SOURCE_DIR} INCLUDE_DIRECTORIES)
+    if (GLOBAL_INCLUDE_DIRS)
+        string (REPLACE ";" " -I" GLOBAL_INCLUDE_DIRS ";${GLOBAL_INCLUDE_DIRS}")
+        string (REPLACE "${SYSROOT}" "" GLOBAL_INCLUDE_DIRS ${GLOBAL_INCLUDE_DIRS})
+    endif ()
+    string (REPLACE ";" " -I\${includedir}/" URHO3D_INCLUDE_DIRS "-I\${includedir};${INSTALL_INCLUDE_DIRS}")
+    configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Urho3D.pc.in ${CMAKE_CURRENT_BINARY_DIR}/Urho3D.pc @ONLY)
+    install (FILES ${CMAKE_CURRENT_BINARY_DIR}/Urho3D.pc DESTINATION ${DEST_PKGCONFIG_DIR})
+endif ()
 
 
 # Setup the compiler flags for building shared library (do this here so that it does not interfere with the pkg-config file generation above)
 # Setup the compiler flags for building shared library (do this here so that it does not interfere with the pkg-config file generation above)
 if (URHO3D_LIB_TYPE STREQUAL SHARED)
 if (URHO3D_LIB_TYPE STREQUAL SHARED)
@@ -176,6 +185,9 @@ if (URHO3D_LIB_TYPE STREQUAL SHARED)
     set_target_properties (${STATIC_LIBRARY_TARGETS} PROPERTIES POSITION_INDEPENDENT_CODE true) 
     set_target_properties (${STATIC_LIBRARY_TARGETS} PROPERTIES POSITION_INDEPENDENT_CODE true) 
 endif ()
 endif ()
 
 
+# Add include directories to find the export header and SDL header for building Urho3D library
+include_directories (${CMAKE_BINARY_DIR}/Engine ../ThirdParty/SDL/include)
+
 # Define post build steps
 # Define post build steps
 # Strip the output shared library for embedded devices
 # Strip the output shared library for embedded devices
 if (URHO3D_LIB_TYPE STREQUAL SHARED AND (CMAKE_CROSSCOMPILING OR IOS))
 if (URHO3D_LIB_TYPE STREQUAL SHARED AND (CMAKE_CROSSCOMPILING OR IOS))

+ 1 - 1
Source/Engine/LuaScript/CMakeLists.txt

@@ -63,7 +63,7 @@ install (FILES ${H_FILES} DESTINATION ${DEST_INCLUDE_DIR})
 set (LIBS ../../ThirdParty/Lua${JIT}/src)
 set (LIBS ../../ThirdParty/Lua${JIT}/src)
 set (LINK_LIBS_ONLY tolua++_static)
 set (LINK_LIBS_ONLY tolua++_static)
 set (INCLUDE_DIRS_ONLY . .. ../Audio ../Container ../Core ../Engine ../Graphics ../Input ../IO ../Math ../Navigation ../Network ../Physics ../Resource ../Scene ../UI
 set (INCLUDE_DIRS_ONLY . .. ../Audio ../Container ../Core ../Engine ../Graphics ../Input ../IO ../Math ../Navigation ../Network ../Physics ../Resource ../Scene ../UI
-    ../../ThirdParty/Bullet/src ../../ThirdParty/kNet/include ../../ThirdParty/tolua++/include)
+    ../../ThirdParty/Bullet/src ../../ThirdParty/kNet/include ../../ThirdParty/SDL/include ../../ThirdParty/tolua++/include ${CMAKE_BINARY_DIR}/Engine)
 
 
 # Setup target
 # Setup target
 setup_library ()
 setup_library ()

+ 4 - 5
Source/Engine/Urho3D.pc.in

@@ -1,4 +1,4 @@
-prefix=@CMAKE_INSTALL_PREFIX@
+prefix=@DEST_INSTALL_PREFIX@
 exec_prefix=${prefix}
 exec_prefix=${prefix}
 includedir=${prefix}/@DEST_INCLUDE_DIR@
 includedir=${prefix}/@DEST_INCLUDE_DIR@
 libdir=${exec_prefix}/@DEST_LIBRARY_DIR@
 libdir=${exec_prefix}/@DEST_LIBRARY_DIR@
@@ -6,7 +6,6 @@ libdir=${exec_prefix}/@DEST_LIBRARY_DIR@
 Name: Urho3D
 Name: Urho3D
 Description: Urho3D is a lightweight, cross-platform rendering and game engine implemented in C++ and released under the MIT license. Greatly inspired by OGRE (http://www.ogre3d.org) and Horde3D (http://www.horde3d.org).
 Description: Urho3D is a lightweight, cross-platform rendering and game engine implemented in C++ and released under the MIT license. Greatly inspired by OGRE (http://www.ogre3d.org) and Horde3D (http://www.horde3d.org).
 Version: 1.3.0
 Version: 1.3.0
-Requires:
-Conflicts:
-Cflags: @URHO3D_COMPILE_DEFINITIONS@ @CMAKE_CXX_FLAGS@ @URHO3D_INCLUDE_DIRS@
-Libs: @CMAKE_EXE_LINKER_FLAGS@ -L${libdir} @URHO3D_LIBS@
+URL: https://code.google.com/p/urho3d/
+Cflags: @URHO3D_COMPILE_DEFINITIONS@ @CMAKE_CXX_FLAGS@ @GLOBAL_INCLUDE_DIRS@ @URHO3D_INCLUDE_DIRS@
+Libs: @CMAKE_EXE_LINKER_FLAGS@ @URHO3D_ABS_PATH_LIBS@ -L${libdir} @URHO3D_LIBS@

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

@@ -110,5 +110,8 @@ install (DIRECTORY include/ DESTINATION ${DEST_INCLUDE_DIR}/SDL USE_SOURCE_PERMI
 set (INSTALL_INCLUDE_DIRS ${INSTALL_INCLUDE_DIRS} SDL PARENT_SCOPE)
 set (INSTALL_INCLUDE_DIRS ${INSTALL_INCLUDE_DIRS} SDL PARENT_SCOPE)
 install (FILES src/main/android/SDL_android_main.c DESTINATION ${DEST_SHARE_DIR}/templates/android)
 install (FILES src/main/android/SDL_android_main.c DESTINATION ${DEST_SHARE_DIR}/templates/android)
 
 
+# Define dependency libs
+set (INCLUDE_DIRS_ONLY include)
+
 # Setup target
 # Setup target
 setup_library ()
 setup_library ()