ext4_extent: Rework extent insertion.
[lwext4.git] / CMakeLists.txt
1 project(lwext4 C)
2 cmake_minimum_required(VERSION 2.8)
3
4
5 include_directories(${PROJECT_BINARY_DIR}/include)
6 include_directories(blockdev/filedev)
7 include_directories(blockdev/filedev_win)
8
9 set(BLOCKDEV_TYPE  none)
10
11 add_definitions(-DCONFIG_USE_DEFAULT_CONFIG=0)
12 add_definitions(-DVERSION="${VERSION}")
13
14 #Examples
15 if    (CMAKE_SYSTEM_PROCESSOR STREQUAL  cortex-m0)
16     #...
17 elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  cortex-m3)
18     #...
19 elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  arm-sim)
20     #...
21 elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  cortex-m4)
22     #...
23 elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  bf518)
24     #...
25 elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  avrxmega7)
26     add_definitions(-DCONFIG_HAVE_OWN_ERRNO=1)
27 elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  msp430g2210)
28     add_definitions(-DCONFIG_DEBUG_PRINTF=0)
29     add_definitions(-DCONFIG_DEBUG_ASSERT=0)
30     #...
31 elseif(LIB_ONLY)
32     add_definitions(-DCONFIG_DEBUG_PRINTF=0)
33     add_definitions(-DCONFIG_DEBUG_ASSERT=0)
34     add_definitions(-DCONFIG_HAVE_OWN_OFLAGS=1)
35     add_definitions(-DCONFIG_HAVE_OWN_ERRNO=0)
36     add_definitions(-DCONFIG_BLOCK_DEV_CACHE_SIZE=16)
37 else()
38     #Generic example target
39     set(BLOCKDEV_TYPE  linux)
40     add_definitions(-DCONFIG_HAVE_OWN_OFLAGS=0)
41     add_definitions(-DCONFIG_HAVE_OWN_ERRNO=0)
42     add_definitions(-DCONFIG_HAVE_OWN_ASSERT=0)
43     add_definitions(-DCONFIG_BLOCK_DEV_CACHE_SIZE=16)
44     add_subdirectory(fs_test)
45 endif()
46
47 macro(output_configure)
48     get_property(
49         definitions
50         DIRECTORY
51         PROPERTY COMPILE_DEFINITIONS
52     )
53     file(WRITE
54          ${PROJECT_BINARY_DIR}/include/generated/ext4_config.h
55          "")
56     foreach(item ${definitions})
57         string(REGEX MATCH "^CONFIG_" match_res ${item})
58         if(match_res)
59             string(REGEX REPLACE "=(.+)$" "" replace_res ${item})
60             string(CONFIGURE
61                    "#define ${replace_res} ${CMAKE_MATCH_1}"
62                    output_str)
63             file(APPEND
64                  ${PROJECT_BINARY_DIR}/include/generated/ext4_config.h
65                  "${output_str}\n")
66         endif()
67     endforeach()
68 endmacro()
69 output_configure()
70
71 add_subdirectory(blockdev)
72
73 #Library build
74 add_subdirectory(src)
75 #Detect all possible warnings for lwext4 target
76 if (NOT CMAKE_COMPILER_IS_GNUCC)
77     set_target_properties(lwext4 PROPERTIES COMPILE_FLAGS "")
78 else()
79     set_target_properties(lwext4 PROPERTIES COMPILE_FLAGS "-Wall -Wextra -pedantic")
80 endif()
81
82 #Config file generation
83 file(
84     COPY include
85     DESTINATION .
86 )
87
88 #DISTRIBUTION
89 set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
90 set(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
91 set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}")
92 set(CPACK_SOURCE_GENERATOR "TBZ2")
93 set(CPACK_SOURCE_PACKAGE_FILE_NAME
94   "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
95 set(CPACK_SOURCE_IGNORE_FILES
96 "/build" ".git")
97 include(CPack)
98
99
100 add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)