Skip to content

Commit

Permalink
Don't recreate unzip.h every time configure is run
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc-Aldorasi-Imprivata committed Apr 16, 2020
1 parent f1f6d5c commit 0d25a1d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
31 changes: 11 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -262,26 +262,13 @@ if(MZ_COMPAT)
list(APPEND MINIZIP_SRC "mz_compat.c")
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_compat.h")

set(COMPAT_HEADER "\
/* file.h -- Compatibility layer shim\n\
part of the MiniZip project\n\n\
This program is distributed under the terms of the same license as zlib.\n\
See the accompanying LICENSE file for the full text of the license.\n\
*/\n\n\
#ifndef MZ_COMPAT_FILE\n\
#define MZ_COMPAT_FILE\n\n\
#include \"mz_compat.h\"\n\n\
#endif\n")

string(REPLACE "file.h" "zip.h" ZIP_COMPAT_HEADER ${COMPAT_HEADER})
string(REPLACE "MZ_COMPAT_FILE" "MZ_COMPAT_ZIP" ZIP_COMPAT_HEADER ${ZIP_COMPAT_HEADER})
file(WRITE "zip.h" ${ZIP_COMPAT_HEADER})
list(APPEND MINIZIP_PUBLIC_HEADERS "zip.h")

string(REPLACE "file.h" "unzip.h" UNZIP_COMPAT_HEADER ${COMPAT_HEADER})
string(REPLACE "MZ_COMPAT_FILE" "MZ_COMPAT_UNZIP" UNZIP_COMPAT_HEADER ${UNZIP_COMPAT_HEADER})
file(WRITE "unzip.h" ${UNZIP_COMPAT_HEADER})
list(APPEND MINIZIP_PUBLIC_HEADERS "unzip.h")
function(make_compat_header filename header_guard)
configure_file(compat_header.h.in generated_headers/minizip/${filename} @ONLY)
list(APPEND MINIZIP_PUBLIC_HEADERS "${CMAKE_CURRENT_BINARY_DIR}/generated_headers/minizip/${filename}")
endfunction()

make_compat_header("zip.h" "MZ_COMPAT_ZIP")
make_compat_header("unzip.h" "MZ_COMPAT_UNZIP")

if(MZ_COMPAT_VERSION)
add_definitions(-DMZ_COMPAT_VERSION=${MZ_COMPAT_VERSION})
Expand Down Expand Up @@ -541,6 +528,10 @@ set_target_properties(${PROJECT_NAME} PROPERTIES

target_link_libraries(${PROJECT_NAME} PRIVATE ${version_rc})

if(MZ_COMPAT)
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/generated_headers")
endif()

if(MZ_LZMA)
set_target_properties(${PROJECT_NAME} PROPERTIES C_STANDARD 99)
endif()
Expand Down
15 changes: 15 additions & 0 deletions compat_header.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* @filename@ -- Compatibility layer shim
part of the MiniZip project

This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/

#ifndef @header_guard@
#define @header_guard@

#include "mz_compat.h"

#endif


0 comments on commit 0d25a1d

Please sign in to comment.