![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/UNITTESTS/CMakeLists.txt@0:8fdf9a60065b, 2018-10-10 (annotated)
- Committer:
- kadonotakashi
- Date:
- Wed Oct 10 00:33:53 2018 +0000
- Revision:
- 0:8fdf9a60065b
how to make mbed librry
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | cmake_minimum_required(VERSION 3.0.2) |
kadonotakashi | 0:8fdf9a60065b | 2 | |
kadonotakashi | 0:8fdf9a60065b | 3 | set(PROJECT_NAME unittests) |
kadonotakashi | 0:8fdf9a60065b | 4 | set(LIB_NAME MbedOS) |
kadonotakashi | 0:8fdf9a60065b | 5 | |
kadonotakashi | 0:8fdf9a60065b | 6 | project(${PROJECT_NAME}) |
kadonotakashi | 0:8fdf9a60065b | 7 | |
kadonotakashi | 0:8fdf9a60065b | 8 | # Setup c++ standard |
kadonotakashi | 0:8fdf9a60065b | 9 | macro(use_cxx14) |
kadonotakashi | 0:8fdf9a60065b | 10 | if (CMAKE_VERSION VERSION_LESS 3.1) |
kadonotakashi | 0:8fdf9a60065b | 11 | if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
kadonotakashi | 0:8fdf9a60065b | 12 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++98") |
kadonotakashi | 0:8fdf9a60065b | 13 | endif() |
kadonotakashi | 0:8fdf9a60065b | 14 | else() |
kadonotakashi | 0:8fdf9a60065b | 15 | set(CMAKE_CXX_STANDARD 98) |
kadonotakashi | 0:8fdf9a60065b | 16 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
kadonotakashi | 0:8fdf9a60065b | 17 | endif() |
kadonotakashi | 0:8fdf9a60065b | 18 | endmacro() |
kadonotakashi | 0:8fdf9a60065b | 19 | |
kadonotakashi | 0:8fdf9a60065b | 20 | use_cxx14() |
kadonotakashi | 0:8fdf9a60065b | 21 | |
kadonotakashi | 0:8fdf9a60065b | 22 | #################### |
kadonotakashi | 0:8fdf9a60065b | 23 | # GTEST |
kadonotakashi | 0:8fdf9a60065b | 24 | #################### |
kadonotakashi | 0:8fdf9a60065b | 25 | |
kadonotakashi | 0:8fdf9a60065b | 26 | # Download and unpack googletest at configure time |
kadonotakashi | 0:8fdf9a60065b | 27 | configure_file(googletest-CMakeLists.txt.in googletest-download/CMakeLists.txt) |
kadonotakashi | 0:8fdf9a60065b | 28 | execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . |
kadonotakashi | 0:8fdf9a60065b | 29 | RESULT_VARIABLE result |
kadonotakashi | 0:8fdf9a60065b | 30 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download) |
kadonotakashi | 0:8fdf9a60065b | 31 | if (result) |
kadonotakashi | 0:8fdf9a60065b | 32 | message(FATAL_ERROR "CMake failed for google test: ${result}") |
kadonotakashi | 0:8fdf9a60065b | 33 | endif() |
kadonotakashi | 0:8fdf9a60065b | 34 | execute_process(COMMAND ${CMAKE_COMMAND} --build . |
kadonotakashi | 0:8fdf9a60065b | 35 | RESULT_VARIABLE result |
kadonotakashi | 0:8fdf9a60065b | 36 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download) |
kadonotakashi | 0:8fdf9a60065b | 37 | if (result) |
kadonotakashi | 0:8fdf9a60065b | 38 | message(FATAL_ERROR "Build failed for google test: ${result}") |
kadonotakashi | 0:8fdf9a60065b | 39 | endif() |
kadonotakashi | 0:8fdf9a60065b | 40 | |
kadonotakashi | 0:8fdf9a60065b | 41 | # Prevent overriding the parent project's compiler/linker |
kadonotakashi | 0:8fdf9a60065b | 42 | # settings on Windows |
kadonotakashi | 0:8fdf9a60065b | 43 | set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) |
kadonotakashi | 0:8fdf9a60065b | 44 | |
kadonotakashi | 0:8fdf9a60065b | 45 | # Add googletest directly to our build. This defines |
kadonotakashi | 0:8fdf9a60065b | 46 | # the gtest and gtest_main targets. |
kadonotakashi | 0:8fdf9a60065b | 47 | add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src |
kadonotakashi | 0:8fdf9a60065b | 48 | ${CMAKE_BINARY_DIR}/googletest-build |
kadonotakashi | 0:8fdf9a60065b | 49 | EXCLUDE_FROM_ALL) |
kadonotakashi | 0:8fdf9a60065b | 50 | |
kadonotakashi | 0:8fdf9a60065b | 51 | # The gtest/gtest_main/gmock/gmock_main targets carry header search path |
kadonotakashi | 0:8fdf9a60065b | 52 | # dependencies automatically when using CMake 2.8.11 or |
kadonotakashi | 0:8fdf9a60065b | 53 | # later. |
kadonotakashi | 0:8fdf9a60065b | 54 | target_include_directories(gmock_main SYSTEM BEFORE INTERFACE |
kadonotakashi | 0:8fdf9a60065b | 55 | "${gtest_SOURCE_DIR}/include" |
kadonotakashi | 0:8fdf9a60065b | 56 | "${gmock_SOURCE_DIR}/include") |
kadonotakashi | 0:8fdf9a60065b | 57 | |
kadonotakashi | 0:8fdf9a60065b | 58 | #################### |
kadonotakashi | 0:8fdf9a60065b | 59 | # TESTING |
kadonotakashi | 0:8fdf9a60065b | 60 | #################### |
kadonotakashi | 0:8fdf9a60065b | 61 | |
kadonotakashi | 0:8fdf9a60065b | 62 | enable_testing() |
kadonotakashi | 0:8fdf9a60065b | 63 | |
kadonotakashi | 0:8fdf9a60065b | 64 | set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES |
kadonotakashi | 0:8fdf9a60065b | 65 | "${CMAKE_BINARY_DIR}/Testing" |
kadonotakashi | 0:8fdf9a60065b | 66 | ) |
kadonotakashi | 0:8fdf9a60065b | 67 | |
kadonotakashi | 0:8fdf9a60065b | 68 | #################### |
kadonotakashi | 0:8fdf9a60065b | 69 | # CODE COVERAGE SETUP |
kadonotakashi | 0:8fdf9a60065b | 70 | #################### |
kadonotakashi | 0:8fdf9a60065b | 71 | |
kadonotakashi | 0:8fdf9a60065b | 72 | if (COVERAGE) |
kadonotakashi | 0:8fdf9a60065b | 73 | |
kadonotakashi | 0:8fdf9a60065b | 74 | if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug") |
kadonotakashi | 0:8fdf9a60065b | 75 | message(WARNING "Non-debug build may result misleading code coverage results.") |
kadonotakashi | 0:8fdf9a60065b | 76 | endif() |
kadonotakashi | 0:8fdf9a60065b | 77 | |
kadonotakashi | 0:8fdf9a60065b | 78 | # Append coverage compiler flags |
kadonotakashi | 0:8fdf9a60065b | 79 | set(COVERAGE_COMPILER_FLAGS "-g -O0 --coverage -fprofile-arcs -ftest-coverage") |
kadonotakashi | 0:8fdf9a60065b | 80 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}") |
kadonotakashi | 0:8fdf9a60065b | 81 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}") |
kadonotakashi | 0:8fdf9a60065b | 82 | |
kadonotakashi | 0:8fdf9a60065b | 83 | endif(COVERAGE) |
kadonotakashi | 0:8fdf9a60065b | 84 | |
kadonotakashi | 0:8fdf9a60065b | 85 | #################### |
kadonotakashi | 0:8fdf9a60065b | 86 | # UNIT TESTS |
kadonotakashi | 0:8fdf9a60065b | 87 | #################### |
kadonotakashi | 0:8fdf9a60065b | 88 | |
kadonotakashi | 0:8fdf9a60065b | 89 | # Set include dirs. |
kadonotakashi | 0:8fdf9a60065b | 90 | set(unittest-includes-base |
kadonotakashi | 0:8fdf9a60065b | 91 | "${PROJECT_SOURCE_DIR}/target_h" |
kadonotakashi | 0:8fdf9a60065b | 92 | "${PROJECT_SOURCE_DIR}/target_h/events" |
kadonotakashi | 0:8fdf9a60065b | 93 | "${PROJECT_SOURCE_DIR}/target_h/events/equeue" |
kadonotakashi | 0:8fdf9a60065b | 94 | "${PROJECT_SOURCE_DIR}/target_h/platform" |
kadonotakashi | 0:8fdf9a60065b | 95 | "${PROJECT_SOURCE_DIR}/stubs" |
kadonotakashi | 0:8fdf9a60065b | 96 | "${PROJECT_SOURCE_DIR}/.." |
kadonotakashi | 0:8fdf9a60065b | 97 | "${PROJECT_SOURCE_DIR}/../features" |
kadonotakashi | 0:8fdf9a60065b | 98 | "${PROJECT_SOURCE_DIR}/../features/netsocket" |
kadonotakashi | 0:8fdf9a60065b | 99 | "${PROJECT_SOURCE_DIR}/../platform" |
kadonotakashi | 0:8fdf9a60065b | 100 | "${PROJECT_SOURCE_DIR}/../drivers" |
kadonotakashi | 0:8fdf9a60065b | 101 | "${PROJECT_SOURCE_DIR}/../hal" |
kadonotakashi | 0:8fdf9a60065b | 102 | "${PROJECT_SOURCE_DIR}/../events" |
kadonotakashi | 0:8fdf9a60065b | 103 | "${PROJECT_SOURCE_DIR}/../events/equeue" |
kadonotakashi | 0:8fdf9a60065b | 104 | "${PROJECT_SOURCE_DIR}/../rtos" |
kadonotakashi | 0:8fdf9a60065b | 105 | "${PROJECT_SOURCE_DIR}/../rtos/TARGET_CORTEX" |
kadonotakashi | 0:8fdf9a60065b | 106 | "${PROJECT_SOURCE_DIR}/../rtos/TARGET_CORTEX/rtx5/Include" |
kadonotakashi | 0:8fdf9a60065b | 107 | "${PROJECT_SOURCE_DIR}/../cmsis" |
kadonotakashi | 0:8fdf9a60065b | 108 | "${PROJECT_SOURCE_DIR}/../features/frameworks" |
kadonotakashi | 0:8fdf9a60065b | 109 | "${PROJECT_SOURCE_DIR}/../features/frameworks/mbed-trace" |
kadonotakashi | 0:8fdf9a60065b | 110 | "${PROJECT_SOURCE_DIR}/../features/frameworks/nanostack-libservice" |
kadonotakashi | 0:8fdf9a60065b | 111 | "${PROJECT_SOURCE_DIR}/../features/frameworks/nanostack-libservice/mbed-client-libservice" |
kadonotakashi | 0:8fdf9a60065b | 112 | "${PROJECT_SOURCE_DIR}/../features/filesystem/fat" |
kadonotakashi | 0:8fdf9a60065b | 113 | "${PROJECT_SOURCE_DIR}/../features/filesystem/fat/ChaN" |
kadonotakashi | 0:8fdf9a60065b | 114 | "${PROJECT_SOURCE_DIR}/../features/filesystem/bd" |
kadonotakashi | 0:8fdf9a60065b | 115 | "${PROJECT_SOURCE_DIR}/../features/filesystem/" |
kadonotakashi | 0:8fdf9a60065b | 116 | "${PROJECT_SOURCE_DIR}/../features/filesystem/littlefs" |
kadonotakashi | 0:8fdf9a60065b | 117 | "${PROJECT_SOURCE_DIR}/../features/filesystem/littlefs/littlefs" |
kadonotakashi | 0:8fdf9a60065b | 118 | "${PROJECT_SOURCE_DIR}/../features/cellular/framework/API" |
kadonotakashi | 0:8fdf9a60065b | 119 | "${PROJECT_SOURCE_DIR}/../features/cellular/framework/AT" |
kadonotakashi | 0:8fdf9a60065b | 120 | "${PROJECT_SOURCE_DIR}/../features/cellular/framework" |
kadonotakashi | 0:8fdf9a60065b | 121 | "${PROJECT_SOURCE_DIR}/../features/cellular/framework/common" |
kadonotakashi | 0:8fdf9a60065b | 122 | "${PROJECT_SOURCE_DIR}/../features/lorawan" |
kadonotakashi | 0:8fdf9a60065b | 123 | "${PROJECT_SOURCE_DIR}/../features/lorawan/lorastack" |
kadonotakashi | 0:8fdf9a60065b | 124 | "${PROJECT_SOURCE_DIR}/../features/lorawan/lorastack/mac" |
kadonotakashi | 0:8fdf9a60065b | 125 | "${PROJECT_SOURCE_DIR}/../features/lorawan/lorastack/phy" |
kadonotakashi | 0:8fdf9a60065b | 126 | "${PROJECT_SOURCE_DIR}/../features/lorawan/system" |
kadonotakashi | 0:8fdf9a60065b | 127 | "${PROJECT_SOURCE_DIR}/../features/mbedtls" |
kadonotakashi | 0:8fdf9a60065b | 128 | "${PROJECT_SOURCE_DIR}/../features/mbedtls/inc" |
kadonotakashi | 0:8fdf9a60065b | 129 | ) |
kadonotakashi | 0:8fdf9a60065b | 130 | |
kadonotakashi | 0:8fdf9a60065b | 131 | # Create a list for test suites. |
kadonotakashi | 0:8fdf9a60065b | 132 | set(TEST_SUITES) |
kadonotakashi | 0:8fdf9a60065b | 133 | |
kadonotakashi | 0:8fdf9a60065b | 134 | # Get all matched tests. |
kadonotakashi | 0:8fdf9a60065b | 135 | file(GLOB_RECURSE unittest-file-list |
kadonotakashi | 0:8fdf9a60065b | 136 | "unittest.cmake" |
kadonotakashi | 0:8fdf9a60065b | 137 | ) |
kadonotakashi | 0:8fdf9a60065b | 138 | |
kadonotakashi | 0:8fdf9a60065b | 139 | if ("${unittest-file-list}" STREQUAL "") |
kadonotakashi | 0:8fdf9a60065b | 140 | message(FATAL_ERROR "No tests found. Exiting...") |
kadonotakashi | 0:8fdf9a60065b | 141 | endif() |
kadonotakashi | 0:8fdf9a60065b | 142 | |
kadonotakashi | 0:8fdf9a60065b | 143 | # Create unit test targets |
kadonotakashi | 0:8fdf9a60065b | 144 | foreach(testfile ${unittest-file-list}) |
kadonotakashi | 0:8fdf9a60065b | 145 | #################### |
kadonotakashi | 0:8fdf9a60065b | 146 | # DEFINE TARGETS |
kadonotakashi | 0:8fdf9a60065b | 147 | #################### |
kadonotakashi | 0:8fdf9a60065b | 148 | |
kadonotakashi | 0:8fdf9a60065b | 149 | # Init file lists. |
kadonotakashi | 0:8fdf9a60065b | 150 | set(unittest-includes ${unittest-includes-base}) |
kadonotakashi | 0:8fdf9a60065b | 151 | set(unittest-sources) |
kadonotakashi | 0:8fdf9a60065b | 152 | set(unittest-test-sources) |
kadonotakashi | 0:8fdf9a60065b | 153 | |
kadonotakashi | 0:8fdf9a60065b | 154 | # Get source files |
kadonotakashi | 0:8fdf9a60065b | 155 | include("${testfile}") |
kadonotakashi | 0:8fdf9a60065b | 156 | |
kadonotakashi | 0:8fdf9a60065b | 157 | get_filename_component(TEST_SUITE_DIR ${testfile} DIRECTORY) |
kadonotakashi | 0:8fdf9a60065b | 158 | |
kadonotakashi | 0:8fdf9a60065b | 159 | file(RELATIVE_PATH |
kadonotakashi | 0:8fdf9a60065b | 160 | TEST_SUITE_NAME # output |
kadonotakashi | 0:8fdf9a60065b | 161 | ${PROJECT_SOURCE_DIR} # root |
kadonotakashi | 0:8fdf9a60065b | 162 | ${TEST_SUITE_DIR} #abs dirpath |
kadonotakashi | 0:8fdf9a60065b | 163 | ) |
kadonotakashi | 0:8fdf9a60065b | 164 | |
kadonotakashi | 0:8fdf9a60065b | 165 | string(REGEX REPLACE "/|\\\\" "-" TEST_SUITE_NAME ${TEST_SUITE_NAME}) |
kadonotakashi | 0:8fdf9a60065b | 166 | |
kadonotakashi | 0:8fdf9a60065b | 167 | set(TEST_SUITES ${TEST_SUITES} ${TEST_SUITE_NAME}) |
kadonotakashi | 0:8fdf9a60065b | 168 | |
kadonotakashi | 0:8fdf9a60065b | 169 | set(LIBS_TO_BE_LINKED gmock_main) |
kadonotakashi | 0:8fdf9a60065b | 170 | |
kadonotakashi | 0:8fdf9a60065b | 171 | # Build directories list |
kadonotakashi | 0:8fdf9a60065b | 172 | set(BUILD_DIRECTORIES) |
kadonotakashi | 0:8fdf9a60065b | 173 | |
kadonotakashi | 0:8fdf9a60065b | 174 | if (unittest-sources) |
kadonotakashi | 0:8fdf9a60065b | 175 | # Create the testable static library. |
kadonotakashi | 0:8fdf9a60065b | 176 | add_library("${TEST_SUITE_NAME}.${LIB_NAME}" STATIC ${unittest-sources}) |
kadonotakashi | 0:8fdf9a60065b | 177 | target_include_directories("${TEST_SUITE_NAME}.${LIB_NAME}" PRIVATE |
kadonotakashi | 0:8fdf9a60065b | 178 | ${unittest-includes}) |
kadonotakashi | 0:8fdf9a60065b | 179 | set(LIBS_TO_BE_LINKED ${LIBS_TO_BE_LINKED} "${TEST_SUITE_NAME}.${LIB_NAME}") |
kadonotakashi | 0:8fdf9a60065b | 180 | |
kadonotakashi | 0:8fdf9a60065b | 181 | # Append lib build directory to list |
kadonotakashi | 0:8fdf9a60065b | 182 | list(APPEND BUILD_DIRECTORIES "./CMakeFiles/${TEST_SUITE_NAME}.${LIB_NAME}.dir") |
kadonotakashi | 0:8fdf9a60065b | 183 | endif(unittest-sources) |
kadonotakashi | 0:8fdf9a60065b | 184 | |
kadonotakashi | 0:8fdf9a60065b | 185 | if (unittest-test-sources) |
kadonotakashi | 0:8fdf9a60065b | 186 | # Create the executable. |
kadonotakashi | 0:8fdf9a60065b | 187 | add_executable(${TEST_SUITE_NAME} ${unittest-test-sources}) |
kadonotakashi | 0:8fdf9a60065b | 188 | target_include_directories(${TEST_SUITE_NAME} PRIVATE |
kadonotakashi | 0:8fdf9a60065b | 189 | ${unittest-includes}) |
kadonotakashi | 0:8fdf9a60065b | 190 | |
kadonotakashi | 0:8fdf9a60065b | 191 | # Link the executable with the libraries. |
kadonotakashi | 0:8fdf9a60065b | 192 | target_link_libraries(${TEST_SUITE_NAME} ${LIBS_TO_BE_LINKED}) |
kadonotakashi | 0:8fdf9a60065b | 193 | |
kadonotakashi | 0:8fdf9a60065b | 194 | add_test(NAME "${TEST_SUITE_NAME}" COMMAND ${TEST_SUITE_NAME}) |
kadonotakashi | 0:8fdf9a60065b | 195 | |
kadonotakashi | 0:8fdf9a60065b | 196 | # Append test build directory to list |
kadonotakashi | 0:8fdf9a60065b | 197 | list(APPEND BUILD_DIRECTORIES "./CMakeFiles/${TEST_SUITE_NAME}.dir") |
kadonotakashi | 0:8fdf9a60065b | 198 | else() |
kadonotakashi | 0:8fdf9a60065b | 199 | message(WARNING "No test source files found for ${TEST_SUITE_NAME}.\n") |
kadonotakashi | 0:8fdf9a60065b | 200 | endif(unittest-test-sources) |
kadonotakashi | 0:8fdf9a60065b | 201 | endforeach(testfile) |
kadonotakashi | 0:8fdf9a60065b | 202 |