CMake: now ext4_config.h will be automatically generated.
authorngkaho1234 <ngkaho1234@gmail.com>
Thu, 28 Jan 2016 16:18:58 +0000 (00:18 +0800)
committerngkaho1234 <ngkaho1234@gmail.com>
Fri, 29 Jan 2016 08:25:37 +0000 (16:25 +0800)
CMakeLists.txt
include/ext4_config.h

index 97fde99947a2a590c36ac3ea488f1abcb691d6c7..1a5fcf3d8a1bdbdecc6556be1b3af7df5d3a265a 100644 (file)
@@ -2,12 +2,13 @@ project(lwext4 C)
 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 @@ else()
     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
@@ -54,6 +79,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}")
 set(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
index 3d856eba8d425fb93e031dc41493466f48fb8695..0fc06cd46b4f2e4682baf82b5ad69b3886d4e197 100644 (file)
@@ -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
 
 /*****************************************************************************/