FindODE.cmake 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. # Filename: FindODE.cmake
  2. # Author: CFSworks (7 Feb, 2014)
  3. #
  4. # Usage:
  5. # find_package(ODE [REQUIRED] [QUIET])
  6. #
  7. # Once done this will define:
  8. # ODE_FOUND - system has ode
  9. # ODE_INCLUDE_DIR - the ode include directory
  10. #
  11. # ODE_RELEASE_LIBRARY - the filepath of the ode release library
  12. # ODE_DEBUG_LIBRARY - the filepath of the ode debug library
  13. #
  14. # ODE_SINGLE_DEBUG_LIBRARY - the filepath of the single-precision ode debug library
  15. # ODE_SINGLE_RELEASE_LIBRARY - the filepath of the single-precision ode release library
  16. # ODE_DOUBLE_DEBUG_LIBRARY - the filepath of the double-precision ode debug library
  17. # ODE_DOUBLE_RELEASE_LIBRARY - the filepath of the double-precision ode release library
  18. #
  19. # ODE::ODE - The recommended ODE library to link against
  20. # ODE::ODE_single - If available, this links against single-precision ODE
  21. # ODE::ODE_double - If available, this links against double-precision ODE
  22. #
  23. # Find the libode include files
  24. find_path(ODE_INCLUDE_DIR "ode/ode.h")
  25. # Find the libode library built for release
  26. find_library(ODE_RELEASE_LIBRARY
  27. NAMES "ode" "libode")
  28. # Find the libode library built for debug
  29. find_library(ODE_DEBUG_LIBRARY
  30. NAMES "oded" "liboded")
  31. # Find the single-precision library built for release
  32. find_library(ODE_SINGLE_RELEASE_LIBRARY
  33. NAMES "ode_single" "libode_single")
  34. # Find the single-precision library built for debug
  35. find_library(ODE_SINGLE_DEBUG_LIBRARY
  36. NAMES "ode_singled" "libode_singled")
  37. # Find the double-precision library built for release
  38. find_library(ODE_DOUBLE_RELEASE_LIBRARY
  39. NAMES "ode_double" "libode_double")
  40. # Find the double-precision library built for debug
  41. find_library(ODE_DOUBLE_DEBUG_LIBRARY
  42. NAMES "ode_doubled" "libode_doubled")
  43. # Find libccd, which ODE sometimes links against, so we want to let the linker
  44. # know about it if it's present.
  45. find_library(ODE_LIBCCD_LIBRARY
  46. NAMES "ccd" "libccd")
  47. mark_as_advanced(ODE_INCLUDE_DIR)
  48. mark_as_advanced(ODE_RELEASE_LIBRARY)
  49. mark_as_advanced(ODE_DEBUG_LIBRARY)
  50. mark_as_advanced(ODE_SINGLE_RELEASE_LIBRARY)
  51. mark_as_advanced(ODE_SINGLE_DEBUG_LIBRARY)
  52. mark_as_advanced(ODE_DOUBLE_RELEASE_LIBRARY)
  53. mark_as_advanced(ODE_DOUBLE_DEBUG_LIBRARY)
  54. mark_as_advanced(ODE_LIBCCD_LIBRARY)
  55. # Define targets for both precisions (and unspecified)
  56. foreach(_precision _single _double "")
  57. string(TOUPPER "${_precision}" _PRECISION)
  58. if(EXISTS "${ODE${_PRECISION}_RELEASE_LIBRARY}" OR
  59. EXISTS "${ODE${_PRECISION}_DEBUG_LIBRARY}")
  60. if(NOT TARGET ODE::ODE${_precision})
  61. add_library(ODE::ODE${_precision} UNKNOWN IMPORTED GLOBAL)
  62. set_target_properties(ODE::ODE${_precision} PROPERTIES
  63. INTERFACE_INCLUDE_DIRECTORIES "${ODE_INCLUDE_DIR}")
  64. if(ODE_LIBCCD_LIBRARY)
  65. set_target_properties(ODE::ODE${_precision} PROPERTIES
  66. INTERFACE_LINK_LIBRARIES "${ODE_LIBCCD_LIBRARY}")
  67. endif()
  68. if(EXISTS "${ODE${_PRECISION}_RELEASE_LIBRARY}")
  69. set_property(TARGET ODE::ODE${_precision} APPEND PROPERTY
  70. IMPORTED_CONFIGURATIONS RELEASE)
  71. set_target_properties(ODE::ODE${_precision} PROPERTIES
  72. IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C"
  73. IMPORTED_LOCATION_RELEASE "${ODE${_PRECISION}_RELEASE_LIBRARY}")
  74. endif()
  75. if(EXISTS "${ODE${_PRECISION}_DEBUG_LIBRARY}")
  76. set_property(TARGET ODE::ODE${_precision} APPEND PROPERTY
  77. IMPORTED_CONFIGURATIONS DEBUG)
  78. set_target_properties(ODE::ODE${_precision} PROPERTIES
  79. IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C"
  80. IMPORTED_LOCATION_DEBUG "${ODE${_PRECISION}_DEBUG_LIBRARY}")
  81. endif()
  82. # If this has a precision, we should be sure to define
  83. # dIDESINGLE/dIDEDOUBLE to keep it consistent
  84. if(_precision)
  85. string(REPLACE "_" "dIDE" _precision_symbol "${_PRECISION}")
  86. set_target_properties(ODE::ODE${_precision} PROPERTIES
  87. INTERFACE_COMPILE_DEFINITIONS "${_precision_symbol}")
  88. unset(_precision_symbol)
  89. endif()
  90. endif()
  91. endif()
  92. endforeach(_precision)
  93. unset(_precision)
  94. unset(_PRECISION)
  95. # OKAY. If everything went well, we have ODE::ODE_single and/or
  96. # ODE::ODE_double. We might even have an ODE::ODE, but if not, we need to
  97. # alias one of the other two to it.
  98. if(NOT TARGET ODE::ODE)
  99. if(TARGET ODE::ODE_single)
  100. set(_copy_from "ODE::ODE_single")
  101. elseif(TARGET ODE::ODE_double)
  102. set(_copy_from "ODE::ODE_double")
  103. endif()
  104. if(DEFINED _copy_from)
  105. add_library(ODE::ODE UNKNOWN IMPORTED GLOBAL)
  106. foreach(_prop
  107. INTERFACE_INCLUDE_DIRECTORIES
  108. INTERFACE_COMPILE_DEFINITIONS
  109. INTERFACE_LINK_LIBRARIES
  110. IMPORTED_CONFIGURATIONS
  111. IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE
  112. IMPORTED_LOCATION_RELEASE
  113. IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG
  114. IMPORTED_LOCATION_DEBUG)
  115. get_target_property(_value "${_copy_from}" "${_prop}")
  116. if(_value)
  117. set_target_properties(ODE::ODE PROPERTIES "${_prop}" "${_value}")
  118. endif()
  119. unset(_value)
  120. endforeach(_prop)
  121. unset(_prop)
  122. endif()
  123. unset(_copy_from)
  124. endif()
  125. if(TARGET ODE::ODE)
  126. set(_HAS_ODE_LIBRARY ON)
  127. endif()
  128. include(FindPackageHandleStandardArgs)
  129. find_package_handle_standard_args(ODE DEFAULT_MSG ODE_INCLUDE_DIR _HAS_ODE_LIBRARY)
  130. unset(_HAS_ODE_LIBRARY)