| 1 |
if (NOT ${PROJECT_NAME}_DEPS_PRESET) |
| 2 |
set (${PROJECT_NAME}_DEPS_PRESET "default") |
| 3 |
endif () |
| 4 |
|
| 5 |
set (_output_quiet "") |
| 6 |
if (${PROJECT_NAME}_DEPS_OUTPUT_QUIET) |
| 7 |
set (_output_quiet OUTPUT_QUIET) |
| 8 |
endif () |
| 9 |
|
| 10 |
message(STATUS "Building the dependencies with preset ${${PROJECT_NAME}_DEPS_PRESET}") |
| 11 |
|
| 12 |
set(_gen_arg "") |
| 13 |
if (CMAKE_GENERATOR) |
| 14 |
set (_gen_arg "-G${CMAKE_GENERATOR}") |
| 15 |
endif () |
| 16 |
|
| 17 |
set(_build_args "") |
| 18 |
|
| 19 |
if (CMAKE_C_COMPILER) |
| 20 |
list(APPEND _build_args "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}") |
| 21 |
endif () |
| 22 |
|
| 23 |
if (CMAKE_CXX_COMPILER) |
| 24 |
list(APPEND _build_args "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}") |
| 25 |
endif () |
| 26 |
|
| 27 |
if (CMAKE_TOOLCHAIN_FILE) |
| 28 |
list(APPEND _build_args "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}") |
| 29 |
endif () |
| 30 |
|
| 31 |
if (${PROJECT_NAME}_DEPS_SHARED) # if deps needs to be built as shared libs |
| 32 |
list(APPEND _build_args "-DBUILD_SHARED_LIBS:BOOL=ON") |
| 33 |
endif () |
| 34 |
|
| 35 |
if (BUILD_SHARED_LIBS) # forward if PIC is needed (static deps but project is shared library) |
| 36 |
list(APPEND _build_args "-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON") |
| 37 |
endif () |
| 38 |
|
| 39 |
set(_build_dir "${CMAKE_CURRENT_LIST_DIR}/build-${${PROJECT_NAME}_DEPS_PRESET}") |
| 40 |
if (${PROJECT_NAME}_DEPS_BUILD_DIR) |
| 41 |
set(_build_dir "${${PROJECT_NAME}_DEPS_BUILD_DIR}") |
| 42 |
endif () |
| 43 |
|
| 44 |
message(STATUS "build dir = ${_build_dir}") |
| 45 |
|
| 46 |
set(_preset_arg "--preset ${${PROJECT_NAME}_DEPS_PRESET}") |
| 47 |
if (CMAKE_VERSION VERSION_LESS 3.19) |
| 48 |
message(WARNING "CMake presets are not supported with this version of CMake. Building all dependency packages!") |
| 49 |
set(_preset_arg "." ) |
| 50 |
list(APPEND _build_args "-DLibBGCode_Deps_BUILD_ALL:BOOL=ON") |
| 51 |
endif () |
| 52 |
|
| 53 |
execute_process( |
| 54 |
COMMAND ${CMAKE_COMMAND} "${_preset_arg}" "${_gen_arg}" -B ${_build_dir} ${_build_args} |
| 55 |
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} |
| 56 |
${_output_quiet} |
| 57 |
ERROR_VARIABLE _deps_configure_output |
| 58 |
RESULT_VARIABLE _deps_configure_result |
| 59 |
) |
| 60 |
|
| 61 |
if (NOT _deps_configure_result EQUAL 0) |
| 62 |
message(FATAL_ERROR "Dependency configure failed with output:\n${_deps_configure_output}") |
| 63 |
else () |
| 64 |
execute_process( |
| 65 |
COMMAND ${CMAKE_COMMAND} --build . |
| 66 |
WORKING_DIRECTORY ${_build_dir} |
| 67 |
${_output_quiet} |
| 68 |
ERROR_VARIABLE _deps_build_output |
| 69 |
RESULT_VARIABLE _deps_build_result |
| 70 |
) |
| 71 |
if (NOT _deps_build_result EQUAL 0) |
| 72 |
message(FATAL_ERROR "Dependency build failed with output:\n${_deps_build_output}") |
| 73 |
endif () |
| 74 |
endif () |
| 75 |
|
| 76 |
if (${PROJECT_NAME}_DEPS_PRESET STREQUAL "wasm") |
| 77 |
list(APPEND CMAKE_FIND_ROOT_PATH ${_build_dir}/destdir/usr/local) |
| 78 |
set(CMAKE_FIND_ROOT_PATH "${CMAKE_FIND_ROOT_PATH}" CACHE STRING "" FORCE) |
| 79 |
else () |
| 80 |
list(APPEND CMAKE_PREFIX_PATH ${_build_dir}/destdir/usr/local) |
| 81 |
set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH}" CACHE STRING "" FORCE) |
| 82 |
endif () |