Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pkg-config] Add new port #11523

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ports/pkg-config/CONTROL
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Source: pkg-config
Version: 0.29.2
Homepage: https://gitlab.freedesktop.org/pkg-config/pkg-config
Description: pkg-config is a script to make putting together all the build flags when compiling/linking a lot easier.
Build-Depends: glib[core]
49 changes: 49 additions & 0 deletions ports/pkg-config/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
set(VCPKG_POLICY_EMPTY_INCLUDE_FOLDER enabled) # Tool build no library or includes

vcpkg_from_gitlab(
GITLAB_URL https://gitlab.freedesktop.org/
OUT_SOURCE_PATH SOURCE_PATH
REPO pkg-config/pkg-config
REF edf8e6f0ea77ede073f07bff0d2ae1fc7a38103b #v0.29.2
SHA512 537bace09ff183ec793587fc7cf091d75cd5ec34efc1261227de70a15631f40558528f19dbe9e3f2eb8bc24bed21003a01c7766c849ae498031c0c1ae322e314
HEAD_REF master
)

# Remove if GLIB installs a *.pc file or keep it to make it independent of pkg-config itself
set(GLIBS "-lglib-2.0 -lgio-2.0 -lgmodule-2.0 -lgobject-2.0 -lgthread-2.0")
if(VCPKG_TARGET_IS_WINDOWS)
set(GLIB_LIBS_DEBUG "-L${CURRENT_INSTALLED_DIR}/debug/lib ${GLIBS} -lzlibd")
set(GLIB_LIBS_RELEASE "-L${CURRENT_INSTALLED_DIR}/lib ${GLIBS} -lzlib")
else()
set(GLIB_LIBS_DEBUG "-L${CURRENT_INSTALLED_DIR}/lib ${GLIBS} -lz -pthread")
set(GLIB_LIBS_RELEASE "-L${CURRENT_INSTALLED_DIR}/lib ${GLIBS} -lz -pthread")
endif()

set(ENV{GLIB_CFLAGS} "-I${CURRENT_INSTALLED_DIR}/include")
vcpkg_configure_make(
SOURCE_PATH ${SOURCE_PATH}
AUTOCONFIG
CONFIG_DEPENDENT_ENVIRONMENT "GLIB_LIBS"
)

vcpkg_install_make()

file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/tools/${PORT}/debug) # no need for debug tools

vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/${PORT}/bin)

# # Handle copyright
file(INSTALL "${SOURCE_PATH}/COPYING" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)

# pkg-config depends on glib. Note that glib build-depends on pkg-config,
# but you can just set the corresponding environment variables (ZLIB_LIBS,
# ZLIB_CFLAGS are the only needed ones when this is written) to build it.

# pkg-config also either needs an earlier version of itself to find glib
# or you need to set GLIB_CFLAGS and GLIB_LIBS to the correct values for
# where it's installed in your system.

