From 5961d6dc3724e2cf882ab07afbb9bbbfaeb4fd31 Mon Sep 17 00:00:00 2001 From: Ward Fisher Date: Tue, 26 May 2020 14:46:23 -0600 Subject: [PATCH 1/2] Added a check for m4 and throw an error if m4 isn't on the path and the generated file isn't present (as it would be in a point release). In support of https://github.com/Unidata/netcdf-c/issues/1739 --- CMakeLists.txt | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cb06a077f..2e9b7cc09 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1492,20 +1492,27 @@ ENDIF() MACRO(GEN_m4 filename) + # If m4 isn't present, and the generated file doesn't exist, + # it cannot be generated and an error should be thrown. + IF(NOT HAVE_M4) + IF(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${filename.c}) + MESSAGE(FATAL_ERROR "m4 is required to generate ${filename}.c. Please install m4 so that it is on the PATH and try again.") + ENDIF() + ENDIF(NOT HAVE_M4) + IF(HAVE_M4) + # If m4 is available, remove generated file if it exists. + IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${filename}.c) + FILE(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/${filename}.c) + ENDIF() - # If m4 is available, remove generated file if it exists. - IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${filename}.c) - FILE(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/${filename}.c) - ENDIF() - - ADD_CUSTOM_COMMAND( - OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${filename}.c - COMMAND ${NC_M4} - ARGS ${M4FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/${filename}.m4 > ${CMAKE_CURRENT_SOURCE_DIR}/${filename}.c - VERBATIM - ) -ENDIF(HAVE_M4) + ADD_CUSTOM_COMMAND( + OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${filename}.c + COMMAND ${NC_M4} + ARGS ${M4FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/${filename}.m4 > ${CMAKE_CURRENT_SOURCE_DIR}/${filename}.c + VERBATIM + ) + ENDIF(HAVE_M4) ENDMACRO(GEN_m4) # Binary tests, but ones which depend on value of 'TEMP_LARGE' being defined. From 31712192b215eaaeda049eda843c1c8fc4b3176c Mon Sep 17 00:00:00 2001 From: Ward Fisher Date: Tue, 26 May 2020 16:09:10 -0600 Subject: [PATCH 2/2] More m4 fenceposting. --- CMakeLists.txt | 1 + libsrc/CMakeLists.txt | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e9b7cc09..713fd6c44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1488,6 +1488,7 @@ IF(NC_M4) SET(HAVE_M4 TRUE) ELSE() MESSAGE(STATUS "m4 not found.") + SET(HAVE_M4 FALSE) ENDIF() MACRO(GEN_m4 filename) diff --git a/libsrc/CMakeLists.txt b/libsrc/CMakeLists.txt index 65a3f8745..e3e28793e 100644 --- a/libsrc/CMakeLists.txt +++ b/libsrc/CMakeLists.txt @@ -4,9 +4,10 @@ # Process these files with m4. SET(m4_SOURCES attr ncx putget t_ncxx) foreach (f ${m4_SOURCES}) - IF(HAVE_M4) GEN_m4(${f}) - ENDIF() + IF(NOT EXISTS ${f}.c) + MESSAGE(FATAL_ERROR "m4 is required to generate ${f}.c. Please install m4 on the PATH and try again.") + ENDIF() endforeach(f) SET(libsrc_SOURCES v1hpg.c putget.c attr.c nc3dispatch.c