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

Adjust cmake to install same .h and .pc files as configure #642

Merged
merged 4 commits into from Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/pkgcheck.yml
@@ -0,0 +1,35 @@
name: CI Pkgcheck
on: [push, pull_request]
jobs:
ci-pkgcheck:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
name: [
Ubuntu GCC
]
include:
- name: Ubuntu GCC
os: ubuntu-latest
compiler: gcc
packages: ninja-build

steps:
- name: Checkout repository
uses: actions/checkout@v1

- name: Install packages (Ubuntu)
if: runner.os == 'Linux' && matrix.packages
run: |
sudo apt-get update
sudo apt-get install -y ${{ matrix.packages }}

- name: Compare output of configure and cmake
run: |
mkdir ${{ matrix.build-dir || '.not-used' }}
cd ${{ matrix.build-dir || '.' }}
sh ${{ matrix.build-src-dir || '.' }}/test/pkgcheck.sh
env:
CC: ${{ matrix.compiler }}
58 changes: 43 additions & 15 deletions CMakeLists.txt
Expand Up @@ -40,7 +40,7 @@ set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation direc
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
set(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages")
set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files")
set(INSTALL_PKGCONFIG_DIR "${INSTALL_LIB_DIR}/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files")
dankegel marked this conversation as resolved.
Show resolved Hide resolved

include(CheckTypeSize)
include(CheckSymbolExists)
Expand Down Expand Up @@ -311,10 +311,11 @@ endif()
# Check for stndard/system includes
#
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
check_include_file(stdarg.h HAVE_STDARG_H)
check_include_file(stdint.h HAVE_STDINT_H)
check_include_file(stddef.h HAVE_STDDEF_H)
check_include_file(sys/sdt.h HAVE_SYS_SDT_H)
check_include_file(unistd.h Z_HAVE_UNISTD_H)
check_include_file(unistd.h HAVE_UNISTD_H)

#
# Check to see if we have large file support
Expand Down Expand Up @@ -781,15 +782,13 @@ macro(generate_cmakein input output)
file(REMOVE ${output})
file(STRINGS ${input} _lines)
foreach(_line IN LISTS _lines)
file(APPEND ${output} "${_line}\n")

if(_line STREQUAL "#define ZCONF_H" OR _line STREQUAL "#define ZCONFNG_H")
file(APPEND ${output} "#cmakedefine Z_HAVE_UNISTD_H\n")
if(NOT HAVE_PTRDIFF_T)
file(APPEND ${output} "#cmakedefine NEED_PTRDIFF_T\n")
file(APPEND ${output} "#cmakedefine PTRDIFF_TYPE ${PTRDIFF_TYPE}\n")
endif()
string(REGEX REPLACE "#ifdef HAVE_UNISTD_H.*" "@ZCONF_UNISTD_LINE@" _line "${_line}")
string(REGEX REPLACE "#ifdef HAVE_STDARG_H.*" "@ZCONF_STDARG_LINE@" _line "${_line}")
string(REGEX REPLACE "#ifdef NEED_PTRDIFF_T.*" "@ZCONF_PTRDIFF_LINE@" _line "${_line}")
if(NEED_PTRDIFF_T)
string(REGEX REPLACE "typedef PTRDIFF_TYPE" "typedef @PTRDIFF_TYPE@" _line "${_line}")
endif()
file(APPEND ${output} "${_line}\n")
endforeach()
endmacro(generate_cmakein)

Expand Down Expand Up @@ -817,11 +816,18 @@ if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
endif()
endif()

set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib${SUFFIX}.pc)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein
${ZLIB_PC} @ONLY)
configure_file(${CMAKE_CURRENT_BINARY_DIR}/zconf${SUFFIX}.h.cmakein
${CMAKE_CURRENT_BINARY_DIR}/zconf${SUFFIX}.h @ONLY)
# Refer to prefix symbolically to ease relocation by end user,
# as Makefile-generated .pc file does.
if(INSTALL_INC_DIR STREQUAL "${CMAKE_INSTALL_PREFIX}/include")
set(PC_INSTALL_INC_DIR "\${prefix}/include")
else()
set(PC_INSTALL_INC_DIR "${INSTALL_INC_DIR}")
endif()
if(INSTALL_LIB_DIR STREQUAL "${CMAKE_INSTALL_PREFIX}/lib")
set(PC_INSTALL_LIB_DIR "\${exec_prefix}/lib")
else()
set(PC_INSTALL_LIB_DIR "${INSTALL_LIB_DIR}")
endif()

#============================================================================
# zlib
Expand Down Expand Up @@ -968,6 +974,28 @@ if(NOT DEFINED BUILD_SHARED_LIBS OR BUILD_SHARED_LIBS)
endif()
endif()

