Skip to content

Commit

Permalink
[vcpkg-ci-cmake-toolchain-file] Validate toolchain file (microsoft#43527
Browse files Browse the repository at this point in the history
)
  • Loading branch information
dg0yt authored Feb 6, 2025
1 parent 9f1ac32 commit 8143d2e
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)

vcpkg_cmake_configure(
SOURCE_PATH "${CURRENT_PORT_DIR}/project"
DISABLE_PARALLEL_CONFIGURE # keep separate logs
)
vcpkg_cmake_build()
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 3.30)
project(cmake-toolchain-file-test C CXX)

foreach(var IN ITEMS
CMAKE_SYSROOT
CMAKE_FIND_ROOT_PATH
CMAKE_PREFIX_PATH
CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES
CMAKE_SYSTEM_IGNORE_PATH
CMAKE_FIND_ROOT_PATH_MODE_LIBRARY
)
list(JOIN "${var}" "\n " dirs)
message("" "${var}:\n ${dirs}\n")
endforeach()

set(CMAKE_FIND_DEBUG_MODE 1)
set(link_libs "")
set(implicit_link_libs "${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES}")
list(REMOVE_ITEM implicit_link_libs ${CMAKE_C_IMPLICIT_LINK_LIBRARIES})
foreach(lib IN LISTS implicit_link_libs)
if(EXISTS "${lib}")
message("" "Absolute path: ${lib}\n")
else()
string(MAKE_C_IDENTIFIER "${lib}" id)
find_library(${id}_LIBRARY NAMES "${lib}" NO_CACHE)
if(NOT ${id}_LIBRARY)
find_library(${id}_LIBRARY NAMES "${lib}" PATHS ${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES} NO_DEFAULT_PATH NO_CACHE)
endif()
list(APPEND link_libs "${${id}_LIBRARY}")
endif()
endforeach()

# Pull link errors into config step set of log files
try_compile(link_libs_accepted
SOURCES "${CMAKE_CURRENT_LIST_DIR}/main.c"
LINK_LIBRARIES ${link_libs}
LOG_DESCRIPTION "Checking linking with ${link_libs}"
OUTPUT_VARIABLE output
)
if(NOT link_libs_accepted)
message(FATAL_ERROR "${output}")
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stdio.h>

int main()
{
printf("Hello %s\n", "world");
return 0;
}
13 changes: 13 additions & 0 deletions scripts/test_ports/vcpkg-ci-cmake-toolchain-file/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "vcpkg-ci-cmake-toolchain-file",
"version-string": "ci",
"description": "Validate vcpkg.cmake toolchain file",
"homepage": "https://github.com/microsoft/vcpkg",
"license": "MIT",
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true
}
]
}
5 changes: 5 additions & 0 deletions scripts/toolchains/android.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ endif()

include("${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake")

# find_library must ignore host libs
if(ANDROID_TOOLCHAIN_ROOT AND EXISTS "${ANDROID_TOOLCHAIN_ROOT}/lib")
list(APPEND CMAKE_SYSTEM_IGNORE_PATH "${ANDROID_TOOLCHAIN_ROOT}/lib")
endif()

if(NOT _VCPKG_ANDROID_TOOLCHAIN)
set(_VCPKG_ANDROID_TOOLCHAIN 1)

Expand Down

0 comments on commit 8143d2e

Please sign in to comment.