CMake: Redo ODE find module

This defines an ODE::ODE target; it also automatically selects
the correct `dIDESINGLE`/`dIDEDOUBLE` compile-time definition.
This commit is contained in:
Sam Edwards 2018-10-18 15:28:40 -06:00
parent dd5c411e88
commit 8dd46eb736
3 changed files with 186 additions and 116 deletions

View File

@ -7,74 +7,144 @@
# Once done this will define: # Once done this will define:
# ODE_FOUND - system has ode # ODE_FOUND - system has ode
# ODE_INCLUDE_DIR - the ode include directory # ODE_INCLUDE_DIR - the ode include directory
# ODE_LIBRARY_DIR - the ode library directory
# ODE_LIBRARY - the path to the library binary
# #
# ODE_RELEASE_LIBRARY - the filepath of the ode release library # ODE_RELEASE_LIBRARY - the filepath of the ode release library
# ODE_DEBUG_LIBRARY - the filepath of the ode debug library # ODE_DEBUG_LIBRARY - the filepath of the ode debug library
# #
# ODE_SINGLE_DEBUG_LIBRARY - the filepath of the single-precision ode debug library
# ODE_SINGLE_RELEASE_LIBRARY - the filepath of the single-precision ode release library
# ODE_DOUBLE_DEBUG_LIBRARY - the filepath of the double-precision ode debug library
# ODE_DOUBLE_RELEASE_LIBRARY - the filepath of the double-precision ode release library
#
# ODE::ODE - The recommended ODE library to link against
# ODE::ODE_single - If available, this links against single-precision ODE
# ODE::ODE_double - If available, this links against double-precision ODE
#
if(NOT ODE_INCLUDE_DIR OR NOT ODE_LIBRARY_DIR) if(NOT ODE_INCLUDE_DIR OR NOT ODE_LIBRARY_DIR)
# Find the libode include files # Find the libode include files
find_path(ODE_INCLUDE_DIR find_path(ODE_INCLUDE_DIR
NAMES "ode.h" NAMES "ode.h"
PATHS "/usr/include" PATH_SUFFIXES "ode")
"/usr/local/include"
"/sw/include"
"/opt/include"
"/opt/local/include"
"/opt/csw/include"
PATH_SUFFIXES "" "ode"
)
# Find the libode library built for release # Find the libode library built for release
find_library(ODE_RELEASE_LIBRARY find_library(ODE_RELEASE_LIBRARY
NAMES "ode" "libode" NAMES "ode" "libode")
PATHS "/usr"
"/usr/local"
"/usr/freeware"
"/sw"
"/opt"
"/opt/csw"
PATH_SUFFIXES "lib" "lib32" "lib64"
)
# Find the libode library built for debug # Find the libode library built for debug
find_library(ODE_DEBUG_LIBRARY find_library(ODE_DEBUG_LIBRARY
NAMES "oded" "liboded" NAMES "oded" "liboded")
PATHS "/usr"
"/usr/local"
"/usr/freeware"
"/sw"
"/opt"
"/opt/csw"
PATH_SUFFIXES "lib" "lib32" "lib64"
)
# Find the single-precision library built for release
find_library(ODE_SINGLE_RELEASE_LIBRARY
NAMES "ode_single" "libode_single")
# Find the single-precision library built for debug
find_library(ODE_SINGLE_DEBUG_LIBRARY
NAMES "ode_singled" "libode_singled")
# Find the double-precision library built for release
find_library(ODE_DOUBLE_RELEASE_LIBRARY
NAMES "ode_double" "libode_double" )
# Find the double-precision library built for debug
find_library(ODE_DOUBLE_DEBUG_LIBRARY
NAMES "ode_doubled" "libode_doubled")
unset(_ODE_LIB_PATHS)
mark_as_advanced(ODE_INCLUDE_DIR) mark_as_advanced(ODE_INCLUDE_DIR)
mark_as_advanced(ODE_RELEASE_LIBRARY) mark_as_advanced(ODE_RELEASE_LIBRARY)
mark_as_advanced(ODE_DEBUG_LIBRARY) mark_as_advanced(ODE_DEBUG_LIBRARY)
mark_as_advanced(ODE_SINGLE_RELEASE_LIBRARY)
mark_as_advanced(ODE_SINGLE_DEBUG_LIBRARY)
mark_as_advanced(ODE_DOUBLE_RELEASE_LIBRARY)
mark_as_advanced(ODE_DOUBLE_DEBUG_LIBRARY)
endif() endif()
# Choose library # Define targets for both precisions (and unspecified)
if(CMAKE_BUILD_TYPE MATCHES "Debug" AND ODE_DEBUG_LIBRARY) foreach(_precision _single _double "")
set(ODE_LIBRARY ${ODE_DEBUG_LIBRARY} CACHE FILEPATH "The filepath to libode's library binary.") string(TOUPPER "${_precision}" _PRECISION)
elseif(ODE_RELEASE_LIBRARY)
set(ODE_LIBRARY ${ODE_RELEASE_LIBRARY} CACHE FILEPATH "The filepath to libode's library binary.") if(EXISTS "${ODE${_PRECISION}_RELEASE_LIBRARY}" OR
elseif(ODE_DEBUG_LIBRARY) EXISTS "${ODE${_PRECISION}_DEBUG_LIBRARY}")
set(ODE_LIBRARY ${ODE_DEBUG_LIBRARY} CACHE FILEPATH "The filepath to libode's library binary.") if(NOT TARGET ODE::ODE${_precision})
add_library(ODE::ODE${_precision} UNKNOWN IMPORTED GLOBAL)
set_target_properties(ODE::ODE${_precision} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${ODE_INCLUDE_DIR}")
if(EXISTS "${ODE${_PRECISION}_RELEASE_LIBRARY}")
set_property(TARGET ODE::ODE${_precision} APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(ODE::ODE${_precision} PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
IMPORTED_LOCATION_RELEASE "${ODE${_PRECISION}_RELEASE_LIBRARY}")
endif() endif()
# Translate library into library directory if(EXISTS "${ODE${_PRECISION}_DEBUG_LIBRARY}")
if(ODE_LIBRARY) set_property(TARGET ODE::ODE${_precision} APPEND PROPERTY
unset(ODE_LIBRARY_DIR CACHE) IMPORTED_CONFIGURATIONS DEBUG)
get_filename_component(ODE_LIBRARY_DIR "${ODE_LIBRARY}" PATH) set_target_properties(ODE::ODE${_precision} PROPERTIES
set(ODE_LIBRARY_DIR "${ODE_LIBRARY_DIR}" CACHE PATH "The path to libode's library directory.") # Library path IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
IMPORTED_LOCATION_DEBUG "${ODE${_PRECISION}_DEBUG_LIBRARY}")
endif() endif()
mark_as_advanced(ODE_LIBRARY) # If this has a precision, we should be sure to define
mark_as_advanced(ODE_LIBRARY_DIR) # dIDESINGLE/dIDEDOUBLE to keep it consistent
if(_precision)
string(REPLACE "_" "dIDE" _precision_symbol "${_PRECISION}")
set_target_properties(ODE::ODE${_precision} PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "${_precision_symbol}")
unset(_precision_symbol)
endif()
endif()
endif()
endforeach(_precision)
unset(_precision)
unset(_PRECISION)
# OKAY. If everything went well, we have ODE::ODE_single and/or
# ODE::ODE_double. We might even have an ODE::ODE, but if not, we need to
# alias one of the other two to it.
if(NOT TARGET ODE::ODE)
if(TARGET ODE::ODE_single)
set(_copy_from "ODE::ODE_single")
elseif(TARGET ODE::ODE_double)
set(_copy_from "ODE::ODE_double")
endif()
if(DEFINED _copy_from)
add_library(ODE::ODE UNKNOWN IMPORTED GLOBAL)
foreach(_prop
INTERFACE_INCLUDE_DIRECTORIES
INTERFACE_COMPILE_DEFINITIONS
IMPORTED_CONFIGURATIONS
IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE
IMPORTED_LOCATION_RELEASE
IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG
IMPORTED_LOCATION_DEBUG)
get_target_property(_value "${_copy_from}" "${_prop}")
if(DEFINED _value)
set_target_properties(ODE::ODE PROPERTIES "${_prop}" "${_value}")
endif()
unset(_value)
endforeach(_prop)
endif()
unset(_copy_from)
endif()
if(TARGET ODE::ODE)
set(_HAS_ODE_LIBRARY ON)
endif()
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(ODE DEFAULT_MSG ODE_LIBRARY ODE_INCLUDE_DIR ODE_LIBRARY_DIR) find_package_handle_standard_args(ODE DEFAULT_MSG ODE_INCLUDE_DIR _HAS_ODE_LIBRARY)
unset(_HAS_ODE_LIBRARY)

View File

@ -336,7 +336,8 @@ find_package(ODE QUIET)
package_option(ODE package_option(ODE
"Enable this option to support game dynamics with the Open Dynamics Engine (ODE)." "Enable this option to support game dynamics with the Open Dynamics Engine (ODE)."
LICENSE "BSD-3") LICENSE "BSD-3"
IMPORTED_AS ODE::ODE)
config_package(ODE "Open Dynamics Engine") config_package(ODE "Open Dynamics Engine")

View File

@ -86,7 +86,6 @@ list(REMOVE_ITEM P3ODE_IGATE_SOURCES "odeHelperStructs.h")
composite_sources(p3ode P3ODE_SOURCES) composite_sources(p3ode P3ODE_SOURCES)
add_library(p3ode ${P3ODE_SOURCES} ${P3ODE_HEADERS}) add_library(p3ode ${P3ODE_SOURCES} ${P3ODE_HEADERS})
set_target_properties(p3ode PROPERTIES DEFINE_SYMBOL BUILDING_PANDAODE) set_target_properties(p3ode PROPERTIES DEFINE_SYMBOL BUILDING_PANDAODE)
target_compile_definitions(p3ode PUBLIC dSINGLE)
target_link_libraries(p3ode p3igateruntime panda PKG::ODE) target_link_libraries(p3ode p3igateruntime panda PKG::ODE)
target_interrogate(p3ode ${P3ODE_IGATE_SOURCES} EXTENSIONS ${P3ODE_IGATEEXT}) target_interrogate(p3ode ${P3ODE_IGATE_SOURCES} EXTENSIONS ${P3ODE_IGATEEXT})