if(HAVE_STDARG_H)
SET(ZCONF_STDARG_LINE "#if 1 /* was set to #if 1 by configure/cmake/etc */")
else()
SET(ZCONF_STDARG_LINE "#ifdef HAVE_STDARG_H /* may be set to #if 1 by configure/cmake/etc */")
endif()
if(HAVE_UNISTD_H)
SET(ZCONF_UNISTD_LINE "#if 1 /* was set to #if 1 by configure/cmake/etc */")
else()
SET(ZCONF_UNISTD_LINE "#ifdef HAVE_UNISTD_H /* may be set to #if 1 by configure/cmake/etc */")
endif()
if(NEED_PTRDIFF_T)
SET(ZCONF_PTRDIFF_LINE "#if 1 /* was set to #if 1 by configure/cmake/etc */")
else()
SET(ZCONF_PTRDIFF_LINE "#ifdef NEED_PTRDIFF_T /* may be set to #if 1 by configure/cmake/etc */")
endif()

set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib${SUFFIX}.pc)
dankegel marked this conversation as resolved.
Show resolved Hide resolved
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein
${ZLIB_PC} @ONLY)
configure_file(${CMAKE_CURRENT_BINARY_DIR}/zconf${SUFFIX}.h.cmakein
${CMAKE_CURRENT_BINARY_DIR}/zconf${SUFFIX}.h @ONLY)

if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL)
install(TARGETS ${ZLIB_INSTALL_LIBRARIES}
RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
Expand Down
63 changes: 63 additions & 0 deletions test/pkgcheck.sh
@@ -0,0 +1,63 @@
#!/bin/sh
# Verify that the various build systems produce identical results on a Unixlike system
set -ex

# If suffix not set to "", default to -ng
suffix=${suffix--ng}

# Use same compiler for make and cmake builds
if test "$CC"x = ""x
then
if clang --version
then
export CC=clang
elif gcc --version
then
export CC=gcc
fi
fi

# New build system
# Happens to delete top-level zconf.h
# (which itself is a bug, https://github.com/madler/zlib/issues/162 )
# which triggers another bug later in configure,
# https://github.com/madler/zlib/issues/499
rm -rf btmp2 pkgtmp2
mkdir btmp2 pkgtmp2
export DESTDIR=$(pwd)/pkgtmp2
cd btmp2
cmake -G Ninja ..
ninja -v
ninja install
cd ..

# Original build system
rm -rf btmp1 pkgtmp1
mkdir btmp1 pkgtmp1
export DESTDIR=$(pwd)/pkgtmp1
cd btmp1
case $(uname) in
Darwin)
export LDFLAGS="-Wl,-headerpad_max_install_names"
;;
Linux)
if grep -i fedora /etc/os-release > /dev/null
then
# Note: Fedora patches cmake to use -O2 in release, which
# does not match the -O3 configure sets :-(
export CFLAGS="-O2 -DNDEBUG"
fi
;;
esac
../configure
make
make install
cd ..

if diff --exclude '*.so*' --exclude '*.a' -Nur pkgtmp1 pkgtmp2
then
echo pkgcheck-cmake-bits-identical PASS
else
echo pkgcheck-cmake-bits-identical FAIL
exit 1
fi
4 changes: 2 additions & 2 deletions zconf-ng.h.in
Expand Up @@ -98,11 +98,11 @@ typedef void const *voidpc;
typedef void *voidpf;
typedef void *voidp;

#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */
#ifdef HAVE_UNISTD_H /* may be set to #if 1 by configure/cmake/etc */
# define Z_HAVE_UNISTD_H
#endif

#ifdef NEED_PTRDIFF_T /* may be set to #if 1 by ./configure */
#ifdef NEED_PTRDIFF_T /* may be set to #if 1 by configure/cmake/etc */
typedef PTRDIFF_TYPE ptrdiff_t;
#endif

Expand Down
4 changes: 2 additions & 2 deletions zconf.h.in
Expand Up @@ -102,11 +102,11 @@ typedef void const *voidpc;
typedef void *voidpf;
typedef void *voidp;

#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */
#ifdef HAVE_UNISTD_H /* may be set to #if 1 by configure/cmake/etc */
# define Z_HAVE_UNISTD_H
#endif

#ifdef NEED_PTRDIFF_T /* may be set to #if 1 by ./configure */
#ifdef NEED_PTRDIFF_T /* may be set to #if 1 by configure/cmake/etc */
typedef PTRDIFF_TYPE ptrdiff_t;
#endif

Expand Down
10 changes: 5 additions & 5 deletions zlib.pc.cmakein
@@ -1,12 +1,12 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=@CMAKE_INSTALL_PREFIX@
libdir=@INSTALL_LIB_DIR@
sharedlibdir=@INSTALL_LIB_DIR@
includedir=@INSTALL_INC_DIR@
exec_prefix=${prefix}
libdir=@PC_INSTALL_LIB_DIR@
sharedlibdir=${libdir}
includedir=@PC_INSTALL_INC_DIR@

Name: zlib@SUFFIX@
Description: zlib-ng compression library
Version: @zlib_VERSION@
Version: @ZLIB_FULL_VERSION@

Requires:
Libs: -L${libdir} -L${sharedlibdir} -lz@SUFFIX@
Expand Down