Update license file (github badge)
[lwext4.git] / CMakeLists.txt
index 3068d0a3f05c95d28f26baf8c9766a239e0c7662..68a9cb0d2c6aa1e30072c7f4adff11e437207e19 100644 (file)
-project(lwext4 C)\r
-cmake_minimum_required(VERSION 2.8)\r
-\r
-\r
-\r
-#LIBRARY\r
-include_directories(. lwext4)\r
-aux_source_directory(lwext4 LWEXT4_SRC)\r
-add_library(lwext4  ${LWEXT4_SRC})\r
-\r
-#Examples\r
-if(CMAKE_SYSTEM_PROCESSOR STREQUAL  cortex-m3)\r
-    #Library size print\r
-    add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND ${SIZE} -B liblwext4.a)\r
-elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  cortex-m4)\r
-    #Library size print\r
-    add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND ${SIZE} -B liblwext4.a)\r
-    #Discoery disco demo\r
-    include(demos/stm32f429_disco/stm32f429_demo.cmake)\r
-elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  bf518)\r
-    #Library size print\r
-    add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND ${SIZE} -B liblwext4.a)\r
-else()\r
-    #Warning setup\r
-    set_target_properties(lwext4 PROPERTIES COMPILE_FLAGS "-Wall -Wextra -pedantic -std=gnu99")\r
-    #Library size print\r
-    add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND size -B liblwext4.a)\r
-    #Generic example target\r
-    include(demos/generic/generic.cmake)\r
-    include(fs_test/fs_test.cmake)\r
-endif()\r
-\r
-#DISTRIBUTION\r
-set(CPACK_PACKAGE_VERSION_MAJOR "0")\r
-set(CPACK_PACKAGE_VERSION_MINOR "4")\r
-set(CPACK_PACKAGE_VERSION_PATCH "0")\r
-set(CPACK_SOURCE_GENERATOR "TBZ2")\r
-set(CPACK_SOURCE_PACKAGE_FILE_NAME\r
-  "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")\r
-set(CPACK_SOURCE_IGNORE_FILES\r
-"/build" ".svn")\r
-include(CPack)\r
-\r
-add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)\r
+project(lwext4 C)
+cmake_minimum_required(VERSION 2.8)
+
+
+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
+if    (CMAKE_SYSTEM_PROCESSOR STREQUAL  cortex-m0)
+    #...
+elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  cortex-m3)
+    add_definitions(-DCONFIG_UNALIGNED_ACCESS=1)
+elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  arm-sim)
+    #...
+elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  cortex-m4)
+    add_definitions(-DCONFIG_UNALIGNED_ACCESS=1)
+elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  bf518)
+    #...
+elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  avrxmega7)
+    add_definitions(-DCONFIG_HAVE_OWN_ERRNO=1)
+elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  msp430g2210)
+    add_definitions(-DCONFIG_DEBUG_PRINTF=0)
+    add_definitions(-DCONFIG_DEBUG_ASSERT=0)
+    #...
+elseif(LIB_ONLY)
+    add_definitions(-DCONFIG_DEBUG_PRINTF=0)
+    add_definitions(-DCONFIG_DEBUG_ASSERT=0)
+    add_definitions(-DCONFIG_HAVE_OWN_OFLAGS=1)
+    add_definitions(-DCONFIG_HAVE_OWN_ERRNO=0)
+    add_definitions(-DCONFIG_BLOCK_DEV_CACHE_SIZE=16)
+else()
+    #Generic example target
+    if (WIN32)
+      set(BLOCKDEV_TYPE  windows)
+    else()
+      set(BLOCKDEV_TYPE  linux)
+    endif()
+    set (INSTALL_LIB 1)
+    add_definitions(-DCONFIG_HAVE_OWN_OFLAGS=0)
+    add_definitions(-DCONFIG_HAVE_OWN_ERRNO=0)
+    add_definitions(-DCONFIG_HAVE_OWN_ASSERT=0)
+    add_definitions(-DCONFIG_BLOCK_DEV_CACHE_SIZE=16)
+    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
+add_subdirectory(src)
+#Detect all possible warnings for lwext4 target
+if (NOT CMAKE_COMPILER_IS_GNUCC)
+    set_target_properties(lwext4 PROPERTIES COMPILE_FLAGS "")
+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}")
+set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}")
+set(CPACK_SOURCE_GENERATOR "TBZ2")
+set(CPACK_SOURCE_PACKAGE_FILE_NAME
+  "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
+set(CPACK_SOURCE_IGNORE_FILES
+"/build" ".git")
+include(CPack)
+
+
+add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)