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

[bzip2] fixes for building release-only #12759

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
9 changes: 5 additions & 4 deletions ports/bzip2/CONTROL
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Source: bzip2
Version: 1.0.6-6
Homepage: http://www.bzip.org/
Description: High-quality data compressor.
Source: bzip2
Version: 1.0.6
Port-Version: 7
Homepage: http://www.bzip.org/
Description: High-quality data compressor.
103 changes: 52 additions & 51 deletions ports/bzip2/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,51 +1,52 @@
include(vcpkg_common_functions)
set(BZIP2_VERSION 1.0.6) # TODO: Update to 1.0.8
vcpkg_download_distfile(ARCHIVE # TODO: switch to vcpkg_from_git with https://sourceware.org/git/?p=bzip2.git;a=summary
URLS "https://github.com/past-due/bzip2-mirror/releases/download/v${BZIP2_VERSION}/bzip2-${BZIP2_VERSION}.tar.gz"
FILENAME "bzip2-${BZIP2_VERSION}.tar.gz"
SHA512 00ace5438cfa0c577e5f578d8a808613187eff5217c35164ffe044fbafdfec9e98f4192c02a7d67e01e5a5ccced630583ad1003c37697219b0f147343a3fdd12)

vcpkg_extract_source_archive_ex(
OUT_SOURCE_PATH SOURCE_PATH
ARCHIVE ${ARCHIVE}
REF ${BZIP2_VERSION}
PATCHES
fix-import-export-macros.patch
fix-windows-include.patch
)

file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}")

vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
OPTIONS_DEBUG
-DBZIP2_SKIP_HEADERS=ON
-DBZIP2_SKIP_TOOLS=ON
)

vcpkg_install_cmake()
vcpkg_copy_pdbs()

file(READ "${CURRENT_PACKAGES_DIR}/include/bzlib.h" BZLIB_H)
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
string(REPLACE "defined(BZ_IMPORT)" "0" BZLIB_H "${BZLIB_H}")
else()
string(REPLACE "defined(BZ_IMPORT)" "1" BZLIB_H "${BZLIB_H}")
endif()
file(WRITE "${CURRENT_PACKAGES_DIR}/include/bzlib.h" "${BZLIB_H}")

file(COPY "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/bzip2")
file(RENAME "${CURRENT_PACKAGES_DIR}/share/bzip2/LICENSE" "${CURRENT_PACKAGES_DIR}/share/bzip2/copyright")

file(COPY "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")

vcpkg_test_cmake(PACKAGE_NAME BZip2 MODULE)

set(BZIP2_PREFIX "${CURRENT_INSTALLED_DIR}")
set(bzname bz2)
configure_file("${CMAKE_CURRENT_LIST_DIR}/bzip2.pc.in" "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/bzip2.pc" @ONLY)
set(BZIP2_PREFIX "${CURRENT_INSTALLED_DIR}/debug")
set(bzname bz2d)
configure_file("${CMAKE_CURRENT_LIST_DIR}/bzip2.pc.in" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/bzip2.pc" @ONLY)
vcpkg_fixup_pkgconfig()
set(BZIP2_VERSION 1.0.6) # TODO: Update to 1.0.8
vcpkg_download_distfile(ARCHIVE # TODO: switch to vcpkg_from_git with https://sourceware.org/git/?p=bzip2.git;a=summary
URLS "https://github.com/past-due/bzip2-mirror/releases/download/v${BZIP2_VERSION}/bzip2-${BZIP2_VERSION}.tar.gz"
FILENAME "bzip2-${BZIP2_VERSION}.tar.gz"
SHA512 00ace5438cfa0c577e5f578d8a808613187eff5217c35164ffe044fbafdfec9e98f4192c02a7d67e01e5a5ccced630583ad1003c37697219b0f147343a3fdd12)

vcpkg_extract_source_archive_ex(
OUT_SOURCE_PATH SOURCE_PATH
ARCHIVE ${ARCHIVE}
REF ${BZIP2_VERSION}
PATCHES
fix-import-export-macros.patch
fix-windows-include.patch
)

file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}")

vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
OPTIONS_DEBUG
-DBZIP2_SKIP_HEADERS=ON
-DBZIP2_SKIP_TOOLS=ON
)

vcpkg_install_cmake()
vcpkg_copy_pdbs()

file(READ "${CURRENT_PACKAGES_DIR}/include/bzlib.h" BZLIB_H)
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
string(REPLACE "defined(BZ_IMPORT)" "0" BZLIB_H "${BZLIB_H}")
else()
string(REPLACE "defined(BZ_IMPORT)" "1" BZLIB_H "${BZLIB_H}")
endif()
file(WRITE "${CURRENT_PACKAGES_DIR}/include/bzlib.h" "${BZLIB_H}")

