shithub: lwext4

Download patch

ref: 9b40d089d6cf5912b558dd3e0ca1a246baa6750a
parent: a45154a49b743eba4669442e6993c50583329d99
author: ngkaho1234 <ngkaho1234@gmail.com>
date: Thu Jan 28 19:18:58 EST 2016

CMake: now ext4_config.h will be automatically generated.

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,12 +2,13 @@
 cmake_minimum_required(VERSION 2.8)
 
 
-include_directories(include)
+include_directories(${PROJECT_BINARY_DIR}/include)
 include_directories(blockdev/filedev)
 include_directories(blockdev/filedev_win)
 
 set(BLOCKDEV_TYPE  none)
 
+add_definitions(-DCONFIG_USE_DEFAULT_CONFIG=0)
 add_definitions(-DVERSION="${VERSION}")
 
 #Examples
@@ -43,6 +44,30 @@
     add_subdirectory(fs_test)
 endif()
 
+macro(output_configure)
+    get_property(
+        definitions
+        DIRECTORY
+        PROPERTY COMPILE_DEFINITIONS
+    )
+    file(WRITE
+         ${PROJECT_BINARY_DIR}/include/generated/ext4_config.h
+         "")
+    foreach(item ${definitions})
+        string(REGEX MATCH "^CONFIG_" match_res ${item})
+        if(match_res)
+            string(REGEX REPLACE "=(.+)$" "" replace_res ${item})
+            string(CONFIGURE
+                   "#define ${replace_res} ${CMAKE_MATCH_1}"
+                   output_str)
+            file(APPEND
+                 ${PROJECT_BINARY_DIR}/include/generated/ext4_config.h
+                 "${output_str}\n")
+        endif()
+    endforeach()
+endmacro()
+output_configure()
+
 add_subdirectory(blockdev)
 
 #Library build
@@ -53,6 +78,12 @@
 else()
     set_target_properties(lwext4 PROPERTIES COMPILE_FLAGS "-Wall -Wextra -pedantic")
 endif()
+
+#Config file generation
+file(
+    COPY include
+    DESTINATION .
+)
 
 #DISTRIBUTION
 set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
--- a/include/ext4_config.h
+++ b/include/ext4_config.h
@@ -41,8 +41,8 @@
 extern "C" {
 #endif
 
-#ifdef CONFIG_HAVE_OWN_CFG
-#include <config.h>
+#if !CONFIG_USE_DEFAULT_CFG
+#include "generated/ext4_config.h"
 #endif
 
 /*****************************************************************************/