forked from micahpearlman/MonkVG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_external_proj.cmake
39 lines (32 loc) · 1.52 KB
/
build_external_proj.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# --------------------------------------------------
# Builds a external project at configuration time instead of build time
# See: https://gist.github.com/amir-saniyan/4339e6f3ef109c75eda8018f7d5192a7
function (build_external_git_project target git_url)
set(CMAKELIST_CONTENT "
cmake_minimum_required(VERSION ${CMAKE_MINIMUM_REQUIRED_VERSION})
project(build_external_git_project)
include(ExternalProject)
ExternalProject_add(${target}
GIT_REPOSITORY \"${git_url}\"
CMAKE_GENERATOR \"${CMAKE_GENERATOR}\"
CMAKE_GENERATOR_PLATFORM \"${CMAKE_GENERATOR_PLATFORM}\"
CMAKE_GENERATOR_TOOLSET \"${CMAKE_GENERATOR_TOOLSET}\"
CMAKE_GENERATOR_INSTANCE \"${CMAKE_GENERATOR_INSTANCE}\"
CMAKE_ARGS ${ARGN}
LOG_DOWNLOAD 1 LOG_UPDATE 1 LOG_CONFIGURE 1 LOG_BUILD 1 LOG_INSTALL 1)
add_custom_target(build_external_project)
add_dependencies(build_external_project ${target})
")
set(TARGET_DIR "${CMAKE_CURRENT_BINARY_DIR}/ExternalProjects/${target}")
file(WRITE "${TARGET_DIR}/CMakeLists.txt" "${CMAKELIST_CONTENT}")
file(MAKE_DIRECTORY "${TARGET_DIR}" "${TARGET_DIR}/build")
execute_process(COMMAND ${CMAKE_COMMAND}
-G "${CMAKE_GENERATOR}"
-A "${CMAKE_GENERATOR_PLATFORM}"
-T "${CMAKE_GENERATOR_TOOLSET}"
..
WORKING_DIRECTORY "${TARGET_DIR}/build")
execute_process(COMMAND ${CMAKE_COMMAND}
--build .
WORKING_DIRECTORY "${TARGET_DIR}/build")
endfunction()