CMakeLists.txt 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. project(lwext4 C)
  2. cmake_minimum_required(VERSION 3.4)
  3. include_directories(include)
  4. include_directories(${PROJECT_BINARY_DIR}/include)
  5. include_directories(blockdev/filedev)
  6. include_directories(blockdev/filedev_win)
  7. set(BLOCKDEV_TYPE none)
  8. add_definitions(-DCONFIG_USE_DEFAULT_CONFIG=0)
  9. add_definitions(-DVERSION="${VERSION}")
  10. #Examples
  11. if (CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m0)
  12. #...
  13. elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m3)
  14. add_definitions(-DCONFIG_UNALIGNED_ACCESS=1)
  15. elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL arm-sim)
  16. #...
  17. elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m4)
  18. add_definitions(-DCONFIG_UNALIGNED_ACCESS=1)
  19. elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL bf518)
  20. #...
  21. elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL avrxmega7)
  22. add_definitions(-DCONFIG_HAVE_OWN_ERRNO=1)
  23. elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL msp430g2210)
  24. add_definitions(-DCONFIG_DEBUG_PRINTF=0)
  25. add_definitions(-DCONFIG_DEBUG_ASSERT=0)
  26. #...
  27. elseif(LIB_ONLY)
  28. add_definitions(-DCONFIG_DEBUG_PRINTF=0)
  29. add_definitions(-DCONFIG_DEBUG_ASSERT=0)
  30. add_definitions(-DCONFIG_HAVE_OWN_OFLAGS=1)
  31. add_definitions(-DCONFIG_HAVE_OWN_ERRNO=0)
  32. add_definitions(-DCONFIG_BLOCK_DEV_CACHE_SIZE=16)
  33. else()
  34. #Generic example target
  35. if (WIN32)
  36. set(BLOCKDEV_TYPE windows)
  37. else()
  38. set(BLOCKDEV_TYPE linux)
  39. endif()
  40. set (INSTALL_LIB 1)
  41. add_definitions(-DCONFIG_HAVE_OWN_OFLAGS=0)
  42. add_definitions(-DCONFIG_HAVE_OWN_ERRNO=0)
  43. add_definitions(-DCONFIG_HAVE_OWN_ASSERT=0)
  44. add_definitions(-DCONFIG_BLOCK_DEV_CACHE_SIZE=16)
  45. add_subdirectory(fs_test)
  46. endif()
  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. add_subdirectory(blockdev)
  71. #Library build
  72. add_subdirectory(src)
  73. #Detect all possible warnings for lwext4 target
  74. if (NOT CMAKE_COMPILER_IS_GNUCC)
  75. set_target_properties(lwext4 PROPERTIES COMPILE_FLAGS "")
  76. else()
  77. set_target_properties(lwext4 PROPERTIES COMPILE_FLAGS "-Wall -Wextra -pedantic")
  78. endif()
  79. #DISTRIBUTION
  80. set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
  81. set(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
  82. set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}")
  83. set(CPACK_SOURCE_GENERATOR "TBZ2")
  84. set(CPACK_SOURCE_PACKAGE_FILE_NAME
  85. "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
  86. set(CPACK_SOURCE_IGNORE_FILES
  87. "/build" ".git")
  88. include(CPack)
  89. add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)