autobuild.cmake 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. if (NOT ${PROJECT_NAME}_DEPS_PRESET)
  2. set (${PROJECT_NAME}_DEPS_PRESET "default")
  3. endif ()
  4. set (_output_quiet "")
  5. if (${PROJECT_NAME}_DEPS_OUTPUT_QUIET)
  6. set (_output_quiet OUTPUT_QUIET)
  7. endif ()
  8. message(STATUS "Building the dependencies with preset ${${PROJECT_NAME}_DEPS_PRESET}")
  9. set(_gen_arg "")
  10. if (CMAKE_GENERATOR)
  11. set (_gen_arg "-G${CMAKE_GENERATOR}")
  12. endif ()
  13. set(_build_args "")
  14. if (CMAKE_C_COMPILER)
  15. list(APPEND _build_args "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
  16. endif ()
  17. if (CMAKE_CXX_COMPILER)
  18. list(APPEND _build_args "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
  19. endif ()
  20. if (CMAKE_TOOLCHAIN_FILE)
  21. list(APPEND _build_args "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")
  22. endif ()
  23. set(_build_dir "${CMAKE_CURRENT_LIST_DIR}/build-${${PROJECT_NAME}_DEPS_PRESET}")
  24. if (${PROJECT_NAME}_DEPS_BUILD_DIR)
  25. set(_build_dir "${${PROJECT_NAME}_DEPS_BUILD_DIR}")
  26. endif ()
  27. message(STATUS "build dir = ${_build_dir}")
  28. execute_process(
  29. COMMAND ${CMAKE_COMMAND} --preset ${${PROJECT_NAME}_DEPS_PRESET} "${_gen_arg}" -B ${_build_dir} ${_build_args}
  30. WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
  31. ${_output_quiet}
  32. ERROR_VARIABLE _deps_configure_output
  33. RESULT_VARIABLE _deps_configure_result
  34. )
  35. if (NOT _deps_configure_result EQUAL 0)
  36. message(FATAL_ERROR "Dependency configure failed with output:\n${_deps_configure_output}")
  37. else ()
  38. execute_process(
  39. COMMAND ${CMAKE_COMMAND} --build .
  40. WORKING_DIRECTORY ${_build_dir}
  41. ${_output_quiet}
  42. ERROR_VARIABLE _deps_build_output
  43. RESULT_VARIABLE _deps_build_result
  44. )
  45. if (NOT _deps_build_result EQUAL 0)
  46. message(FATAL_ERROR "Dependency build failed with output:\n${_deps_build_output}")
  47. endif ()
  48. endif ()
  49. list(APPEND CMAKE_PREFIX_PATH ${_build_dir}/destdir/usr/local)
  50. set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH}" CACHE STRING "")