Skip to content

Commit

Permalink
Merge pull request #137 from aminya/vcpkg-rev [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored Jul 15, 2022
2 parents 5dc3e39 + 5bc9eda commit 43a63d7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,25 @@ It gets the following named parameters that can have different values in front o

## `run_vcpkg` function

```cmake
run_vcpkg()
```

Or by specifying the options
```cmake
run_vcpkg(
VCPKG_URL "https://github.com/microsoft/vcpkg.git"
VCPKG_REV "33c8f025390f8682811629b6830d2d66ecedcaa5"
ENABLE_VCPKG_UPDATE
)
```

Named Option:

- `ENABLE_VCPKG_UPDATE`: (Disabled by default). If enabled, the vcpkg registry is updated before building (using `git pull`). As a result, if some of your vcpkg dependencies have been updated in the registry, they will be rebuilt.
- `ENABLE_VCPKG_UPDATE`: (Disabled by default). If enabled, the vcpkg registry is updated before building (using `git pull`).

If `VCPKG_REV` is set to a specific commit sha, no rebuilds are triggered.
If `VCPKG_REV` is not specified or is a branch, enabling `ENABLE_VCPKG_UPDATE` will rebuild your updated vcpkg dependencies.

Named String:

Expand All @@ -249,6 +265,9 @@ Named String:

- `VCPKG_URL`: (Defaults to `https://github.com/microsoft/vcpkg.git`). This option allows setting the URL of the vcpkg repository. By default, the official vcpkg repository is used.

- `VCPKG_REV`: This option allows checking out a specific branch name or a commit sha.
If `VCPKG_REV` is set to a specific commit sha, the builds will become reproducible because that exact commit is always used for the builds. To make sure that this commit sha is pulled, enable `ENABLE_VCPKG_UPDATE`

## `target_link_system_libraries` function

A function that accepts the same arguments as `target_link_libraries`. It has the following features:
Expand Down
25 changes: 17 additions & 8 deletions src/Vcpkg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ include(FetchContent)

# Install vcpkg and vcpkg dependencies: - should be called before defining project()
macro(run_vcpkg)
# named boolean ENABLE_VCPKG_UPDATE argument
# named boolean ENABLE_VCPKG_UPDATE arguments
set(options ENABLE_VCPKG_UPDATE)
# optional named VCPKG_DIR and VCPKG_URL argument
set(oneValueArgs VCPKG_DIR VCPKG_URL)
# optional named VCPKG_DIR, VCPKG_URL, and VCPKG_REV arguments
set(oneValueArgs VCPKG_DIR VCPKG_URL VCPKG_REV)
cmake_parse_arguments(
_vcpkg_args
"${options}"
Expand All @@ -20,15 +20,15 @@ macro(run_vcpkg)
STREQUAL
"")
# the installation directory is specified
get_filename_component(VCPKG_PARENT_DIR ${_vcpkg_args_VCPKG_DIR} DIRECTORY)
get_filename_component(VCPKG_PARENT_DIR "${_vcpkg_args_VCPKG_DIR}" DIRECTORY)
else()
# Default vcpkg installation directory
if(WIN32)
set(VCPKG_PARENT_DIR $ENV{userprofile})
set(_vcpkg_args_VCPKG_DIR ${VCPKG_PARENT_DIR}/vcpkg)
set(_vcpkg_args_VCPKG_DIR "${VCPKG_PARENT_DIR}/vcpkg")
else()
set(VCPKG_PARENT_DIR $ENV{HOME})
set(_vcpkg_args_VCPKG_DIR ${VCPKG_PARENT_DIR}/vcpkg)
set(_vcpkg_args_VCPKG_DIR "${VCPKG_PARENT_DIR}/vcpkg")
endif()
endif()

Expand All @@ -40,7 +40,7 @@ macro(run_vcpkg)
message(STATUS "vcpkg is already installed at ${_vcpkg_args_VCPKG_DIR}.")
if(${_vcpkg_args_ENABLE_VCPKG_UPDATE})
message(STATUS "Updating the repository...")
execute_process(COMMAND "git" "pull" WORKING_DIRECTORY ${_vcpkg_args_VCPKG_DIR})
execute_process(COMMAND "git" "pull" WORKING_DIRECTORY "${_vcpkg_args_VCPKG_DIR}")
endif()
else()
message(STATUS "Installing vcpkg at ${_vcpkg_args_VCPKG_DIR}")
Expand All @@ -51,7 +51,7 @@ macro(run_vcpkg)
endif()
find_program(GIT_EXECUTABLE "git" REQUIRED)
execute_process(COMMAND "${GIT_EXECUTABLE}" "clone" "${_vcpkg_args_VCPKG_URL}"
WORKING_DIRECTORY ${VCPKG_PARENT_DIR} COMMAND_ERROR_IS_FATAL LAST)
WORKING_DIRECTORY "${VCPKG_PARENT_DIR}" COMMAND_ERROR_IS_FATAL LAST)
endif()
# Run vcpkg bootstrap
if(WIN32)
Expand All @@ -63,6 +63,15 @@ macro(run_vcpkg)
endif()
endif()

if(NOT
"${_vcpkg_args_VCPKG_REV}"
STREQUAL
"")
find_program(GIT_EXECUTABLE "git" REQUIRED)
execute_process(COMMAND "${GIT_EXECUTABLE}" "checkout" "${_vcpkg_args_VCPKG_REV}"
WORKING_DIRECTORY "${VCPKG_PARENT_DIR}/vcpkg" COMMAND_ERROR_IS_FATAL LAST)
endif()

configure_mingw_vcpkg()

# Setting up vcpkg toolchain
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ target_link_system_libraries(
Eigen3::Eigen)
target_link_system_libraries(
lib2
PRIVATE
PRIVATE
mythirdpartylib)

# package everything automatically
Expand Down

0 comments on commit 43a63d7

Please sign in to comment.