summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Sean Morrison <brlcad@gmail.com>2022-03-10 01:08:09 -0500
committerCosmin Truta <ctruta@gmail.com>2022-09-10 22:02:00 +0300
commit840af2eda6359e42be7867dfb53e2b2a011c1226 (patch)
treecf521062f7e60e817cdcc1a1ae3b42dca56531ed
parent8a354b41e9c4f79b42c156d94188bd6adc808590 (diff)
downloadlibpng-840af2eda6359e42be7867dfb53e2b2a011c1226.tar.gz
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>
-rw-r--r--CMakeLists.txt21
-rw-r--r--scripts/genchk.cmake.in3
2 files changed, 20 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3b7db9e73..941cacb49 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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
diff --git a/scripts/genchk.cmake.in b/scripts/genchk.cmake.in
index ab3b9d746..1b6aa84ae 100644
--- a/scripts/genchk.cmake.in
+++ b/scripts/genchk.cmake.in
@@ -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}"