From e3a6cb1695336c834c9664eabc40028f01e3b99f Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sun, 2 May 2021 17:13:16 +0100 Subject: [PATCH] Remove OsIdentity.cmake Removes the OsIdentity.cmake file and uses a cross-compilation friendly and OS-independent method of detecting system double-precision bullet instead. --- CMakeLists.txt | 23 +++++++++-- cmake/CheckBulletPrecision.cmake | 21 ++++++---- cmake/OSIdentity.cmake | 67 -------------------------------- components/CMakeLists.txt | 6 +-- 4 files changed, 33 insertions(+), 84 deletions(-) delete mode 100644 cmake/OSIdentity.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 5fc63152e4..c3c17ddcfc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,9 +13,6 @@ if(POLICY CMP0083) cmake_policy(SET CMP0083 NEW) endif() -# Detect OS -include(cmake/OSIdentity.cmake) - option(OPENMW_GL4ES_MANUAL_INIT "Manually initialize gl4es. This is more reliable on platforms without a windowing system. Requires gl4es to be configured with -DNOEGL=ON -DNO_LOADER=ON -DNO_INIT_CONSTRUCTOR=ON." OFF) if(OPENMW_GL4ES_MANUAL_INIT) add_definitions(-DOPENMW_GL4ES_MANUAL_INIT) @@ -312,7 +309,25 @@ if(OPENMW_USE_SYSTEM_BULLET) set(REQUIRED_BULLET_VERSION 283) # but for build testing, 283 is fine endif() - find_package(Bullet ${REQUIRED_BULLET_VERSION} REQUIRED COMPONENTS BulletCollision LinearMath) + # First, try BulletConfig-float64.cmake which comes with Debian derivatives. + # This file does not define the Bullet version in a CMake-friendly way. + find_package(Bullet CONFIGS BulletConfig-float64.cmake QUIET COMPONENTS BulletCollision LinearMath) + if (BULLET_FOUND) + string(REPLACE "." "" _bullet_version_num ${BULLET_VERSION_STRING}) + if (_bullet_version_num VERSION_LESS REQUIRED_BULLET_VERSION) + message(FATAL_ERROR "System bullet version too old, OpenMW requires at least ${REQUIRED_BULLET_VERSION}, got ${_bullet_version_num}") + endif() + # Fix the relative include: + set(BULLET_INCLUDE_DIRS "${BULLET_ROOT_DIR}/${BULLET_INCLUDE_DIRS}") + include(FindPackageMessage) + find_package_message(Bullet "Found Bullet: ${BULLET_LIBRARIES} ${BULLET_VERSION_STRING}" "${BULLET_VERSION_STRING}-float64") + else() + find_package(Bullet ${REQUIRED_BULLET_VERSION} REQUIRED COMPONENTS BulletCollision LinearMath) + endif() + + # Only link the Bullet libraries that we need: + string(REGEX MATCHALL "((optimized|debug);)?[^;]*(BulletCollision|LinearMath)[^;]*" BULLET_LIBRARIES "${BULLET_LIBRARIES}") + include(cmake/CheckBulletPrecision.cmake) if (HAS_DOUBLE_PRECISION_BULLET) message(STATUS "Bullet uses double precision") diff --git a/cmake/CheckBulletPrecision.cmake b/cmake/CheckBulletPrecision.cmake index ec36240348..4700f1651d 100644 --- a/cmake/CheckBulletPrecision.cmake +++ b/cmake/CheckBulletPrecision.cmake @@ -18,16 +18,21 @@ file(WRITE ${TMP_ROOT}/CMakeLists.txt " cmake_minimum_required(VERSION 3.1.0) project(checkbullet) -add_executable(checkbullet checkbullet.cpp) -find_package(Bullet REQUIRED COMPONENTS BulletCollision LinearMath) -target_compile_definitions(checkbullet PUBLIC BT_USE_DOUBLE_PRECISION) -include_directories(\$\{BULLET_INCLUDE_DIRS\}) -include(${CMAKE_SOURCE_DIR}/cmake/OSIdentity.cmake) -if (UBUNTU_FOUND OR DEBIAN_FOUND) - target_link_libraries(checkbullet BulletCollision-float64 LinearMath-float64) + +# First, try BulletConfig-float64.cmake which comes with Debian derivatives. +find_package(Bullet CONFIGS BulletConfig-float64.cmake QUIET COMPONENTS BulletCollision LinearMath) +if (BULLET_FOUND) + # Fix the relative include: + set(BULLET_INCLUDE_DIRS \"\$\{BULLET_ROOT_DIR\}/\$\{BULLET_INCLUDE_DIRS\}\") else() - target_link_libraries(checkbullet \$\{BULLET_LIBRARIES\}) + find_package(Bullet REQUIRED COMPONENTS BulletCollision LinearMath) endif() +string(REGEX MATCHALL \"((optimized|debug);)?[^;]*(BulletCollision|LinearMath)[^;]*\" BULLET_LIBRARIES \"$\{BULLET_LIBRARIES\}\") + +add_executable(checkbullet checkbullet.cpp) +target_compile_definitions(checkbullet PUBLIC BT_USE_DOUBLE_PRECISION) +target_include_directories(checkbullet PUBLIC \$\{BULLET_INCLUDE_DIRS\}) +target_link_libraries(checkbullet \$\{BULLET_LIBRARIES\}) ") if (DEFINED BULLET_ROOT) diff --git a/cmake/OSIdentity.cmake b/cmake/OSIdentity.cmake deleted file mode 100644 index 40b7b20895..0000000000 --- a/cmake/OSIdentity.cmake +++ /dev/null @@ -1,67 +0,0 @@ -if (UNIX) - - if (APPLE) - - set(CMAKE_OS_NAME "OSX" CACHE STRING "Operating system name" FORCE) - - else (APPLE) - - ## Check for Debian GNU/Linux ________________ - - find_file(DEBIAN_FOUND debian_version debconf.conf - PATHS /etc - ) - if (DEBIAN_FOUND) - set(CMAKE_OS_NAME "Debian" CACHE STRING "Operating system name" FORCE) - endif (DEBIAN_FOUND) - - ## Check for Fedora _________________________ - - find_file(FEDORA_FOUND fedora-release - PATHS /etc - ) - if (FEDORA_FOUND) - set(CMAKE_OS_NAME "Fedora" CACHE STRING "Operating system name" FORCE) - endif (FEDORA_FOUND) - - ## Check for RedHat _________________________ - - find_file(REDHAT_FOUND redhat-release inittab.RH - PATHS /etc - ) - if (REDHAT_FOUND) - set(CMAKE_OS_NAME "RedHat" CACHE STRING "Operating system name" FORCE) - endif (REDHAT_FOUND) - - ## Extra check for Ubuntu ____________________ - - if (DEBIAN_FOUND) - - ## At its core Ubuntu is a Debian system, with - ## a slightly altered configuration; hence from - ## a first superficial inspection a system will - ## be considered as Debian, which signifies an - ## extra check is required. - - find_file(UBUNTU_EXTRA legal issue - PATHS /etc - ) - - if (UBUNTU_EXTRA) - ## Scan contents of file - file(STRINGS ${UBUNTU_EXTRA} UBUNTU_FOUND - REGEX Ubuntu - ) - ## Check result of string search - if (UBUNTU_FOUND) - set(CMAKE_OS_NAME "Ubuntu" CACHE STRING "Operating system name" FORCE) - set(DEBIAN_FOUND FALSE) - endif (UBUNTU_FOUND) - - endif (UBUNTU_EXTRA) - - endif (DEBIAN_FOUND) - - endif (APPLE) - -endif (UNIX) diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 9b65c3da09..b901b2e17f 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -254,11 +254,7 @@ target_link_libraries(components RecastNavigation::Recast ) -if ((UBUNTU_FOUND OR DEBIAN_FOUND) AND OPENMW_USE_SYSTEM_BULLET) - target_link_libraries(components BulletCollision-float64 LinearMath-float64) -else() - target_link_libraries(components ${BULLET_LIBRARIES}) -endif() +target_link_libraries(components ${BULLET_LIBRARIES}) if (WIN32) target_link_libraries(components