From aa394b5ebc893ef23d35c1ad3a36b48573141064 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Tue, 19 Jul 2022 15:26:04 +0200 Subject: [PATCH] Prevent cmake writing to source dir --- CMakeLists.txt | 20 ++++++++------------ nczarr_test/CMakeLists.txt | 18 ++++++++---------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e52f56a0..2153f22d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1983,22 +1983,18 @@ ENDIF() MACRO(GEN_m4 filename) -set(dest "${CMAKE_CURRENT_SOURCE_DIR}/${filename}.c") + set(fallbackdest "${CMAKE_CURRENT_SOURCE_DIR}/${filename}.c") + set(dest "${CMAKE_CURRENT_BINARY_DIR}/${filename}.c") # 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 ${dest}) - MESSAGE(FATAL_ERROR "m4 is required to generate ${dest}. Please install m4 so that it is on the PATH and try again.") + IF(NOT EXISTS ${fallbackdest}) + MESSAGE(FATAL_ERROR "m4 is required to generate ${filename}.c. Please install m4 so that it is on the PATH and try again.") + ELSE() + SET(${dest} ${fallbackdest}) 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() - + ELSE() ADD_CUSTOM_COMMAND( OUTPUT ${dest} COMMAND ${NC_M4} @@ -2006,7 +2002,7 @@ set(dest "${CMAKE_CURRENT_SOURCE_DIR}/${filename}.c") VERBATIM ) - ENDIF(HAVE_M4) + ENDIF() ENDMACRO(GEN_m4) # Binary tests, but ones which depend on value of 'TEMP_LARGE' being defined. diff --git a/nczarr_test/CMakeLists.txt b/nczarr_test/CMakeLists.txt index a19eaa055..ed41e4be3 100644 --- a/nczarr_test/CMakeLists.txt +++ b/nczarr_test/CMakeLists.txt @@ -20,20 +20,18 @@ FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/test_filter_avail.c "${ASOURCE}") FILE(READ ${CMAKE_CURRENT_SOURCE_DIR}/../nc_test4/tst_specific_filters.sh SPSOURCE) STRING(PREPEND SPSOURCE "#!/bin/bash\n") STRING(PREPEND SPSOURCE "TESTNCZARR=1\n") -FILE(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/run_specific_filters.1 "${SPSOURCE}") -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/run_specific_filters.1 ${CMAKE_CURRENT_SOURCE_DIR}/run_specific_filters.sh @ONLY NEWLINE_STYLE LF) -FILE(COPY ${CMAKE_CURRENT_SOURCE_DIR}/run_specific_filters.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR} FILE_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE) -FILE(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/run_specific_filters.1) -FILE(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/run_specific_filters.sh) +# Replace with FILE(CONFIGURE) when cmake 3.18 is in common use +FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/run_specific_filters.1 "${SPSOURCE}") +CONFIGURE_FILE(${CMAKE_CURRENT_BINARY_DIR}/run_specific_filters.1 ${CMAKE_CURRENT_BINARY_DIR}/run_specific_filters.sh FILE_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE @ONLY NEWLINE_STYLE LF) +FILE(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/run_specific_filters.1) FILE(READ ${CMAKE_CURRENT_SOURCE_DIR}/../nc_test4/tst_unknown.sh SPSOURCE) STRING(PREPEND SPSOURCE "#!/bin/bash\n") STRING(PREPEND SPSOURCE "TESTNCZARR=1\n") -FILE(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/run_unknown.1 "${SPSOURCE}") -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/run_unknown.1 ${CMAKE_CURRENT_SOURCE_DIR}/run_unknown.sh @ONLY NEWLINE_STYLE LF) -FILE(COPY ${CMAKE_CURRENT_SOURCE_DIR}/run_unknown.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR} FILE_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE) -FILE(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/run_unknown.1) -FILE(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/run_unknown.sh) +# Replace with FILE(CONFIGURE) when cmake 3.18 is in common use +FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/run_unknown.1 "${SPSOURCE}") +CONFIGURE_FILE(${CMAKE_CURRENT_BINARY_DIR}/run_unknown.1 ${CMAKE_CURRENT_BINARY_DIR}/run_unknown.sh FILE_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE @ONLY NEWLINE_STYLE LF) +FILE(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/run_unknown.1) FILE(GLOB COPY_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.sh ${CMAKE_CURRENT_SOURCE_DIR}/ref*.cdl