CMakeLists.txt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # Project information.
  2. cmake_minimum_required ( VERSION 3.13.0 )
  3. project ( "coreHTTP unit test"
  4. VERSION 1.0.0
  5. LANGUAGES C )
  6. # Allow the project to be organized into folders.
  7. set_property( GLOBAL PROPERTY USE_FOLDERS ON )
  8. # Use C90.
  9. set( CMAKE_C_STANDARD 90 )
  10. set( CMAKE_C_STANDARD_REQUIRED ON )
  11. # Do not allow in-source build.
  12. if( ${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR} )
  13. message( FATAL_ERROR "In-source build is not allowed. Please build in a separate directory, such as ${PROJECT_SOURCE_DIR}/build." )
  14. endif()
  15. # Set global path variables.
  16. get_filename_component(__MODULE_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
  17. set(MODULE_ROOT_DIR ${__MODULE_ROOT_DIR} CACHE INTERNAL "coreHTTP repository root.")
  18. # Configure options to always show in CMake GUI.
  19. option( BUILD_CLONE_SUBMODULES
  20. "Set this to ON to automatically clone any required Git submodules. When OFF, submodules must be manually cloned."
  21. ON )
  22. # Set output directories.
  23. set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
  24. set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
  25. set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
  26. # ====================== Coverity Analysis Configuration =======================
  27. # Include filepaths for source and include.
  28. include( ${MODULE_ROOT_DIR}/httpFilePaths.cmake )
  29. # Target for Coverity analysis that builds the library.
  30. add_library( coverity_analysis
  31. ${HTTP_SOURCES} )
  32. # Build HTTP library target without custom config dependency.
  33. target_compile_definitions( coverity_analysis PUBLIC HTTP_DO_NOT_USE_CUSTOM_CONFIG=1 )
  34. # HTTP public include path.
  35. target_include_directories( coverity_analysis PUBLIC ${HTTP_INCLUDE_PUBLIC_DIRS} )
  36. # Build HTTP library target without logging
  37. target_compile_options(coverity_analysis PUBLIC -DNDEBUG )
  38. # ===================== Clone needed third-party libraries ======================
  39. # Define an llhttp parser resource path.
  40. set( LLHTTP_DIR ${MODULE_ROOT_DIR}/source/dependency/3rdparty/llhttp CACHE INTERNAL "llhttp library source directory." )
  41. include( llhttp_build.cmake )
  42. # Check if the llhttp_source directory exists.
  43. if( NOT EXISTS ${LLHTTP_DIR}/src/llhttp.c )
  44. # Attempt to clone llhttp.
  45. if( ${BUILD_CLONE_SUBMODULES} )
  46. clone_llhttp()
  47. else()
  48. message( FATAL_ERROR "The required submodule llhttp does not exist. Either clone it manually, or set BUILD_CLONE_SUBMODULES to 1 to automatically clone it during build." )
  49. endif()
  50. endif()
  51. # ============================ Test configuration ==============================
  52. # Define a CMock resource path.
  53. set( CMOCK_DIR ${MODULE_ROOT_DIR}/test/unit-test/CMock CACHE INTERNAL "CMock library source directory." )
  54. # Include CMock build configuration.
  55. include( unit-test/cmock_build.cmake )
  56. # Check if the CMock source directory exists, and if not present, clone the submodule
  57. # if BUILD_CLONE_SUBMODULES configuration is enabled.
  58. if( NOT EXISTS ${CMOCK_DIR}/src )
  59. # Attempt to clone CMock.
  60. if( ${BUILD_CLONE_SUBMODULES} )
  61. clone_cmock()
  62. else()
  63. message( FATAL_ERROR "The required submodule CMock does not exist. Either clone it manually, or set BUILD_CLONE_SUBMODULES to 1 to automatically clone it during build." )
  64. endif()
  65. endif()
  66. # Add unit test and coverage configuration.
  67. # Use CTest utility for managing test runs. This has to be added BEFORE
  68. # defining test targets with add_test()
  69. enable_testing()
  70. # Add build targets for CMock and Unit, required for unit testing.
  71. add_cmock_targets()
  72. # Add function to enable CMock based tests and coverage.
  73. include( ${MODULE_ROOT_DIR}/tools/cmock/create_test.cmake )
  74. # Include build configuration for unit tests.
  75. add_subdirectory( unit-test )
  76. # ==================== Coverage Analysis configuration ========================
  77. # Add a target for running coverage on tests.
  78. add_custom_target( coverage
  79. COMMAND ${CMAKE_COMMAND} -DCMOCK_DIR=${CMOCK_DIR}
  80. -P ${MODULE_ROOT_DIR}/tools/cmock/coverage.cmake
  81. DEPENDS cmock unity core_http_utest core_http_send_utest
  82. WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
  83. )