-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate vcpkg for dependency management
- Loading branch information
1 parent
35aee8d
commit f8bd87b
Showing
2 changed files
with
120 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,70 @@ | ||
|
||
macro(find_vcpkg) | ||
if(NOT EXISTS ${CMAKE_TOOLCHAIN_FILE}) | ||
if(NOT EXISTS ${VCPKG_EXECUTABLE}) | ||
find_program(VCPKG_EXECUTABLE vcpkg PATHS | ||
"$ENV{ProgramFiles}/Microsoft Visual Studio/*/*/VC/vcpkg/" | ||
"$ENV{USERPROFILE}$ENV{HOME}/vcpkg/" | ||
) | ||
if (EXISTS ${VCPKG_EXECUTABLE}) | ||
get_filename_component(dir ${VCPKG_EXECUTABLE} DIRECTORY) | ||
set(CMAKE_TOOLCHAIN_FILE "${dir}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file") | ||
endif () | ||
endif() | ||
if(EXISTS ${CMAKE_TOOLCHAIN_FILE}) | ||
set(VCPKG_FOUND TRUE CACHE BOOL "VCPKG toolchain file found ${CMAKE_TOOLCHAIN_FILE}") | ||
endif() | ||
if(NOT DEFINED VCPKG_ROOT) | ||
set(VCPKG_ROOT "$ENV{VCPKG_ROOT}" CACHE PATH "Path to vcpkg installation") | ||
endif() | ||
|
||
if(EXISTS "${VCPKG_ROOT}/vcpkg") | ||
set(VCPKG_EXECUTABLE "${VCPKG_ROOT}/vcpkg" CACHE FILEPATH "Path to vcpkg executable") | ||
else() | ||
find_program(VCPKG_EXECUTABLE vcpkg PATHS | ||
"$ENV{ProgramFiles}/Microsoft Visual Studio/*/*/VC/vcpkg/" | ||
"$ENV{USERPROFILE}/vcpkg/" | ||
"$ENV{HOME}/vcpkg/" | ||
) | ||
endif() | ||
|
||
if(EXISTS ${VCPKG_EXECUTABLE}) | ||
get_filename_component(VCPKG_ROOT ${VCPKG_EXECUTABLE} DIRECTORY) | ||
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file") | ||
set(VCPKG_FOUND TRUE CACHE BOOL "VCPKG found") | ||
else() | ||
set(VCPKG_FOUND FALSE CACHE BOOL "VCPKG not found") | ||
endif() | ||
endmacro() | ||
|
||
macro(fetch_vcpkg) | ||
include(gitect) | ||
if(GIT_EXECUTABLE) | ||
execute_process( | ||
COMMAND ${GIT_EXECUTABLE} clone https://github.com/microsoft/vcpkg | ||
WORKING_DIRECTORY $ENV{USERPROFILE}$ENV{HOME} | ||
) | ||
execute_process( | ||
COMMAND ${CMAKE_COMMAND} --build . | ||
WORKING_DIRECTORY ${vcpkg_SOURCE_DIR} | ||
) | ||
endif() | ||
include(gitect) | ||
if(GIT_EXECUTABLE) | ||
set(VCPKG_ROOT "$ENV{HOME}/vcpkg" CACHE PATH "Path to vcpkg installation") | ||
execute_process( | ||
COMMAND ${GIT_EXECUTABLE} clone https://github.com/microsoft/vcpkg ${VCPKG_ROOT} | ||
RESULT_VARIABLE GIT_RESULT | ||
) | ||
if(NOT GIT_RESULT EQUAL 0) | ||
message(FATAL_ERROR "Failed to clone vcpkg repository") | ||
endif() | ||
execute_process( | ||
COMMAND ${CMAKE_COMMAND} -E chdir ${VCPKG_ROOT} ${VCPKG_ROOT}/bootstrap-vcpkg.sh | ||
RESULT_VARIABLE BOOTSTRAP_RESULT | ||
) | ||
if(NOT BOOTSTRAP_RESULT EQUAL 0) | ||
message(FATAL_ERROR "Failed to bootstrap vcpkg") | ||
endif() | ||
set(VCPKG_EXECUTABLE "${VCPKG_ROOT}/vcpkg" CACHE FILEPATH "Path to vcpkg executable" FORCE) | ||
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file" FORCE) | ||
set(VCPKG_FOUND TRUE CACHE BOOL "VCPKG found" FORCE) | ||
endif() | ||
endmacro() | ||
|
||
if(NOT ${VCPKG_FOUND}) | ||
find_vcpkg() | ||
endif() | ||
find_vcpkg() | ||
|
||
option(OPENMIND_USE_VCPKG "Use vcpkg" ${VCPKG_FOUND}) | ||
option(OPENMIND_USE_VCPKG "Use vcpkg" ON) | ||
|
||
if(OPENMIND_USE_VCPKG) | ||
if(NOT ${VCPKG_FOUND}) | ||
find_vcpkg() | ||
endif() | ||
if(NOT ${VCPKG_FOUND}) | ||
fetch_vcpkg() | ||
find_vcpkg() | ||
endif() | ||
if(NOT ${VCPKG_FOUND}) | ||
message(FATAL_ERROR "VCPKG is required but not found") | ||
endif() | ||
if(VCPKG_EXECUTABLE) | ||
execute_process( | ||
COMMAND ${VCPKG_EXECUTABLE} install | ||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | ||
) | ||
endif() | ||
endif (OPENMIND_USE_VCPKG) | ||
if(NOT VCPKG_FOUND) | ||
fetch_vcpkg() | ||
endif() | ||
if(NOT VCPKG_FOUND) | ||
message(FATAL_ERROR "VCPKG is required but not found") | ||
endif() | ||
if(VCPKG_EXECUTABLE) | ||
execute_process( | ||
COMMAND ${VCPKG_EXECUTABLE} install | ||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | ||
RESULT_VARIABLE VCPKG_RESULT | ||
) | ||
if(NOT VCPKG_RESULT EQUAL 0) | ||
message(FATAL_ERROR "Failed to install dependencies using vcpkg") | ||
endif() | ||
endif() | ||
endif() |