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