|
| 1 | +# ============================ Repo configurations ============================= |
| 2 | + |
| 3 | +# Project information. |
| 4 | +cmake_minimum_required( VERSION 3.13.0 ) |
| 5 | +project( coreHTTP |
| 6 | + VERSION 4.0.2 |
| 7 | + LANGUAGES C ) |
| 8 | + |
| 9 | +# Allow the project to be organized into folders. |
| 10 | +set_property( GLOBAL PROPERTY USE_FOLDERS ON ) |
| 11 | + |
| 12 | +# Use C90. |
| 13 | +set( CMAKE_C_STANDARD 90 ) |
| 14 | +set( CMAKE_C_STANDARD_REQUIRED ON ) |
| 15 | + |
| 16 | +# Do not allow in-source build. |
| 17 | +if( ${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR} ) |
| 18 | + message( FATAL_ERROR "In-source build is not allowed. Please build in a separate directory, such as ${PROJECT_SOURCE_DIR}/build." ) |
| 19 | +endif() |
| 20 | + |
| 21 | +# Set global path variables. |
| 22 | +get_filename_component(__MODULE_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}" ABSOLUTE) |
| 23 | +set(MODULE_ROOT_DIR ${__MODULE_ROOT_DIR} CACHE INTERNAL "HTTP source root.") |
| 24 | + |
| 25 | +# Configure options to always show in CMake GUI. |
| 26 | +option( BUILD_CLONE_SUBMODULES |
| 27 | + "Set this to ON to automatically clone any required Git submodules. When OFF, submodules must be manually cloned." |
| 28 | + ON ) |
| 29 | + |
| 30 | +include( CMakeDependentOption ) |
| 31 | +CMAKE_DEPENDENT_OPTION( BUILD_SHARED_LIBS |
| 32 | + "Set this to ON to build HTTP as a shared library. When OFF, HTTP builds as a static library." |
| 33 | + ON "${ALLOW_SHARED_LIBRARIES}" |
| 34 | + OFF ) |
| 35 | + |
| 36 | +# Set output directories. |
| 37 | +set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) |
| 38 | +set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib ) |
| 39 | +set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib ) |
| 40 | + |
| 41 | +# ====================== coreHTTP library configurations ======================= |
| 42 | + |
1 | 43 | # Include filepaths for source and include.
|
2 | 44 | include(httpFilePaths.cmake)
|
3 | 45 |
|
4 | 46 | # Add http_parser submodule to HTTP client library.
|
5 |
| -add_subdirectory( third_party ) |
| 47 | +add_subdirectory( source/third_party ) |
| 48 | + |
| 49 | +# Check if the http_parser source directory exists. |
| 50 | +if( NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/source/third_party/http_parser/http_parser.c ) |
| 51 | + # Attempt to clone http_parser. |
| 52 | + if( ${BUILD_CLONE_SUBMODULES} ) |
| 53 | + clone_http_parser() |
| 54 | + else() |
| 55 | + message( FATAL_ERROR "The required submodule http_parser does not exist. Either clone it manually, or set BUILD_CLONE_SUBMODULES to 1 to automatically clone it during build." ) |
| 56 | + endif() |
| 57 | +endif() |
6 | 58 |
|
7 | 59 | # HTTP library target.
|
8 | 60 | add_library( http
|
9 | 61 | ${HTTP_SOURCES} )
|
10 | 62 |
|
11 | 63 | # HTTP public include path.
|
12 |
| -target_include_directories( http PUBLIC ${HTTP_INCLUDE_PUBLIC_DIRS} |
13 |
| - ${LOGGING_INCLUDE_DIRS} ) |
| 64 | +target_include_directories( http PUBLIC ${HTTP_INCLUDE_PUBLIC_DIRS} ) |
14 | 65 |
|
15 |
| -# HTTP private include path. |
16 |
| -target_include_directories( http PRIVATE ${HTTP_INCLUDE_PRIVATE_DIRS} ) |
| 66 | +# HTTP private include path. The unit test is default build so we include the test |
| 67 | +# configuration for now. |
| 68 | +target_include_directories( http PRIVATE ${HTTP_INCLUDE_PRIVATE_DIRS} |
| 69 | + ${MODULE_ROOT_DIR}/test ) |
17 | 70 |
|
18 | 71 | # Link http_parser to http target.
|
19 | 72 | target_link_libraries( http PRIVATE http_parser )
|
20 | 73 |
|
21 | 74 | # Organization of HTTP in IDE projects.
|
22 | 75 | set_target_properties( http PROPERTIES FOLDER libraries/standard )
|
23 |
| -source_group( include FILES include/http_client.h ) |
24 |
| -source_group( src FILES ${HTTP_SOURCES} ) |
25 |
| -source_group( src\\private FILES src/private/http_internal.h ) |
| 76 | +source_group( include FILES source/include/http_client.h source/portable/transport_interface.h ) |
| 77 | +source_group( source FILES ${HTTP_SOURCES} ) |
| 78 | +source_group( source\\private FILES source/private/http_internal.h ) |
| 79 | + |
| 80 | +# ============================ Test configurations ============================= |
| 81 | + |
| 82 | +# Include CMock build configuration. |
| 83 | +include( test/cmock_build.cmake ) |
| 84 | + |
| 85 | +# Check if the CMock source directory exists, and if not present, clone the submodule |
| 86 | +# if BUILD_CLONE_SUBMODULES configuration is enabled. |
| 87 | +if( NOT EXISTS ${MODULE_ROOT_DIR}/test/CMock/src ) |
| 88 | + # Attempt to clone CMock. |
| 89 | + if( ${BUILD_CLONE_SUBMODULES} ) |
| 90 | + clone_cmock() |
| 91 | + else() |
| 92 | + 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." ) |
| 93 | + endif() |
| 94 | +endif() |
| 95 | + |
| 96 | +# Add unit test and coverage configuration only if CMock directory exists. |
| 97 | +if( EXISTS ${MODULE_ROOT_DIR}/test/CMock/src ) |
| 98 | + |
| 99 | + # Use CTest utility for managing test runs. This has to be added BEFORE |
| 100 | + # defining test targets with add_test() |
| 101 | + enable_testing() |
| 102 | + |
| 103 | + # Add build targets for CMock and Unit, required for unit testing. |
| 104 | + add_cmock_targets() |
| 105 | + |
| 106 | + # Add function to enable CMOck based tests and coverage. |
| 107 | + include("${MODULE_ROOT_DIR}/tools/cmock/create_test.cmake") |
26 | 108 |
|
27 |
| -if(BUILD_TESTS) |
28 |
| - add_subdirectory(utest) |
| 109 | + # Include build configuration for unit tests. |
| 110 | + add_subdirectory( test ) |
| 111 | + |
| 112 | + # Add a target for running coverage on tests. |
| 113 | + add_custom_target(coverage |
| 114 | + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/tools/cmock/coverage.cmake |
| 115 | + DEPENDS cmock unity http_utest http_send_utest |
| 116 | + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
| 117 | + ) |
29 | 118 | endif()
|
0 commit comments