From 1a43a29e78a82ea5a1f30df8a6312c0a3442eb2c Mon Sep 17 00:00:00 2001 From: Moritz Pflanzer Date: Tue, 13 Feb 2018 15:52:16 +0100 Subject: [PATCH] Use configure_file for Perl files Solves the problem that the creduce executable was not regenerated everytime creduce.in changed. --- TODO | 3 -- creduce/CMakeLists.txt | 64 ++++++++++++++---------------------------- 2 files changed, 21 insertions(+), 46 deletions(-) diff --git a/TODO b/TODO index dfe428f0..44fec006 100644 --- a/TODO +++ b/TODO @@ -11,9 +11,6 @@ C-Reduce pre-release list: C-Reduce TODO list: -CMake: - make creduce from creduce.in at build time, not configure time - turn if (foo) goto bar; baz; bar: into diff --git a/creduce/CMakeLists.txt b/creduce/CMakeLists.txt index e9a4f0d9..797102f9 100644 --- a/creduce/CMakeLists.txt +++ b/creduce/CMakeLists.txt @@ -148,58 +148,36 @@ endif() # Generate file "creduce". # -file(READ "creduce.in" CREDUCE_CONTENT) -string(REPLACE "@perl@" "${PERL_EXECUTABLE}" - CREDUCE_CONTENT "${CREDUCE_CONTENT}") -# The following is not needed, but triggers a warning in CMake 3.1+. -# See `cmake --help-policy CMP0053'. Avoid the warning by not doing it. -# string(REPLACE "@PERL@" "${PERL_EXECUTABLE}" -# CREDUCE_CONTENT "${CREDUCE_CONTENT}") -string(REPLACE "@perllibdir@" "${PERL_LIB_DIR}" - CREDUCE_CONTENT "${CREDUCE_CONTENT}") -string(REPLACE "@prefix@" "${CMAKE_INSTALL_PREFIX}" - CREDUCE_CONTENT "${CREDUCE_CONTENT}") -file(WRITE - "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/creduce" - "${CREDUCE_CONTENT}") +# Set variables used as placeholders but not already defined in the CMake file +set(perl "${PERL}") +set(perllibdir "${PERL_LIB_DIR}") +set(prefix "${CMAKE_INSTALL_PREFIX}") + +configure_file("creduce.in" "${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/creduce" @ONLY) + +# Copy file and set correct permissions file(COPY - "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/creduce" + "${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/creduce" DESTINATION "${PROJECT_BINARY_DIR}" FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE - ) +) # Generate file "creduce_config.pm". # -file(READ "creduce_config.pm.in" CREDUCE_CONTENT) -string(REPLACE "@bindir@" "${BIN_DIR}" - CREDUCE_CONTENT "${CREDUCE_CONTENT}") -string(REPLACE "@libexecdir@" "${LIB_EXEC_DIR}" - CREDUCE_CONTENT "${CREDUCE_CONTENT}") -string(REPLACE "@PACKAGE_BUGREPORT@" "${creduce_PACKAGE_BUGREPORT}" - CREDUCE_CONTENT "${CREDUCE_CONTENT}") -string(REPLACE "@PACKAGE_NAME@" "${creduce_PACKAGE_NAME}" - CREDUCE_CONTENT "${CREDUCE_CONTENT}") -string(REPLACE "@PACKAGE_STRING@" "${creduce_PACKAGE_STRING}" - CREDUCE_CONTENT "${CREDUCE_CONTENT}") -string(REPLACE "@PACKAGE_URL@" "${creduce_PACKAGE_URL}" - CREDUCE_CONTENT "${CREDUCE_CONTENT}") -string(REPLACE "@PACKAGE_VERSION@" "${creduce_PACKAGE_VERSION}" - CREDUCE_CONTENT "${CREDUCE_CONTENT}") -string(REPLACE "@VERSION@" "${creduce_VERSION}" - CREDUCE_CONTENT "${CREDUCE_CONTENT}") -# ENE: I do not understand why the \'s seem to be required in the following -# match strings. -string(REPLACE "\@GIT_HASH@" "${GIT_HASH}" - CREDUCE_CONTENT "${CREDUCE_CONTENT}") -string(REPLACE "\@CLANG_FORMAT@" "${CLANG_FORMAT}" - CREDUCE_CONTENT "${CREDUCE_CONTENT}") -file(WRITE - "${PROJECT_BINARY_DIR}/creduce_config.pm" - "${CREDUCE_CONTENT}" - ) +# Set variables used as placeholders but not already defined in the CMake file +set(bindir "${BIN_DIR}") +set(libexecdir "${LIB_EXEC_DIR}") +set(PACKAGE_BUGREPORT "${creduce_PACKAGE_BUGREPORT}") +set(PACKAGE_NAME "${creduce_PACKAGE_NAME}") +set(PACKAGE_STRING "${creduce_PACKAGE_STRING}") +set(PACKAGE_URL "${creduce_PACKAGE_URL}") +set(PACKAGE_VERSION "${creduce_PACKAGE_VERSION}") +set(VERSION "${creduce_VERSION}") + +configure_file("creduce_config.pm.in" "creduce_config.pm" @ONLY) ###############################################################################