if (NOT VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
set(BZIP2_PREFIX "${CURRENT_INSTALLED_DIR}")
set(bzname bz2)
configure_file("${CMAKE_CURRENT_LIST_DIR}/bzip2.pc.in" "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/bzip2.pc" @ONLY)
endif()

if (NOT VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
set(BZIP2_PREFIX "${CURRENT_INSTALLED_DIR}/debug")
set(bzname bz2d)
configure_file("${CMAKE_CURRENT_LIST_DIR}/bzip2.pc.in" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/bzip2.pc" @ONLY)
endif()

vcpkg_fixup_pkgconfig()

file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
file(COPY "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
74 changes: 34 additions & 40 deletions scripts/cmake/vcpkg_fixup_pkgconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
## If the *.pc file contains flags in the lib field which are not libraries. These can be listed here
##
## ### SKIP_CHECK
## Skips the library checks in vcpkg_fixup_pkgconfig. Only use if the script itself has unhandled cases.
## Skips the library checks in vcpkg_fixup_pkgconfig. Only use if the script itself has unhandled cases.
##
## ## Notes
## Still work in progress. If there are more cases which can be handled here feel free to add them
Expand All @@ -51,7 +51,7 @@ function(vcpkg_fixup_pkgconfig_check_files pkg_cfg_cmd _file _config _system_lib
set(_VCPKG_INSTALLED_PKGCONF "${CURRENT_INSTALLED_DIR}")
set(_VCPKG_PACKAGES_PKGCONF "${CURRENT_PACKAGES_DIR}")
endif()

set(PATH_SUFFIX_DEBUG /debug)
set(PKGCONFIG_INSTALLED_DIR "${_VCPKG_INSTALLED_PKGCONF}${PATH_SUFFIX_${_config}}/lib/pkgconfig")
set(PKGCONFIG_INSTALLED_SHARE_DIR "${_VCPKG_INSTALLED_PKGCONF}/share/pkgconfig")
Expand All @@ -77,18 +77,18 @@ function(vcpkg_fixup_pkgconfig_check_files pkg_cfg_cmd _file _config _system_lib
ERROR_STRIP_TRAILING_WHITESPACE
)
if(NOT _pkg_error_var EQUAL 0)
message(STATUS "pkg_cfg_cmd call with:${pkg_cfg_cmd} --exists ${_package_name} failed")
message(STATUS "ENV{PKG_CONFIG_PATH}:$ENV{PKG_CONFIG_PATH}")
message(STATUS "pkg-config call failed with error code:${_pkg_error_var}")
message(STATUS "pkg-config output:${_pkg_output}")
message(FATAL_ERROR "pkg-config error output:${_pkg_error_out}")
message(STATUS "pkg_cfg_cmd call with: ${pkg_cfg_cmd} --exists ${_package_name} failed")
message(STATUS "ENV{PKG_CONFIG_PATH}: $ENV{PKG_CONFIG_PATH}")
message(STATUS "pkg-config call failed with error code: ${_pkg_error_var}")
message(STATUS "pkg-config output: ${_pkg_output}")
message(FATAL_ERROR "pkg-config error output: ${_pkg_error_out}")
else()
debug_message("pkg-config returned:${_pkg_error_var}")
debug_message("pkg-config output:${_pkg_output}")
debug_message("pkg-config error output:${_pkg_error_out}")
debug_message("pkg-config returned: ${_pkg_error_var}")
debug_message("pkg-config output: ${_pkg_output}")
debug_message("pkg-config error output: ${_pkg_error_out}")
endif()

# Get all required libs. --static means we get all libraries required for static linkage
# Get all required libs. --static means we get all libraries required for static linkage
# which is the worst case and includes the case without --static
# This retests already tested *.pc files since pkg-config will recursivly search for
# required packages and add there link flags to the one being tested
Expand All @@ -103,14 +103,14 @@ function(vcpkg_fixup_pkgconfig_check_files pkg_cfg_cmd _file _config _system_lib
ERROR_STRIP_TRAILING_WHITESPACE
)
if(NOT _pkg_error_var EQUAL 0)
message(STATUS "pkg_cfg_cmd call with:${pkg_cfg_cmd} --libs ${_package_name} failed")
message(STATUS "pkg-config call failed with error code:${_pkg_error_var}")
message(STATUS "pkg-config output:${_pkg_libs_output}")
message(FATAL_ERROR "pkg-config error output:${_pkg_error_out}")
message(STATUS "pkg_cfg_cmd call with: ${pkg_cfg_cmd} --libs ${_package_name} failed")
message(STATUS "pkg-config call failed with error code: ${_pkg_error_var}")
message(STATUS "pkg-config output: ${_pkg_libs_output}")
message(FATAL_ERROR "pkg-config error output: ${_pkg_error_out}")
else()
debug_message("pkg-config returned:${_pkg_error_var}")
debug_message("pkg-config output:${_pkg_libs_output}")
debug_message("pkg-config error output:${_pkg_error_out}")
debug_message("pkg-config returned: ${_pkg_error_var}")
debug_message("pkg-config output: ${_pkg_libs_output}")
debug_message("pkg-config error output: ${_pkg_error_out}")
endif()

execute_process(COMMAND "${pkg_cfg_cmd}" --print-errors --static --libs-only-L ${_package_name}
Expand All @@ -123,14 +123,14 @@ function(vcpkg_fixup_pkgconfig_check_files pkg_cfg_cmd _file _config _system_lib
)

if(NOT _pkg_error_var EQUAL 0)
message(STATUS "pkg_cfg_cmd call with:${pkg_cfg_cmd} --libs-only-L ${_package_name} failed")
message(STATUS "pkg-config call failed with error code:${_pkg_error_var}")
message(STATUS "pkg-config output:${_pkg_lib_paths_output}")
message(FATAL_ERROR "pkg-config error output:${_pkg_error_out}")
message(STATUS "pkg_cfg_cmd call with: ${pkg_cfg_cmd} --libs-only-L ${_package_name} failed")
message(STATUS "pkg-config call failed with error code: ${_pkg_error_var}")
message(STATUS "pkg-config output: ${_pkg_lib_paths_output}")
message(FATAL_ERROR "pkg-config error output: ${_pkg_error_out}")
else()
debug_message("pkg-config returned:${_pkg_error_var}")
debug_message("pkg-config output:${_pkg_lib_paths_output}")
debug_message("pkg-config error output:${_pkg_error_out}")
debug_message("pkg-config returned: ${_pkg_error_var}")
debug_message("pkg-config output: ${_pkg_lib_paths_output}")
debug_message("pkg-config error output: ${_pkg_error_out}")
endif()

string(REPLACE "\\ " "##" _pkg_lib_paths_output "${_pkg_lib_paths_output}") # Whitespace path protection
Expand Down Expand Up @@ -160,8 +160,8 @@ function(vcpkg_fixup_pkgconfig_check_files pkg_cfg_cmd _file _config _system_lib
string(REGEX REPLACE "(^|;)/([a-zA-Z])/" "\\1\\2:/" _pkg_lib_paths_output "${_pkg_lib_paths_output}")
string(REGEX REPLACE " /([a-zA-Z])/" ";\\1:/" _pkg_libs_output "${_pkg_libs_output}")
string(REGEX REPLACE "-l/([a-zA-Z])/" "-l\\1:/" _pkg_libs_output "${_pkg_libs_output}")
debug_message("pkg-config output lib paths after replacement (cmake style):${_pkg_lib_paths_output}")
debug_message("pkg-config output lib after replacement (cmake style):${_pkg_libs_output}")
debug_message("pkg-config output lib paths after replacement (cmake style): ${_pkg_lib_paths_output}")
debug_message("pkg-config output lib after replacement (cmake style): ${_pkg_libs_output}")
endif()

if("${_config}" STREQUAL "DEBUG")
Expand Down Expand Up @@ -198,15 +198,15 @@ function(vcpkg_fixup_pkgconfig_check_files pkg_cfg_cmd _file _config _system_lib

string(REGEX REPLACE ";?[\t ]*;[\t ]*" ";" _pkg_libs_output "${_pkg_libs_output}") # Double ;; and Whitespace before/after ; removal

debug_message("Library search paths:${_pkg_lib_paths_output}")
debug_message("Libraries to search:${_pkg_libs_output}")
debug_message("Library search paths: ${_pkg_lib_paths_output}")
debug_message("Libraries to search: ${_pkg_libs_output}")
set(CMAKE_FIND_LIBRARY_SUFFIXES_BACKUP ${CMAKE_FIND_LIBRARY_SUFFIXES})
list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES .lib .dll.a .a)
foreach(_lib IN LISTS _pkg_libs_output)
if(EXISTS "${_lib}" OR "x${_lib}x" STREQUAL "xx" ) # eat; all ok _lib is a fullpath to a library or empty
continue()
elseif (_lib MATCHES "^-l(.+)$")
debug_message("Library match: CMAKE_MATCH_1:${CMAKE_MATCH_1}")
debug_message("Library match: CMAKE_MATCH_1: ${CMAKE_MATCH_1}")
set(_libname "${CMAKE_MATCH_1}")
if(EXISTS "${_libname}")
debug_message("${_libname} detected as an existing full path!")
Expand Down Expand Up @@ -235,7 +235,7 @@ function(vcpkg_fixup_pkgconfig_check_files pkg_cfg_cmd _file _config _system_lib
endif()
endforeach()
# Reaching here means error!
message(STATUS "CHECK_LIB_${_libname}_${_config}:${CHECK_LIB_${_libname}_${_config}}")
message(STATUS "CHECK_LIB_${_libname}_${_config}: ${CHECK_LIB_${_libname}_${_config}}")
message(FATAL_ERROR "Library \"${_libname}\" was not found! If it is a system library use the SYSTEM_LIBRARIES parameter for the vcpkg_fixup_pkgconfig call! Otherwise, correct the *.pc file")
else ()
message(FATAL_ERROR "Unhandled string \"${_lib}\" was found! If it is a system library use the SYSTEM_LIBRARIES parameter for the vcpkg_fixup_pkgconfig call! Otherwise, correct the *.pc file or add the case to vcpkg_fixup_pkgconfig")
Expand All @@ -259,8 +259,7 @@ function(vcpkg_fixup_pkgconfig)
else()
set(PKGCONFIG_STATIC --static)
endif()

message(STATUS "Fixing pkgconfig")

if(_vfpkg_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "vcpkg_fixup_pkgconfig was passed extra arguments: ${_vfct_UNPARSED_ARGUMENTS}")
endif()
Expand Down Expand Up @@ -288,14 +287,12 @@ function(vcpkg_fixup_pkgconfig)
endif()
endif()

#Absolute Unix like paths
#Absolute Unix like paths
string(REGEX REPLACE "([a-zA-Z]):/" "/\\1/" _VCPKG_PACKAGES_DIR "${CURRENT_PACKAGES_DIR}")
string(REGEX REPLACE "([a-zA-Z]):/" "/\\1/" _VCPKG_INSTALLED_DIR "${CURRENT_INSTALLED_DIR}")

message(STATUS "Fixing pkgconfig - release")
debug_message("Files: ${_vfpkg_RELEASE_FILES}")
foreach(_file ${_vfpkg_RELEASE_FILES})
message(STATUS "Checking file: ${_file}")
get_filename_component(PKG_LIB_SEARCH_PATH "${_file}" DIRECTORY)
file(RELATIVE_PATH RELATIVE_PC_PATH "${PKG_LIB_SEARCH_PATH}" "${CURRENT_PACKAGES_DIR}")
string(REGEX REPLACE "/$" "" RELATIVE_PC_PATH "${RELATIVE_PC_PATH}")
Expand All @@ -317,10 +314,8 @@ function(vcpkg_fixup_pkgconfig)
endforeach()
endif()

message(STATUS "Fixing pkgconfig - debug")
debug_message("Files: ${_vfpkg_DEBUG_FILES}")
foreach(_file ${_vfpkg_DEBUG_FILES})
message(STATUS "Checking file: ${_file}")
get_filename_component(PKG_LIB_SEARCH_PATH "${_file}" DIRECTORY)
file(RELATIVE_PATH RELATIVE_PC_PATH "${PKG_LIB_SEARCH_PATH}" "${CURRENT_PACKAGES_DIR}/debug/")
string(REGEX REPLACE "/$" "" RELATIVE_PC_PATH "${RELATIVE_PC_PATH}")
Expand All @@ -338,7 +333,7 @@ function(vcpkg_fixup_pkgconfig)
string(REPLACE "debug/lib" "lib" _contents "${_contents}") # the prefix will contain the debug keyword
string(REGEX REPLACE "^prefix=(\")?(\\\\)?\\\${prefix}(/debug)?(\")?" "prefix=\${pcfiledir}/${RELATIVE_PC_PATH}" _contents "${_contents}") # make pc file relocatable
string(REGEX REPLACE "[\n]prefix=(\")?(\\\\)?\\\${prefix}(/debug)?(\")?" "\nprefix=\${pcfiledir}/${RELATIVE_PC_PATH}" _contents "${_contents}") # make pc file relocatable
string(REPLACE "\${prefix}/debug" "\${prefix}" _contents "${_contents}") # replace remaining debug paths if they exist.
string(REPLACE "\${prefix}/debug" "\${prefix}" _contents "${_contents}") # replace remaining debug paths if they exist.
file(WRITE "${_file}" "${_contents}")
unset(PKG_LIB_SEARCH_PATH)
endforeach()
Expand All @@ -348,7 +343,6 @@ function(vcpkg_fixup_pkgconfig)
vcpkg_fixup_pkgconfig_check_files("${PKGCONFIG}" "${_file}" "DEBUG" "${_vfpkg_SYSTEM_LIBRARIES}" "${_vfpkg_IGNORE_FLAGS}")
endforeach()
endif()
message(STATUS "Fixing pkgconfig --- finished")

set(VCPKG_FIXUP_PKGCONFIG_CALLED TRUE CACHE INTERNAL "See below" FORCE)
# Variable to check if this function has been called!
Expand Down