vcpkg/ports/ignition-modularscripts/ignition_modular_library.cmake
Alexander Neumann 458c20e94b
[vcpkg/scripts/pkgconfig] rewrite pkg-config check for libraries (#11550)
* [vcpkg/scripts/pkgconfig] rewrite pkgconfig check for libraries.

* [vcpkg/scripts/pkgconfig] fix more details.

* [vcpkg/scripts/pkgconfig] smaller improvements

* ws change to check functionallity of script for testing.

* [vcpkg/scripts/pkgconfig] update to latest test version

* Revert "ws change to check functionallity of script for testing."

This reverts commit 26269e9e77.

* [nettle] bump control for vcpkg_fixup_pkgconfig test

* [gmp] rerun CI to create new *.pc files

* [gmp/nettle] enable port debug

* [vcpkg/script/pkgconfig] fix path conversion regex for CI

* [CI|OSX] install pkg-config on osx

* [gmp/nettle] disable port debug

* [vcpkg/scripts/pkgconfig] update to latest version of x windows pr

* [zlib] add pkgconfig file

* [zstd] add fixup pkgconfig

* [libpng] add pc file installation

* [bzip2] install pc file and leave a TODO for somebody else ;)

* [bzip2] bump control

* [vcpkg/scripts/pkgconfig] skip checks if pkgconfig cannot be found.
- small bugfix in ignore flags regex

* retry zstd and zlib

* [libpng] retry by adding dl and m to system libraries for osx

* [libpng] add missing vcpkg_fixup_pkgconfig()

* [vcpkg/scripts/pkgconfig] unset var if found. 

fixes checks for other configurations which will be always succesful otherwise

* [libpng] bump control

* [libpng] enable port debug to debug osx regression

* ws change to retrigger osx ci and hopeing that it works

* fix typo

* [libpng] remove -lm flag on apple platforms

* ws change to rerun some ports in ci for good measure after the merge with master

* Re-trigger CI test

* [zstd] add pkgconfig

* [zstd] correct debug link

* [vcpkg/script/pkgconfig] - add more search suffixes for static libs
- add additional debug messages for debuging
- fix unsetting of cache variables hiding issues with debug libraries
- fixed pkgconfig fix in the debug case

* [pcre] add pthread dependency to pcre

* [protobuf] fix pkgconfig

* include quotes around the prefix in the case the prefix path was quoted (fixes some regressions)
add option NOT_STATIC_PKGCONFIG to run pkg-config without the --static argument

* [ignition-msgs5] get rid of a dev warning

* [apr] fix apr regression

* [protobuf] fix protobuf regression

* [sdl1] fix regression due to variable expansion of pkg-config. Use similar regex to the library removal for ignored flags.

* [ignition] fix regression

* remove changes of zlib portfile.

* reset changes in osx ci pipeline

* add DISABLE_PARALLEL_CONFIGURE

Co-authored-by: Jack·Boos·Yu <47264268+JackBoosY@users.noreply.github.com>
Co-authored-by: JackBoosY <yuzaiyang@beyondsoft.com>
Co-authored-by: Billy Robert O'Neal <bion@microsoft.com>
2020-07-24 11:39:21 -07:00

148 lines
5.9 KiB
CMake

