From 60c1570db85f9633b870c23a7e12ba3d2876e51e Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Fri, 23 Aug 2019 15:58:47 -0600 Subject: [PATCH] CMake: Add support for makepanda-style thirdparty directories --- CMakeLists.txt | 6 +++ dtool/Package.cmake | 103 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index bf07746e62..fdc0008c1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,12 @@ cmake_minimum_required(VERSION 3.0.2) set(CMAKE_DISABLE_SOURCE_CHANGES ON) # Must go before project() below set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) # Must go before project() below +if(CMAKE_VERSION VERSION_GREATER "3.12" OR POLICY CMP0074) + # Needed for THIRDPARTY_DIRECTORY support; this will be enabled by default + # once the minimum CMake version is at least 3.12. + cmake_policy(SET CMP0074 NEW) +endif() + # Figure out the version file(STRINGS "setup.cfg" _version REGEX "^version = ") string(REGEX REPLACE "^.*= " "" _version "${_version}") diff --git a/dtool/Package.cmake b/dtool/Package.cmake index dca10e6ccc..5c8442eabb 100644 --- a/dtool/Package.cmake +++ b/dtool/Package.cmake @@ -1,3 +1,106 @@ +set(THIRDPARTY_DIRECTORY "" CACHE PATH + "Optional location of a makepanda-style thirdparty directory. All libraries + located here will be prioritized over system libraries. Useful for + cross-compiling.") + +if(THIRDPARTY_DIRECTORY) + # This policy is necessary for PackageName_ROOT variables to be respected + if(POLICY CMP0074) + cmake_policy(GET CMP0074 _policy_cmp0074) + endif() + + if(NOT _policy_cmp0074 STREQUAL "NEW") + message(FATAL_ERROR + "Your version of CMake is too old; please upgrade or unset THIRDPARTY_DIRCTORY to continue.") + endif() + + # Dig up the actual "libs" directory + if(APPLE) + set(_package_dir "${THIRDPARTY_DIRECTORY}/darwin-libs-a") + + elseif(WIN32) + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(_package_dir "${THIRDPARTY_DIRECTORY}/win-libs-vc14-x64") + + file(GLOB Python_ROOT "${THIRDPARTY_DIRECTORY}/win-python*-x64") + else() + set(_package_dir "${THIRDPARTY_DIRECTORY}/win-libs-vc14") + + file(GLOB Python_ROOT "${THIRDPARTY_DIRECTORY}/win-python*") + endif() + + list(REVERSE Python_ROOT) # Descending order of version + + set(BISON_ROOT "${THIRDPARTY_DIRECTORY}/win-util") + set(FLEX_ROOT "${THIRDPARTY_DIRECTORY}/win-util") + + else() + message(FATAL_ERROR + "You can't use THIRDPARTY_DIRECTORY on this platform. Unset it to continue.") + + endif() + + if(NOT EXISTS "${_package_dir}") + message(FATAL_ERROR + "Either your THIRDPARTY_DIRECTORY path does not exist, or it is for the wrong platform.") + + endif() + + foreach(_Package + ARToolKit + Assimp + Bullet + Cg + Eigen3 + FCollada + FFMPEG + FMODEx + Freetype + HarfBuzz + JPEG + LibSquish + ODE + Ogg + OpenAL + OpenEXR + OpenSSL + OpusFile + PNG + SWResample + SWScale + TIFF + VorbisFile + VRPN + ZLIB + ) + + string(TOLOWER "${_Package}" _package) + + # Some packages in the thirdparty dir have different subdirectory names from + # the name of the CMake package + if(_package STREQUAL "cg") + set(_package "nvidiacg") + elseif(_package STREQUAL "eigen3") + set(_package "eigen") + elseif(_package STREQUAL "ogg") + set(_package "vorbis") # It's in the same install dir here + elseif(_package STREQUAL "opusfile") + set(_package "opus") + elseif(_package STREQUAL "libsquish") + set(_package "squish") + elseif(_package STREQUAL "swresample" OR _package STREQUAL "swscale") + set(_package "ffmpeg") # These are also part of FFmpeg + elseif(_package STREQUAL "vorbisfile") + set(_package "vorbis") + endif() + + # Set search path + set(${_Package}_ROOT "${_package_dir}/${_package}") + + endforeach(_Package) + +endif() + # # ------------ Python ------------ #