robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Lewis RussellMerge pull request #38486 from lewis6991/testharnes9e80f63c30

master
3.1 KiB101 linesraw
1set(DEPS_INSTALL_DIR "${CMAKE_BINARY_DIR}/usr")
2set(DEPS_BIN_DIR "${DEPS_INSTALL_DIR}/bin")
3set(DEPS_LIB_DIR "${DEPS_INSTALL_DIR}/lib")
4
5set(DEPS_BUILD_DIR "${CMAKE_BINARY_DIR}/build")
6set(DEPS_DOWNLOAD_DIR "${DEPS_BUILD_DIR}/downloads")
7
8set(DEPS_CMAKE_ARGS
9  -D CMAKE_C_COMPILER=${CMAKE_C_COMPILER}
10  -D CMAKE_C_STANDARD=99
11  -D CMAKE_GENERATOR=${CMAKE_GENERATOR}
12  -D CMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
13  -D BUILD_SHARED_LIBS=OFF
14  -D CMAKE_POSITION_INDEPENDENT_CODE=ON
15  -D CMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR})
16if(APPLE)
17  list(APPEND DEPS_CMAKE_ARGS -D CMAKE_FIND_FRAMEWORK=${CMAKE_FIND_FRAMEWORK})
18endif()
19
20find_program(CACHE_PRG NAMES ccache sccache)
21mark_as_advanced(CACHE_PRG)
22if(CACHE_PRG)
23  set(CMAKE_C_COMPILER_LAUNCHER ${CMAKE_COMMAND} -E env CCACHE_SLOPPINESS=pch_defines,time_macros ${CACHE_PRG})
24  list(APPEND DEPS_CMAKE_CACHE_ARGS -DCMAKE_C_COMPILER_LAUNCHER:STRING=${CMAKE_C_COMPILER_LAUNCHER})
25endif()
26
27# MAKE_PRG
28if(UNIX)
29  find_program(MAKE_PRG NAMES gmake make)
30  mark_as_advanced(MAKE_PRG)
31  if(NOT MAKE_PRG)
32    message(FATAL_ERROR "GNU Make is required to build the dependencies.")
33  else()
34    message(STATUS "Found GNU Make at ${MAKE_PRG}")
35  endif()
36endif()
37# When using make, use the $(MAKE) variable to avoid warning about the job
38# server.
39if(CMAKE_GENERATOR MATCHES "Makefiles")
40  set(MAKE_PRG "$(MAKE)")
41endif()
42if(MINGW AND CMAKE_GENERATOR MATCHES "Ninja")
43  find_program(MAKE_PRG NAMES mingw32-make)
44  if(NOT MAKE_PRG)
45    message(FATAL_ERROR "GNU Make for mingw32 is required to build the dependencies.")
46  else()
47    message(STATUS "Found GNU Make for mingw32: ${MAKE_PRG}")
48  endif()
49endif()
50
51# DEPS_C_COMPILER
52set(DEPS_C_COMPILER "${CMAKE_C_COMPILER}")
53if(CMAKE_OSX_SYSROOT)
54  set(DEPS_C_COMPILER "${DEPS_C_COMPILER} -isysroot${CMAKE_OSX_SYSROOT}")
55endif()
56
57get_filename_component(rootdir ${PROJECT_SOURCE_DIR} NAME)
58if(${rootdir} MATCHES "cmake.deps")
59  set(depsfile ${PROJECT_SOURCE_DIR}/deps.txt)
60else()
61  set(depsfile ${PROJECT_SOURCE_DIR}/cmake.deps/deps.txt)
62endif()
63
64set_directory_properties(PROPERTIES
65  EP_PREFIX "${DEPS_BUILD_DIR}"
66  CMAKE_CONFIGURE_DEPENDS ${depsfile})
67
68file(READ ${depsfile} DEPENDENCIES)
69STRING(REGEX REPLACE "\n" ";" DEPENDENCIES "${DEPENDENCIES}")
70# Process deps.txt:
71foreach(dep ${DEPENDENCIES})
72  STRING(REGEX REPLACE " " ";" dep "${dep}")
73  list(GET dep 0 name)
74  if(${name} MATCHES "^#") # Skip comment lines.
75    continue()
76  endif()
77  list(GET dep 1 value)
78  if(NOT ${name})
79    # _URL variables must NOT be set when USE_EXISTING_SRC_DIR is set,
80    # otherwise ExternalProject will try to re-download the sources.
81    if(NOT USE_EXISTING_SRC_DIR)
82      set(${name} ${value})
83    endif()
84  endif()
85endforeach()
86
87function(get_externalproject_options name DEPS_IGNORE_SHA)
88  string(TOUPPER ${name} name_allcaps)
89  set(url ${${name_allcaps}_URL})
90
91  set(EXTERNALPROJECT_OPTIONS
92    DOWNLOAD_NO_PROGRESS TRUE
93    URL ${${name_allcaps}_URL}
94    CMAKE_CACHE_ARGS ${DEPS_CMAKE_CACHE_ARGS})
95
96  if(NOT ${DEPS_IGNORE_SHA})
97    list(APPEND EXTERNALPROJECT_OPTIONS URL_HASH SHA256=${${name_allcaps}_SHA256})
98  endif()
99
100  set(EXTERNALPROJECT_OPTIONS ${EXTERNALPROJECT_OPTIONS} PARENT_SCOPE)
101endfunction()