# If this requirement is too cumbersome, a bundled copy of a recent glib
# stable release is included. Pass --with-internal-glib to configure to
# use this copy.
2 changes: 2 additions & 0 deletions scripts/ci.baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,8 @@ pixel:x64-windows=fail
pixel:x64-windows-static=fail
pixel:x86-windows=fail
pixel:x64-linux=ignore
# Make currently does not support crosscompile.
pkg-config:arm64-windows=fail
platform-folders:arm-uwp=fail
platform-folders:x64-uwp=fail
plib:arm-uwp=fail
Expand Down
49 changes: 34 additions & 15 deletions scripts/cmake/vcpkg_configure_make.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
## ### OPTIONS_DEBUG
## Additional options passed to configure during the Debug configuration. These are in addition to `OPTIONS`.
##
## ### CONFIG_DEPENDENT_ENVIRONMENT
## List of additional configuration dependent environment variables to set.
## Pass SOMEVAR to set the environment and have SOMEVAR_(DEBUG|RELEASE) set in the portfile to the appropriate values
## General environment variables can be set from within the portfile itself.
##
## ## Notes
## This command supplies many common arguments to configure. To see the full list, examine the source.
##
Expand Down Expand Up @@ -110,10 +115,10 @@ function(vcpkg_configure_make)
cmake_parse_arguments(_csc
"AUTOCONFIG;SKIP_CONFIGURE;COPY_SOURCE"
"SOURCE_PATH;PROJECT_SUBPATH;PRERUN_SHELL"
"OPTIONS;OPTIONS_DEBUG;OPTIONS_RELEASE"
"OPTIONS;OPTIONS_DEBUG;OPTIONS_RELEASE;CONFIG_DEPENDENT_ENVIRONMENT"
${ARGN}
)
# Backup enviromnent variables
# Backup environment variables
set(C_FLAGS_BACKUP "$ENV{CFLAGS}")
set(CXX_FLAGS_BACKUP "$ENV{CXXFLAGS}")
set(LD_FLAGS_BACKUP "$ENV{LDFLAGS}")
Expand Down Expand Up @@ -180,8 +185,8 @@ function(vcpkg_configure_make)
set(BUILD_TARGET "--build=${MSYS_HOST}-pc-mingw32 --target=arm-pc-mingw32 --host=i686-pc-mingw32")
endif()

macro(_vcpkg_append_to_configure_enviromnent inoutstring var defaultval)
# Allows to overwrite settings in custom triplets via the enviromnent
macro(_vcpkg_append_to_configure_environment inoutstring var defaultval)
# Allows to overwrite settings in custom triplets via the environment
if(ENV{${var}})
string(APPEND ${inoutstring} " ${var}='$ENV{${var}}'")
else()
Expand All @@ -190,16 +195,16 @@ function(vcpkg_configure_make)
endmacro()

set(CONFIGURE_ENV "")
_vcpkg_append_to_configure_enviromnent(CONFIGURE_ENV CC "${MSYS_ROOT}/usr/share/automake-1.16/compile cl.exe -nologo")
_vcpkg_append_to_configure_enviromnent(CONFIGURE_ENV CXX "${MSYS_ROOT}/usr/share/automake-1.16/compile cl.exe -nologo")
_vcpkg_append_to_configure_enviromnent(CONFIGURE_ENV LD "link.exe -verbose")
_vcpkg_append_to_configure_enviromnent(CONFIGURE_ENV AR "${MSYS_ROOT}/usr/share/automake-1.16/ar-lib lib.exe -verbose")
_vcpkg_append_to_configure_enviromnent(CONFIGURE_ENV RANLIB ":") # Trick to ignore the RANLIB call
_vcpkg_append_to_configure_enviromnent(CONFIGURE_ENV CCAS ":") # If required set the ENV variable CCAS in the portfile correctly
_vcpkg_append_to_configure_enviromnent(CONFIGURE_ENV NM "dumpbin.exe -symbols -headers -all")
_vcpkg_append_to_configure_environment(CONFIGURE_ENV CC "${MSYS_ROOT}/usr/share/automake-1.16/compile cl.exe -nologo")
_vcpkg_append_to_configure_environment(CONFIGURE_ENV CXX "${MSYS_ROOT}/usr/share/automake-1.16/compile cl.exe -nologo")
_vcpkg_append_to_configure_environment(CONFIGURE_ENV LD "link.exe -verbose")
_vcpkg_append_to_configure_environment(CONFIGURE_ENV AR "${MSYS_ROOT}/usr/share/automake-1.16/ar-lib lib.exe -verbose")
_vcpkg_append_to_configure_environment(CONFIGURE_ENV RANLIB ":") # Trick to ignore the RANLIB call
_vcpkg_append_to_configure_environment(CONFIGURE_ENV CCAS ":") # If required set the ENV variable CCAS in the portfile correctly
_vcpkg_append_to_configure_environment(CONFIGURE_ENV NM "dumpbin.exe -symbols -headers -all")
# Would be better to have a true nm here! Some symbols (mainly exported variables) get not properly imported with dumpbin as nm
# and require __declspec(dllimport) for some reason (same problem CMake has with WINDOWS_EXPORT_ALL_SYMBOLS)
_vcpkg_append_to_configure_enviromnent(CONFIGURE_ENV DLLTOOL "link.exe -verbose -dll")
_vcpkg_append_to_configure_environment(CONFIGURE_ENV DLLTOOL "link.exe -verbose -dll")

