From 36a05c184dcf312bc43c0899633ffd87ce9fea0d Mon Sep 17 00:00:00 2001
From: Pablo Lopez Rios
Date: Wed, 19 Jan 2022 10:02:34 +0000
Subject: [PATCH] Use cmake's configure_file() as suggested by Evgeny
Posenitskiy.
---
CMakeLists.txt | 4 +++-
include/cmake_config.h.in | 5 +++++
src/CMakeLists.txt | 11 -----------
3 files changed, 8 insertions(+), 12 deletions(-)
create mode 100644 include/cmake_config.h.in
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 42e0030..7bec4cd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,7 +16,7 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
# Optional configure for developer mode to generate source code from org-mode files.
option(TREXIO_DEVEL "TREXIO developer mode (for code generation)." OFF)
-if(EXISTS ".git/config")
+if(EXISTS "${CMAKE_SOURCE_DIR}/.git/config")
set(TREXIO_DEVEL ON)
find_package(Python3 REQUIRED)
if(Python3_FOUND)
@@ -32,6 +32,8 @@ if(EXISTS ".git/config")
else()
message(FATAL_ERROR "EMACS not found. It is required to produce TREXIO source code from org-mode files.")
endif()
+ configure_file(${CMAKE_SOURCE_DIR}/include/cmake_config.h.in
+ ${CMAKE_SOURCE_DIR}/include/config.h)
endif()
# Set directories to be included at build time.
diff --git a/include/cmake_config.h.in b/include/cmake_config.h.in
new file mode 100644
index 0000000..109829c
--- /dev/null
+++ b/include/cmake_config.h.in
@@ -0,0 +1,5 @@
+#define PACKAGE_VERSION "@PROJECT_VERSION@"
+#define VERSION "@PROJECT_VERSION@"
+#define VERSION_MAJOR @PROJECT_VERSION_MAJOR@
+#define VERSION_MINOR @PROJECT_VERSION_MINOR@
+#define VERSION_PATCH @PROJECT_VERSION_PATCH@
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b612608..1e46d5f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -127,17 +127,6 @@ if(TREXIO_DEVEL)
${TREXIO_MOD_FILE}
PROPERTIES GENERATED TRUE)
- add_custom_command(
- OUTPUT ${CMAKE_SOURCE_DIR}/include/config.h
- COMMAND bash -c "echo -e '#define TREXIO_PACKAGE_VERSION \"${PROJECT_VERSION}\"\\n#define TREXIO_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}\\n#define TREXIO_VERSION_MINOR ${PROJECT_VERSION_MINOR}\\n#define TREXIO_VERSION_PATCH ${PROJECT_VERSION_PATCH}' > config.h"
- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/include
- COMMENT "Generates minimal include/config.h without using autotools."
- VERBATIM)
-
- set_source_files_properties(
- ${CMAKE_SOURCE_DIR}/include/config.h
- PROPERTIES GENERATED TRUE)
-
endif()
# ============= INSTALL TREXIO ==============