mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
cmake: Fix the build on Unix with source files checked out on Windows
The issue is that, by default, Git for Windows checks out text files with CRLF line endings. This is a problem for awk, which is expecting Unix-style LF line endings. When cloning on Windows and attempting to compile on WSL, Mingw or Cygwin, there may be an error from awk. The fix is to leverage CMake's ability to configure a file and perform EOL conversions. We copy the awk scripts from the source directory to the build directory. This portable method ensures they have LF endings, and the build logic is updated to use the build directory version. Intentionally avoiding .gitattributes to avoid setting precedent. Co-authored-by: Christopher Sean Morrison <brlcad@gmail.com> Co-authored-by: Cosmin Truta <ctruta@gmail.com> Signed-off-by: Cosmin Truta <ctruta@gmail.com>
This commit is contained in:
parent
8a354b41e9
commit
840af2eda6
@ -18,6 +18,7 @@
|
||||
# Revised by Alex Gaynor, 2020
|
||||
# Revised by Owen Rudge, 2020
|
||||
# Revised by Gleb Mazovetskiy, 2021
|
||||
# Revised by Christopher Sean Morrison, 2022
|
||||
|
||||
# This code is released under the libpng license.
|
||||
# For conditions of distribution and use, see the disclaimer
|
||||
@ -293,6 +294,20 @@ if(NOT AWK OR ANDROID OR IOS)
|
||||
${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h)
|
||||
add_custom_target(genfiles) # Dummy
|
||||
else()
|
||||
# Copy the awk scripts, converting their line endings to Unix (LF)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/checksym.awk
|
||||
${CMAKE_CURRENT_BINARY_DIR}/scripts/checksym.awk
|
||||
@ONLY
|
||||
NEWLINE_STYLE LF)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/options.awk
|
||||
${CMAKE_CURRENT_BINARY_DIR}/scripts/options.awk
|
||||
@ONLY
|
||||
NEWLINE_STYLE LF)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/dfn.awk
|
||||
${CMAKE_CURRENT_BINARY_DIR}/scripts/dfn.awk
|
||||
@ONLY
|
||||
NEWLINE_STYLE LF)
|
||||
|
||||
# Generate .chk from .out with awk:
|
||||
# generate_chk(INPUT inputfile OUTPUT outputfile [DEPENDS dep1 [dep2...]])
|
||||
include(CMakeParseArguments)
|
||||
@ -377,14 +392,14 @@ else()
|
||||
# Generate scripts/pnglibconf.h
|
||||
generate_source(OUTPUT "scripts/pnglibconf.c"
|
||||
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.dfa"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/options.awk"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/scripts/options.awk"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h")
|
||||
add_custom_target(scripts_pnglibconf_c DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/scripts/pnglibconf.c")
|
||||
|
||||
# Generate pnglibconf.c
|
||||
generate_source(OUTPUT "pnglibconf.c"
|
||||
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.dfa"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/options.awk"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/scripts/options.awk"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h")
|
||||
add_custom_target(pnglibconf_c DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.c")
|
||||
|
||||
@ -446,7 +461,7 @@ else()
|
||||
generate_chk(INPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out"
|
||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk"
|
||||
DEPENDS scripts_symbols_out
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/checksym.awk"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/scripts/checksym.awk"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/symbols.def")
|
||||
|
||||
add_custom_target(scripts_symbols_chk
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
|
||||
# Variables substituted from CMakeLists.txt
|
||||
set(SRCDIR "@CMAKE_CURRENT_SOURCE_DIR@")
|
||||
set(BINDIR "@CMAKE_CURRENT_BINARY_DIR@")
|
||||
|
||||
set(AWK "@AWK@")
|
||||
|
||||
@ -23,7 +24,7 @@ get_filename_component(OUTPUTDIR "${OUTPUT}" PATH)
|
||||
if("${INPUTEXT}" STREQUAL ".out" AND "${OUTPUTEXT}" STREQUAL ".chk")
|
||||
# Generate .chk from .out with awk (generic)
|
||||
file(REMOVE "${OUTPUT}" "${OUTPUTDIR}/${OUTPUTBASE}.new")
|
||||
execute_process(COMMAND "${AWK}" -f "${SRCDIR}/scripts/checksym.awk"
|
||||
execute_process(COMMAND "${AWK}" -f "${BINDIR}/scripts/checksym.awk"
|
||||
"${SRCDIR}/scripts/${INPUTBASE}.def"
|
||||
"of=${OUTPUTDIR}/${OUTPUTBASE}.new"
|
||||
"${INPUT}"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user