cmake.m4 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. dnl Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. dnl file LICENSE.rst or https://cmake.org/licensing for details.
  3. # CMAKE_FIND_BINARY
  4. # -----------------
  5. # Finds the cmake command-line binary and sets its absolute path in the
  6. # CMAKE_BINARY variable.
  7. AC_DEFUN([CMAKE_FIND_BINARY],
  8. [AC_ARG_VAR([CMAKE_BINARY], [path to the cmake binary])dnl
  9. if test "x$ac_cv_env_CMAKE_BINARY_set" != "xset"; then
  10. AC_PATH_TOOL([CMAKE_BINARY], [cmake])dnl
  11. fi
  12. ])dnl
  13. # CMAKE_FIND_PACKAGE(package, lang, [compiler-id], [cmake-args],
  14. # [action-if-found], [action-if-not-found])
  15. # --------------------------------------------------------------
  16. # Finds a package with CMake.
  17. #
  18. # package:
  19. # The name of the package as called in CMake with find_package(package).
  20. #
  21. # lang:
  22. # The programming language to use (e.g., C, CXX, Fortran).
  23. # See https://cmake.org/cmake/help/latest/command/enable_language.html
  24. # for a complete list of supported languages.
  25. #
  26. # compiler-id:
  27. # (Optional) The compiler ID to use. Defaults to GNU.
  28. # See https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html
  29. # for possible values.
  30. #
  31. # cmake-args:
  32. # (Optional) Additional arguments to pass to cmake command, e.g.,
  33. # -DCMAKE_SIZEOF_VOID_P=8.
  34. #
  35. # action-if-found:
  36. # (Optional) Commands to execute if the package is found.
  37. #
  38. # action-if-not-found:
  39. # (Optional) Commands to execute if the package is not found.
  40. AC_DEFUN([CMAKE_FIND_PACKAGE], [
  41. AC_REQUIRE([CMAKE_FIND_BINARY])dnl
  42. AC_ARG_VAR([$1][_][$2][FLAGS], [$2 compiler flags for $1. This overrides the cmake output])dnl
  43. AC_ARG_VAR([$1][_LIBS], [linker flags for $1. This overrides the cmake output])dnl
  44. failed=false
  45. AC_MSG_CHECKING([for $1])
  46. if test -z "${$1[]_$2[]FLAGS}"; then
  47. $1[]_$2[]FLAGS=`$CMAKE_BINARY --find-package "-DNAME=$1" "-DCOMPILER_ID=m4_default([$3], [GNU])" "-DLANGUAGE=$2" -DMODE=COMPILE $4` || failed=true
  48. fi
  49. if test -z "${$1[]_LIBS}"; then
  50. $1[]_LIBS=`$CMAKE_BINARY --find-package "-DNAME=$1" "-DCOMPILER_ID=m4_default([$3], [GNU])" "-DLANGUAGE=$2" -DMODE=LINK $4` || failed=true
  51. fi
  52. if $failed; then
  53. unset $1[]_$2[]FLAGS
  54. unset $1[]_LIBS
  55. AC_MSG_RESULT([no])
  56. $6
  57. else
  58. AC_MSG_RESULT([yes])
  59. $5
  60. fi[]dnl
  61. ])