function(ignition_modular_build_library NAME MAJOR_VERSION SOURCE_PATH CMAKE_PACKAGE_NAME DEFAULT_CMAKE_PACKAGE_NAME IML_DISABLE_PKGCONFIG_INSTALL)
vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
OPTIONS -DBUILD_TESTING=OFF
)
vcpkg_install_cmake()
# If necessary, move the CMake config files
if(EXISTS "${CURRENT_PACKAGES_DIR}/lib/cmake")
# Some ignition libraries install library subcomponents, that are effectively additional cmake packages
# with name ${CMAKE_PACKAGE_NAME}-${COMPONENT_NAME}, so it is needed to call vcpkg_fixup_cmake_targets for them as well
file(GLOB COMPONENTS_CMAKE_PACKAGE_NAMES
LIST_DIRECTORIES TRUE
RELATIVE "${CURRENT_PACKAGES_DIR}/lib/cmake/"
"${CURRENT_PACKAGES_DIR}/lib/cmake/*")
foreach(COMPONENT_CMAKE_PACKAGE_NAME IN LISTS COMPONENTS_CMAKE_PACKAGE_NAMES)
vcpkg_fixup_cmake_targets(CONFIG_PATH "lib/cmake/${COMPONENT_CMAKE_PACKAGE_NAME}"
TARGET_PATH "share/${COMPONENT_CMAKE_PACKAGE_NAME}"
DO_NOT_DELETE_PARENT_CONFIG_PATH)
endforeach()
file(GLOB_RECURSE CMAKE_RELEASE_FILES
"${CURRENT_PACKAGES_DIR}/lib/cmake/${CMAKE_PACKAGE_NAME}/*")
file(COPY ${CMAKE_RELEASE_FILES} DESTINATION
"${CURRENT_PACKAGES_DIR}/share/${CMAKE_PACKAGE_NAME}/")
endif()
# Remove unused files files
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/lib/cmake
${CURRENT_PACKAGES_DIR}/debug/include
${CURRENT_PACKAGES_DIR}/debug/lib/cmake
${CURRENT_PACKAGES_DIR}/debug/share)
# Make pkg-config files relocatable
if(NOT IML_DISABLE_PKGCONFIG_INSTALL)
if(VCPKG_TARGET_IS_LINUX)
set(SYSTEM_LIBRARIES SYSTEM_LIBRARIES pthread)
endif()
vcpkg_fixup_pkgconfig(${SYSTEM_LIBRARIES})
else()
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/lib/pkgconfig
${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig)
endif()
# Find the relevant license file and install it
if(EXISTS "${SOURCE_PATH}/LICENSE")
set(LICENSE_PATH "${SOURCE_PATH}/LICENSE")
elseif(EXISTS "${SOURCE_PATH}/README.md")
set(LICENSE_PATH "${SOURCE_PATH}/README.md")
endif()
file(INSTALL ${LICENSE_PATH} DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
endfunction()
## # ignition_modular_library
##
## Download and build a library from the Ignition Robotics project ( https://ignitionrobotics.org/ ).
##
## ## Usage:
## ```cmake
## ignition_modular_library(NAME <name>
## VERSION <version>
## SHA512 <sha512>
## [REF <ref>]
## [HEAD_REF <head_ref>]
## [PATCHES <patches>]
## [CMAKE_PACKAGE_NAME <cmake_package_name>]
## [DISABLE_PKGCONFIG_INSTALL])
## ```
##
## ## Parameters:
## ### NAME
## The name of the specific ignition library, i.e. `cmake` for `ignition-cmake0`, `math` for `ignition-math4`.
##
## ### VERSION
## The complete version number.
##
## ### SHA512
## The SHA512 hash that should match the downloaded archive. This is forwarded to the `vcpkg_from_github` command.
##
## ### REF
## Reference to the tag of the desired release. This is forwarded to the `vcpkg_from_github` command.
## If not specified, defaults to `ignition-${NAME}${MAJOR_VERSION}_${VERSION}`.
##
## ### HEAD_REF
## Reference (tag) to the desired release. This is forwarded to the `vcpkg_from_github` command.
## If not specified, defaults to `ign-${NAME}${MAJOR_VERSION}`.
##
## ### PATCHES
## A list of patches to be applied to the extracted sources.
## This is forwarded to the `vcpkg_from_github` command.
##
## ### CMAKE_PACKAGE_NAME
## The name of the CMake package for the port.
## If not specified, defaults to `ignition-${NAME}${MAJOR_VERSION}`.
##
## ### DISABLE_PKGCONFIG_INSTALL
## If present, disable installation of .pc pkg-config configuration files.
##
##
## ## Examples:
##
## * [ignition-cmake0](https://github.com/Microsoft/vcpkg/blob/master/ports/ignition-cmake0/portfile.cmake)
## * [ignition-math4](https://github.com/Microsoft/vcpkg/blob/master/ports/ignition-math4/portfile.cmake)
## * [ignition-fuel-tools1](https://github.com/Microsoft/vcpkg/blob/master/ports/ignition-fuel-tools1/portfile.cmake)
function(ignition_modular_library)
set(options DISABLE_PKGCONFIG_INSTALL)
set(oneValueArgs NAME VERSION SHA512 REF HEAD_REF CMAKE_PACKAGE_NAME)
set(multiValueArgs PATCHES)
cmake_parse_arguments(IML "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
string(REPLACE "." ";" IML_VERSION_LIST ${IML_VERSION})
list(GET IML_VERSION_LIST 0 IML_MAJOR_VERSION)
# If the REF option is omitted, use the canonical one
if(NOT DEFINED IML_REF)
set(IML_REF "ignition-${IML_NAME}${IML_MAJOR_VERSION}_${IML_VERSION}")
endif()
# If the HEAD_REF option is omitted, use the canonical one
if(NOT DEFINED IML_HEAD_REF)
set(IML_HEAD_REF "ign-${IML_NAME}${IML_MAJOR_VERSION}")
endif()
# If the CMAKE_PACKAGE_NAME option is omitted, use the canonical one
set(DEFAULT_CMAKE_PACKAGE_NAME "ignition-${IML_NAME}${IML_MAJOR_VERSION}")
if(NOT DEFINED IML_CMAKE_PACKAGE_NAME)
set(IML_CMAKE_PACKAGE_NAME ${DEFAULT_CMAKE_PACKAGE_NAME})
endif()
# Download library from github, to support also the --head option
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO ignitionrobotics/ign-${IML_NAME}
REF ${IML_REF}
SHA512 ${IML_SHA512}
HEAD_REF ${IML_HEAD_REF}
PATCHES ${IML_PATCHES}
)
# Build library
ignition_modular_build_library(${IML_NAME} ${IML_MAJOR_VERSION} ${SOURCE_PATH} ${IML_CMAKE_PACKAGE_NAME} ${DEFAULT_CMAKE_PACKAGE_NAME} ${IML_DISABLE_PKGCONFIG_INSTALL})
endfunction()