@@ -30,6 +30,7 @@ vcpkg_from_github(
3030# than the one required by ubuntu-insights (1.26).
3131find_program (GO_EXECUTABLE NAMES go HINTS ENV GO_EXECUTABLE_DIR REQUIRED )
3232
33+ # Set up the common go environment that will be used to build the tools and the C-API
3334set (GO_ENV
3435 CGO_ENABLED=1
3536 # An unset CGO_CFLAGS makes the upstream generator add -Werror and pedantic warnings
@@ -41,21 +42,10 @@ if(VCPKG_TARGET_IS_OSX AND VCPKG_OSX_DEPLOYMENT_TARGET)
4142 list (APPEND GO_ENV "MACOSX_DEPLOYMENT_TARGET=${VCPKG_OSX_DEPLOYMENT_TARGET} " )
4243endif ()
4344
44- function (add_insights_tool tool package )
45- vcpkg_execute_required_process (
46- COMMAND
47- "${CMAKE_COMMAND } " -E env ${GO_ENV}
48- "${GO_EXECUTABLE} " build -trimpath
49- -o "${tools_dir} /${tool}${VCPKG_TARGET_EXECUTABLE_SUFFIX} " "${package} "
50- WORKING_DIRECTORY "${SOURCE_PATH} "
51- LOGNAME "build-${tool} "
52- )
53- list (APPEND INSIGHTS_TOOLS "${tool} " )
54- set (INSIGHTS_TOOLS "${INSIGHTS_TOOLS} " PARENT_SCOPE )
55- endfunction ()
56-
57- set (INSIGHTS_TOOLS "" )
58-
45+ # If on Windows, acquire MinGW which is required for building the C API.
46+ #
47+ # TODO: The acquired MinGW targets the legacy C runtime (CRT). Update it to use
48+ # the UCRT packages instead. For now this should be ok.
5949if (VCPKG_TARGET_IS_WINDOWS)
6050 include ("${CMAKE_CURRENT_LIST_DIR } /../../vcpkg-port-utils/mingw/acquire-mingw-msys.cmake" )
6151 multipass_acquire_mingw_msys (MSYS_ROOT )
@@ -64,9 +54,31 @@ if(VCPKG_TARGET_IS_WINDOWS)
6454 "CC=${MINGW_BIN} /gcc.exe"
6555 --modify "PATH=path_list_prepend:${MINGW_BIN} "
6656 )
57+
58+ set (C_API_ENV ${GO_ENV} )
59+ set (INSIGHTS_DEF "${CURRENT_BUILDTREES_DIR} /${TARGET_TRIPLET} -insights.def" )
60+ list (APPEND C_API_ENV "CGO_LDFLAGS=-Wl,--output-def,\" ${INSIGHTS_DEF} \" " )
61+ else ()
62+ set (C_API_ENV ${GO_ENV} )
6763endif ()
6864
65+ set (INSIGHTS_TOOLS "" )
66+
67+ # Build the tools if the feature is requested
6968if ("tools" IN_LIST FEATURES)
69+ function (add_insights_tool tool package )
70+ vcpkg_execute_required_process (
71+ COMMAND
72+ "${CMAKE_COMMAND } " -E env ${GO_ENV}
73+ "${GO_EXECUTABLE} " build -trimpath
74+ -o "${tools_dir} /${tool}${VCPKG_TARGET_EXECUTABLE_SUFFIX} " "${package} "
75+ WORKING_DIRECTORY "${SOURCE_PATH} "
76+ LOGNAME "build-${tool} "
77+ )
78+ list (APPEND INSIGHTS_TOOLS "${tool} " )
79+ set (INSIGHTS_TOOLS "${INSIGHTS_TOOLS} " PARENT_SCOPE )
80+ endfunction ()
81+
7082 set (tools_dir "${CURRENT_PACKAGES_DIR} /tools/${PORT} " )
7183 file (MAKE_DIRECTORY "${tools_dir} " )
7284
@@ -77,9 +89,10 @@ if("tools" IN_LIST FEATURES)
7789 endif ()
7890endif ()
7991
92+ # Build the C-API
8093vcpkg_execute_required_process (
8194 COMMAND
82- "${CMAKE_COMMAND } " -E env ${GO_ENV }
95+ "${CMAKE_COMMAND } " -E env ${C_API_ENV }
8396 "${GO_EXECUTABLE} " run -tags=tools ./generate/...
8497 WORKING_DIRECTORY "${SOURCE_PATH} /insights/C"
8598 LOGNAME build -c-api
@@ -88,26 +101,31 @@ vcpkg_execute_required_process(
88101if (VCPKG_TARGET_IS_WINDOWS)
89102 # Generate an import library, otherwise MSVC will not be able to link against the generated dll
90103 file (MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR} /lib" )
91- set (INSIGHTS_IMPLIB insights .lib)
104+ set (INSIGHTS_IMPLIB libinsights .lib)
92105 find_program (lib_tool NAMES lib.exe llvm-lib REQUIRED )
93106 vcpkg_execute_required_process (
94- COMMAND "${lib_tool} " "/def:${CMAKE_CURRENT_LIST_DIR } /insights.def " /machine:x64
95- "/out:${CURRENT_PACKAGES_DIR} /lib/${INSIGHTS_IMPLIB} "
107+ COMMAND "${lib_tool} " "/def:${INSIGHTS_DEF} " /machine:x64
108+ "/out:${CURRENT_PACKAGES_DIR} /lib/${INSIGHTS_IMPLIB} "
96109 WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR} "
97110 LOGNAME import-library
98111 )
99112
100- file (INSTALL "${SOURCE_PATH} /insights/generated/${INSIGHTS_LIBRARY} "
101- DESTINATION "${CURRENT_PACKAGES_DIR} /bin" )
113+ file (INSTALL "${SOURCE_PATH} /insights/generated/${INSIGHTS_LIBRARY} "
114+ DESTINATION "${CURRENT_PACKAGES_DIR} /bin" )
102115
103- # libinsights is built in a single configuration, but vcpkg's applocal
116+ # libinsights is built with a single configuration, but vcpkg's applocal
104117 # searches only debug/bin for DLLs when building Debug executables.
105118 # Copy the DLL there as well so it can be deployed automatically.
106- file (INSTALL "${SOURCE_PATH} /insights/generated/${INSIGHTS_LIBRARY} "
107- DESTINATION "${CURRENT_PACKAGES_DIR} /debug/bin" )
119+ #
120+ # We also copy the lib import library so that vcpkg doesn't issue a warning
121+ # for a dll without an accompany import library.
122+ file (INSTALL "${SOURCE_PATH} /insights/generated/${INSIGHTS_LIBRARY} "
123+ DESTINATION "${CURRENT_PACKAGES_DIR} /debug/bin" )
124+ file (INSTALL "${CURRENT_PACKAGES_DIR} /lib/${INSIGHTS_IMPLIB} "
125+ DESTINATION "${CURRENT_PACKAGES_DIR} /debug/lib/" )
108126else ()
109- file (INSTALL "${SOURCE_PATH} /insights/generated/${INSIGHTS_LIBRARY} "
110- DESTINATION "${CURRENT_PACKAGES_DIR} /lib" )
127+ file (INSTALL "${SOURCE_PATH} /insights/generated/${INSIGHTS_LIBRARY} "
128+ DESTINATION "${CURRENT_PACKAGES_DIR} /lib" )
111129endif ()
112130
113131file (INSTALL
0 commit comments