Clean up FindUrho3D.cmake module.

Add new build options to override 64-bit Linux package setup for Debian and Redhad -based host systems.
For Travis CI - fix 64-bit RPM package generation to install library in /usr/lib64, also fix external project build test using Urho3D library from SDK.
This commit is contained in:
Yao Wei Tjong 姚伟忠 2014-12-24 18:10:38 +08:00
parent 0c2e47a42d
commit 1b465fb704
6 changed files with 48 additions and 52 deletions

View File

@ -69,6 +69,6 @@ install:
script: rake ci
after_success:
- if [ $SITE_UPDATE_ON_MASTER_COMMIT ]; then rake ci_site_update; fi && if [ $SITE_UPDATE ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then rake ci_rebase; fi
- if [ $PACKAGE_UPLOAD ]; then rake ci_package_upload; fi
- if [ $PACKAGE_UPLOAD ]; then rake ci_package_upload; if [ $LINUX ] && [ ! "$URHO3D_64BIT" == "0" ]; then rake ci_package_upload URHO3D_USE_LIB64_RPM=1; fi; fi
# vi: set ts=2 sw=2 expandtab:

View File

@ -61,34 +61,29 @@ if (CMAKE_PROJECT_NAME STREQUAL Urho3D AND TARGET Urho3D)
set (URHO3D_LIBRARIES Urho3D)
set (FOUND_MESSAGE "Found Urho3D: as CMake target")
else ()
# Library location would be searched based on URHO3D_HOME variable
# Library location would be searched (based on URHO3D_HOME variable if provided)
if (NOT URHO3D_HOME AND DEFINED ENV{URHO3D_HOME})
file (TO_CMAKE_PATH "$ENV{URHO3D_HOME}" URHO3D_HOME)
endif ()
if (URHO3D_HOME)
list (APPEND CMAKE_PREFIX_PATH ${URHO3D_HOME})
set (SEARCH_OPT NO_CMAKE_FIND_ROOT_PATH)
endif ()
set (URHO3D_LIB_NAMES Urho3D)
if (IOS)
set (CMAKE_LIBRARY_ARCHITECTURE ios)
elseif (ANDROID)
set (URHO3D_LIB_SEARCH_HINT HINTS ${URHO3D_HOME}/libs/${ANDROID_NDK_ABI_NAME})
endif ()
if (URHO3D_HOME AND NOT EXISTS ${URHO3D_HOME}/share)
set (URHO3D_INCLUDE_SEARCH_HINT HINTS ${URHO3D_HOME}/include NO_CMAKE_FIND_ROOT_PATH)
if (ANDROID)
set (URHO3D_LIB_SEARCH_HINT HINTS ${URHO3D_HOME}/libs/${ANDROID_NDK_ABI_NAME} NO_CMAKE_FIND_ROOT_PATH)
else ()
set (URHO3D_LIB_SEARCH_HINT HINTS ${URHO3D_HOME}/lib NO_CMAKE_FIND_ROOT_PATH)
endif ()
else ()
list (APPEND CMAKE_PREFIX_PATH ${URHO3D_HOME})
if (ANDROID)
set (URHO3D_LIB_SEARCH_HINT HINTS ${URHO3D_HOME}/libs/${ANDROID_NDK_ABI_NAME})
endif ()
if (NOT URHO3D_64BIT)
set_property (GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS FALSE)
endif ()
if (NOT URHO3D_64BIT)
set_property (GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS FALSE)
elseif (WIN32)
set_property (GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE)
endif ()
find_path (URHO3D_INCLUDE_DIRS Urho3D.h ${URHO3D_INCLUDE_SEARCH_HINT} PATH_SUFFIXES ${PATH_SUFFIX})
find_library (URHO3D_LIBRARIES NAMES ${URHO3D_LIB_NAMES} ${URHO3D_LIB_SEARCH_HINT} PATH_SUFFIXES ${PATH_SUFFIX})
find_path (URHO3D_INCLUDE_DIRS Urho3D.h PATH_SUFFIXES ${PATH_SUFFIX} ${SEARCH_OPT})
find_library (URHO3D_LIBRARIES NAMES ${URHO3D_LIB_NAMES} ${URHO3D_LIB_SEARCH_HINT} PATH_SUFFIXES ${PATH_SUFFIX} ${SEARCH_OPT})
if (WIN32)
find_library (URHO3D_LIBRARIES_DBG NAMES ${URHO3D_LIB_NAMES}_d ${URHO3D_LIB_SEARCH_HINT} PATH_SUFFIXES ${PATH_SUFFIX})
find_library (URHO3D_LIBRARIES_DBG NAMES ${URHO3D_LIB_NAMES}_d ${URHO3D_LIB_SEARCH_HINT} PATH_SUFFIXES ${PATH_SUFFIX} ${SEARCH_OPT})
endif ()
if (URHO3D_INCLUDE_DIRS)
get_filename_component (PATH ${URHO3D_INCLUDE_DIRS} PATH)

View File

@ -98,6 +98,10 @@ if (CMAKE_PROJECT_NAME STREQUAL Urho3D)
option (URHO3D_DOCS_QUIET "Generate documentation as part of normal build, suppress generation process from sending anything to stdout")
cmake_dependent_option (URHO3D_MINIDUMPS "Enable minidumps on crash (VS only)" TRUE "MSVC" FALSE)
option (URHO3D_FILEWATCHER "Enable filewatcher support" TRUE)
if (CPACK_SYSTEM_NAME STREQUAL Linux)
cmake_dependent_option (URHO3D_USE_LIB64_RPM "Enable 64-bit RPM CPack generator using /usr/lib64 and disable all other generators (Debian-based host only)" FALSE "URHO3D_64BIT AND NOT HAS_LIB64" FALSE)
cmake_dependent_option (URHO3D_USE_LIB_DEB "Enable 64-bit DEB CPack generator using /usr/lib and disable all other generators (Redhat-based host only)" FALSE "URHO3D_64BIT AND HAS_LIB64" FALSE)
endif ()
endif ()
option (URHO3D_PROFILING "Enable profiling support" TRUE)
option (URHO3D_LOGGING "Enable logging support" TRUE)
@ -666,7 +670,7 @@ macro (setup_main_executable)
if (ANDROID)
# Add SDL native init function, SDL_Main() entry point must be defined by one of the source files in ${SOURCE_FILES}
find_file (ANDROID_MAIN_C_PATH SDL_android_main.c HINTS ${URHO3D_HOME}/include/${PATH_SUFFIX}/SDL/android PATH_SUFFIXES ${PATH_SUFFIX} DOC "Path to SDL_android_main.c" NO_CMAKE_FIND_ROOT_PATH)
find_file (ANDROID_MAIN_C_PATH SDL_android_main.c HINTS ${URHO3D_HOME}/include/${PATH_SUFFIX}/SDL/android PATH_SUFFIXES ${PATH_SUFFIX} DOC "Path to SDL_android_main.c" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
mark_as_advanced (ANDROID_MAIN_C_PATH) # Hide it from cmake-gui in non-advanced mode
if (ANDROID_MAIN_C_PATH)
list (APPEND SOURCE_FILES ${ANDROID_MAIN_C_PATH})

View File

@ -59,8 +59,10 @@ if (IOS)
elseif (ANDROID)
set (LIB_SUFFIX s/${ANDROID_NDK_ABI_NAME})
elseif (URHO3D_64BIT)
if (NOT CMAKE_HOST_WIN32 AND EXISTS /usr/lib64)
# Probably host system is a RedHat-based distro
if (EXISTS /usr/lib64)
set (HAS_LIB64 TRUE)
endif ()
if (WIN32 OR URHO3D_USE_LIB64_RPM OR (HAS_LIB64 AND NOT URHO3D_USE_LIB_DEB))
set (LIB_SUFFIX 64)
endif ()
endif ()
@ -114,7 +116,19 @@ elseif (CPACK_SYSTEM_NAME STREQUAL Linux)
if (RPI)
set (CPACK_SYSTEM_NAME Raspberry-Pi)
endif ()
list (APPEND CPACK_GENERATOR RPM DEB)
if (NOT URHO3D_64BIT OR HAS_LIB64)
list (APPEND CPACK_GENERATOR RPM)
endif ()
if (NOT URHO3D_64BIT OR NOT HAS_LIB64)
list (APPEND CPACK_GENERATOR DEB)
endif ()
if (URHO3D_64BIT)
if (URHO3D_USE_LIB64_RPM AND NOT HAS_LIB64)
set (CPACK_GENERATOR RPM)
elseif (URHO3D_USE_LIB_DEB AND HAS_LIB64)
set (CPACK_GENERATOR DEB)
endif ()
endif ()
set (CPACK_PACKAGING_INSTALL_PREFIX ${DEST_INSTALL_PREFIX})
endif ()
if (URHO3D_64BIT)

View File

@ -67,6 +67,8 @@ A number of build options can be defined explicitly when invoking the above cmak
|URHO3D_STATIC_RUNTIME|0|Use static C/C++ runtime libraries and eliminate the need for runtime DLLs installation (VS only)|
|URHO3D_LIB_TYPE |*|Specify Urho3D library type, possible values are STATIC (\*default) and SHARED|
|URHO3D_SCP_TO_TARGET |-|Use scp to transfer executables to target system (non-Android cross-compiling build only), SSH digital key must be setup first for this to work, typical value has a pattern of usr@tgt:remote-loc|
|URHO3D_USE_LIB64_RPM |0|Enable 64-bit RPM CPack generator using /usr/lib64 and disable all other generators (Debian-based host only)|
|URHO3D_USE_LIB_DEB |0|Enable 64-bit DEB CPack generator using /usr/lib and disable all other generators (Redhat-based host only)|
|CMAKE_BUILD_TYPE |*|Specify CMake build configuration (single-configuration generator only), possible values are Release (\*default), RelWithDebInfo, and Debug|
|CMAKE_OSX_DEPLOYMENT_TARGET|-|Specify Mac OS X deployment target (OSX build only); default to current running OS X if not specified|
|IPHONEOS_DEPLOYMENT_TARGET|-|Specify iPhone OS deployment target (iOS build only); default to latest installed iOS SDK if not specified|
@ -344,10 +346,6 @@ The physical project root directory is also now the logical project source tree
You may also want to copy (or symlink) the batch files or shell script files from Urho3D project root directory (or from Urho3D SDK installation) to your project root directory. The *.bat or *.sh scripts work together with the Urho3D CMake module to configure and generate your initial project build tree. Both out-of-source build tree (recommended) and non out-of-source build tree are now supported. Note that when you invoke one the *.bat or *.sh script for your project, you can also pass most of the \ref Build_Options "build options" supported by Urho3D project. In fact, you probably have to pass the similar build options that you use when building the Urho3D library to avoid any conflict.
\section UsingLibraryFromProjectBuildTree From Urho3D project build tree
This section assumes that you have already successfully build a static or shared library in the Urho3D project (separately from your own project). In order to find the Urho3D headers and library this way, specify an environment variable called "URHO3D_HOME" which points to the Urho3D project build tree that you configured earlier to build Urho3D project. Note that this is not the Urho3D project root directory (unless Urho3D build tree location is the same as Urho3D project root directory).
In your own project root directory, create a main CMakeLists.txt file and add the following lines: (replace MyProjectName and MyExecutableName with the actual names you want)
\code
@ -372,9 +370,7 @@ if (COMMAND cmake_policy)
endif ()
# Set CMake modules search path
set (CMAKE_MODULE_PATH
CMake/Modules
CACHE PATH "Path to Urho3D-specific CMake modules")
set (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/Modules)
# Include Urho3D Cmake common module
include (Urho3D-CMake-common)
@ -397,6 +393,8 @@ The CMAKE_MODULE_PATH is setup so that CMake can find the Urho3D-specific CMake
When both Urho3D static and shared library are built and available in the Urho3D project's library output directory in its build tree, the FindUrho3D.cmake module has precedence to first select static library type over over shared library type. However, you can use URHO3D_LIB_TYPE build option to explicitly specify which Urho3D library type to be selected. When linking statically against Urho3D static library, Urho3D-CMake-common.cmake module automatically set "URHO3D_STATIC_DEFINE" compiler define for your project. This compiler define is crucial for static linking, especially on MSVC.
As described earlier there are two approaches on how to find the Urho3D library. The FindUrho3D.cmake module is designed not only able to find Urho3D library from the Urho3D SDK installation, but also from any Urho3D project build tree directly. When searching in Urho3D SDK installed in a system-wide default location then no additional variable need to be set. When searching in a non-default SDK installation or when searching in any Urho3D project build tree then the actual location need to be provided via URHO3D_HOME environment variable (set in the host system) or CMake variable (set in the above CMakeLists.txt before calling find_package command).
The define_source_files() and setup_main_executable() are Urho3D-specific macros. The define_source_file() macro is a shorthand to glob all the source files in the current directory. It is equivalent to these commands:
\code
@ -407,21 +405,7 @@ set (SOURCE_FILES ${CPP_FILES} ${H_FILES})
The setup_main_executable() macro then uses SOURCE_FILES and TARGET_NAME variables to setup a new CMake target that would work on ALL platforms supported by Urho3D. Make sure both your project name and target name are not called 'Urho3D', as this name is reserved for Urho3D project only.
\section FromSDK From Urho3D SDK installation
This section assumes that you have already installed Urho3D SDK into your system. If you have installed the SDK in a non-default location then you need to use "URHO3D_HOME" environment variable to specify the prefix path of the non-default installation location.
In your own project root directory, create a main CMakeLists.txt file similar to the first approach but change the CMake module search path setup to read as follows:
\code
# Set CMake modules search path
set (CMAKE_MODULE_PATH
$ENV{URHO3D_HOME}/share/Urho3D/CMake/Modules
${CMAKE_INSTALL_PREFIX}/share/Urho3D/CMake/Modules
CACHE PATH "Path to Urho3D-specific CMake modules")
\endcode
\subsection FromSDKWithPkgConfig Using pkg-config instead of CMake
\section FromSDKWithPkgConfig Using pkg-config instead of CMake
If for some reason you could not use CMake in your project, you could configure your project to compile and link against Urho3D library from SDK installation using 'pkg-config' tool with the help of 'Urho3D.pc' configuration file (which is installed as part of the SDK installation). If the Urho3D SDK is being installed into a local location (such as /usr/local) or a non-default location, then most likely you would need to specify PKG_CONFIG_PATH environment variable to point to the location of the configuration file for this to work. The 'Urho3D.pc' file contains important information on how to configure your compiler and linker correctly. You can use that information as a reference to configure your own project even when you do not use 'pkg-config' tool.

View File

@ -257,6 +257,9 @@ task :ci_package_upload do
if ENV['ANDROID'] && !ENV['NO_SDK_SYSIMG']
system "cd ../Build && android update project -p . -t $(android list target |grep android-$API |cut -d ' ' -f2) && ant debug" or abort 'Failed to make Urho3D Samples APK'
end
if ENV['URHO3D_USE_LIB64_RPM']
system "cd ../Build && cmake . -DURHO3D_USE_LIB64_RPM=#{ENV['URHO3D_USE_LIB64_RPM']}" or abort 'Failed to reconfigure to generate 64-bit RPM package'
end
system 'cd ../Build && make package' or abort 'Failed to make binary package'
end
# Determine the upload location
@ -320,11 +323,7 @@ if (COMMAND cmake_policy)
endif ()
# Set CMake modules search path
set (CMAKE_MODULE_PATH
CMake/Modules
$ENV{URHO3D_HOME}/share/Urho3D/CMake/Modules
${CMAKE_INSTALL_PREFIX}/share/Urho3D/CMake/Modules
CACHE PATH \"Path to Urho3D-specific CMake modules\")
set (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/Modules)
# Include Urho3D CMake common module
include (Urho3D-CMake-common)
@ -387,7 +386,7 @@ def makefile_ci
system "export URHO3D_HOME=../.. && cd ../Build/generated/UsingBuildTree && echo '\nExternal project referencing Urho3D library in its build tree' && ./cmake_generic.sh . #{$build_options} -DURHO3D_LUA#{jit}=1 -DURHO3D_TESTING=#{$testing} -DCMAKE_BUILD_TYPE=#{$configuration} && make -j$NUMJOBS #{test}" or abort 'Failed to configure/build/test temporary project using Urho3D as external library'
puts "\nInstalling Urho3D SDK...\n"
# Create a new project on the fly that uses newly installed Urho3D SDK
install_destination = ENV['LINUX'] || ENV['WINDOWS'] || ENV['OSX'] ? "DESTDIR=~ && export URHO3D_HOME=~#{ENV['WINDOWS'] ? '/usr/${MINGW_PREFIX}' : ''}/usr/local" : ''
install_destination = ENV['LINUX'] || ENV['WINDOWS'] || ENV['OSX'] ? "DESTDIR=~ && export URHO3D_HOME=#{ENV['WINDOWS'] ? `find ~/usr/${MINGW_PREFIX##*/} -type d -name local`.chomp : '~/usr/local'}" : ''
scaffolding "../Build/generated/UsingSDK"
system "cd ../Build && make -j$NUMJOBS install >/dev/null #{install_destination} && cd ../Build/generated/UsingSDK && echo '\nExternal project referencing Urho3D SDK' && ./cmake_generic.sh . #{$build_options} -DURHO3D_LUA#{jit}=1 -DURHO3D_TESTING=#{$testing} -DCMAKE_BUILD_TYPE=#{$configuration} && make -j$NUMJOBS #{test}" or abort 'Failed to configure/build/test temporary project using Urho3D as external library'
# Make, deploy, and test run Android APK in an Android (virtual) device