# Other maybe interesting variables to control
# COMPILE This is the command used to actually compile a C source file. The file name is appended to form the complete command line.
Expand Down Expand Up @@ -281,7 +286,7 @@ function(vcpkg_configure_make)
list(JOIN _csc_OPTIONS_DEBUG " " _csc_OPTIONS_DEBUG)
endif()

# Setup include enviromnent
# Setup include environment
set(ENV{INCLUDE} "${_VCPKG_INSTALLED}/include${VCPKG_HOST_PATH_SEPARATOR}${INCLUDE_BACKUP}")
set(ENV{INCLUDE_PATH} "${_VCPKG_INSTALLED}/include${VCPKG_HOST_PATH_SEPARATOR}${INCLUDE_PATH_BACKUP}")
set(ENV{C_INCLUDE_PATH} "${_VCPKG_INSTALLED}/include${VCPKG_HOST_PATH_SEPARATOR}${C_INCLUDE_PATH_BACKUP}")
Expand Down Expand Up @@ -421,6 +426,12 @@ function(vcpkg_configure_make)
endif()

foreach(_buildtype IN LISTS _buildtypes)
foreach(ENV_VAR ${_csc_CONFIG_DEPENDENT_ENVIRONMENT})
if(ENV{${ENV_VAR}})
set(BACKUP_CONFIG_${ENV_VAR} "$ENV{${ENV_VAR}}")
endif()
set(ENV{${ENV_VAR}} "${${ENV_VAR}_${_buildtype}}")
endforeach()
set(TAR_DIR "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${SHORT_NAME_${_buildtype}}")
file(MAKE_DIRECTORY "${TAR_DIR}")
file(RELATIVE_PATH RELATIVE_BUILD_PATH "${TAR_DIR}" "${SRC_DIR}")
Expand All @@ -440,7 +451,7 @@ function(vcpkg_configure_make)
set(ENV{PKG_CONFIG_PATH} "${PKGCONFIG_INSTALLED_DIR}:${PKGCONFIG_INSTALLED_SHARE_DIR}")
endif()

# Setup enviromnent
# Setup environment
set(ENV{CFLAGS} ${CFLAGS_${_buildtype}})
set(ENV{CXXFLAGS} ${CXXFLAGS_${_buildtype}})
set(ENV{LDFLAGS} ${LDFLAGS_${_buildtype}})
Expand Down Expand Up @@ -477,9 +488,17 @@ function(vcpkg_configure_make)
unset(ENV{PKG_CONFIG_PATH})
endif()
unset(BACKUP_ENV_PKG_CONFIG_PATH_${_buildtype})

foreach(ENV_VAR ${_csc_CONFIG_DEPENDENT_ENVIRONMENT})
if(BACKUP_CONFIG_${ENV_VAR})
set(ENV{${ENV_VAR}} "${BACKUP_CONFIG_${ENV_VAR}}")
else()
unset(ENV{${ENV_VAR}})
endif()
endforeach()
endforeach()

# Restore enviromnent
# Restore environment
set(ENV{CFLAGS} "${C_FLAGS_BACKUP}")
set(ENV{CXXFLAGS} "${CXX_FLAGS_BACKUP}")
set(ENV{LDFLAGS} "${LD_FLAGS_BACKUP}")
Expand Down