Merge pull request #49 from sirocyl/patch-1
[lwext4.git] / CMakeLists.txt
1 project(lwext4 C)
2 cmake_minimum_required(VERSION 3.4)
3
4
5 include_directories(include)
6 include_directories(${PROJECT_BINARY_DIR}/include)
7 include_directories(blockdev/filedev)
8 include_directories(blockdev/filedev_win)
9
10 set(BLOCKDEV_TYPE  none)
11
12 add_definitions(-DCONFIG_USE_DEFAULT_CONFIG=0)
13 add_definitions(-DVERSION="${VERSION}")
14
15 #Examples
16 if    (CMAKE_SYSTEM_PROCESSOR STREQUAL  cortex-m0)
17     #...
18 elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  cortex-m3)
19     add_definitions(-DCONFIG_UNALIGNED_ACCESS=1)
20 elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  arm-sim)
21     #...
22 elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  cortex-m4)
23     add_definitions(-DCONFIG_UNALIGNED_ACCESS=1)
24 elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  bf518)
25     #...
26 elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  avrxmega7)
27     add_definitions(-DCONFIG_HAVE_OWN_ERRNO=1)
28 elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  msp430g2210)
29     add_definitions(-DCONFIG_DEBUG_PRINTF=0)
30     add_definitions(-DCONFIG_DEBUG_ASSERT=0)
31     #...
32 elseif(LIB_ONLY)
33     add_definitions(-DCONFIG_DEBUG_PRINTF=0)
34     add_definitions(-DCONFIG_DEBUG_ASSERT=0)
35     add_definitions(-DCONFIG_HAVE_OWN_OFLAGS=1)
36     add_definitions(-DCONFIG_HAVE_OWN_ERRNO=0)
37     add_definitions(-DCONFIG_BLOCK_DEV_CACHE_SIZE=16)
38 else()
39     #Generic example target
40     if (WIN32)
41       set(BLOCKDEV_TYPE  windows)
42     else()
43       set(BLOCKDEV_TYPE  linux)
44     endif()
45     set (INSTALL_LIB 1)
46     add_definitions(-DCONFIG_HAVE_OWN_OFLAGS=0)
47     add_definitions(-DCONFIG_HAVE_OWN_ERRNO=0)
48     add_definitions(-DCONFIG_HAVE_OWN_ASSERT=0)
49     add_definitions(-DCONFIG_BLOCK_DEV_CACHE_SIZE=16)
50     add_subdirectory(fs_test)
51 endif()
52
53 macro(output_configure)
54     get_property(
55         definitions
56         DIRECTORY
57         PROPERTY COMPILE_DEFINITIONS
58     )
59     file(WRITE
60          ${PROJECT_BINARY_DIR}/include/generated/ext4_config.h
61          "")
62     foreach(item ${definitions})
63         string(REGEX MATCH "^CONFIG_" match_res ${item})
64         if(match_res)
65             string(REGEX REPLACE "=(.+)$" "" replace_res ${item})
66             string(CONFIGURE
67                    "#define ${replace_res} ${CMAKE_MATCH_1}"
68                    output_str)
69             file(APPEND
70                  ${PROJECT_BINARY_DIR}/include/generated/ext4_config.h
71                  "${output_str}\n")
72         endif()
73     endforeach()
74 endmacro()
75 output_configure()
76
77 add_subdirectory(blockdev)
78
79 #Library build
80 add_subdirectory(src)
81 #Detect all possible warnings for lwext4 target
82 if (NOT CMAKE_COMPILER_IS_GNUCC)
83     set_target_properties(lwext4 PROPERTIES COMPILE_FLAGS "")
84 else()
85     set_target_properties(lwext4 PROPERTIES COMPILE_FLAGS "-Wall -Wextra -pedantic")
86 endif()
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)