Skip to content

Commit

Permalink
cmake: generate same zconf.h as configure
Browse files Browse the repository at this point in the history
Also make comment in zconf.h less configure-specific
  • Loading branch information
dankegel authored and Dead2 committed Jun 19, 2020
1 parent 6aacfb6 commit 280f379
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
33 changes: 24 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
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 @@ -975,6 +974,22 @@ 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)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein
${ZLIB_PC} @ONLY)
Expand Down
4 changes: 2 additions & 2 deletions zconf-ng.h.in
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 280f379

Please sign in to comment.