| 1 |
#Copyright (c) Microsoft. All rights reserved. |
| 2 |
#Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 3 |
|
| 4 |
cmake_minimum_required(VERSION 2.8.11) |
| 5 |
|
| 6 |
if(TARGET umock_c) |
| 7 |
return() |
| 8 |
endif() |
| 9 |
|
| 10 |
option(run_unittests "set run_unittests to ON to run unittests (default is OFF)" OFF) |
| 11 |
option(run_int_tests "set run_int_tests to ON to run the integration tests (default is OFF)" OFF) |
| 12 |
option(use_installed_dependencies "set use_installed_dependencies to ON to use installed packages instead of building dependencies from submodules" OFF) |
| 13 |
option(use_cppunittest "set use_cppunittest to ON to build CppUnitTest tests on Windows (default is OFF)" OFF) |
| 14 |
|
| 15 |
project(umock_c) |
| 16 |
|
| 17 |
set(UMOCK_C_VERSION 1.1.19) |
| 18 |
|
| 19 |
#Use solution folders. |
| 20 |
set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 21 |
|
| 22 |
# Build with -fPIC always |
| 23 |
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) |
| 24 |
|
| 25 |
# Build with -Werror |
| 26 |
if(MSVC) |
| 27 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3") |
| 28 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3") |
| 29 |
elseif(UNIX) # LINUX OR APPLE |
| 30 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") |
| 31 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") |
| 32 |
endif() |
| 33 |
|
| 34 |
include (CTest) |
| 35 |
include (CheckIncludeFiles) |
| 36 |
|
| 37 |
set(original_run_e2e_tests ${run_e2e_tests}) |
| 38 |
set(original_run_int_tests ${run_int_tests}) |
| 39 |
set(original_run_unittests ${run_unittests}) |
| 40 |
|
| 41 |
set(run_e2e_tests OFF) |
| 42 |
set(run_int_tests OFF) |
| 43 |
set(run_unittests OFF) |
| 44 |
|
| 45 |
if(${use_installed_dependencies}) |
| 46 |
find_package(azure_macro_utils_c REQUIRED CONFIG) |
| 47 |
else() |
| 48 |
if (NOT TARGET azure_macro_utils_c) |
| 49 |
if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/deps/azure-macro-utils-c/CMakeLists.txt) |
| 50 |
add_subdirectory(deps/azure-macro-utils-c) |
| 51 |
else() |
| 52 |
message(FATAL_ERROR "Could not find azure_macro_utils_c") |
| 53 |
endif() |
| 54 |
endif() |
| 55 |
endif() |
| 56 |
|
| 57 |
if(${original_run_int_tests} OR ${original_run_unittests}) |
| 58 |
if(${use_installed_dependencies}) |
| 59 |
find_package(ctest REQUIRED CONFIG) |
| 60 |
find_package(testrunnerswitcher REQUIRED CONFIG) |
| 61 |
else() |
| 62 |
if (NOT TARGET testrunnerswitcher) |
| 63 |
add_subdirectory(deps/testrunner) |
| 64 |
endif() |
| 65 |
if (NOT TARGET ctest) |
| 66 |
add_subdirectory(deps/ctest) |
| 67 |
endif() |
| 68 |
endif() |
| 69 |
endif() |
| 70 |
|
| 71 |
set(run_e2e_tests ${original_run_e2e_tests}) |
| 72 |
set(run_int_tests ${original_run_int_tests}) |
| 73 |
set(run_unittests ${original_run_unittests}) |
| 74 |
|
| 75 |
include_directories(${MACRO_UTILS_INC_FOLDER}) |
| 76 |
|
| 77 |
set(umock_c_c_files |
| 78 |
./src/umock_c.c |
| 79 |
./src/umock_c_negative_tests.c |
| 80 |
./src/umockalloc.c |
| 81 |
./src/umockcall.c |
| 82 |
./src/umockcallrecorder.c |
| 83 |
./src/umocktypename.c |
| 84 |
./src/umocktypes.c |
| 85 |
./src/umocktypes_bool.c |
| 86 |
./src/umocktypes_c.c |
| 87 |
./src/umocktypes_stdint.c |
| 88 |
./src/umocktypes_charptr.c |
| 89 |
./src/umocktypes_wcharptr.c |
| 90 |
./src/umockcallpairs.c |
| 91 |
./src/umockstring.c |
| 92 |
./src/umockautoignoreargs.c |
| 93 |
./src/umock_log.c |
| 94 |
) |
| 95 |
|
| 96 |
set(umock_c_h_files |
| 97 |
./inc/umock_c/umock_c.h |
| 98 |
./inc/umock_c/umock_c_internal.h |
| 99 |
./inc/umock_c/umock_c_negative_tests.h |
| 100 |
./inc/umock_c/umock_c_prod.h |
| 101 |
./inc/umock_c/umockalloc.h |
| 102 |
./inc/umock_c/umockcall.h |
| 103 |
./inc/umock_c/umockcallrecorder.h |
| 104 |
./inc/umock_c/umocktypename.h |
| 105 |
./inc/umock_c/umocktypes.h |
| 106 |
./inc/umock_c/umocktypes_bool.h |
| 107 |
./inc/umock_c/umocktypes_c.h |
| 108 |
./inc/umock_c/umocktypes_stdint.h |
| 109 |
./inc/umock_c/umocktypes_charptr.h |
| 110 |
./inc/umock_c/umocktypes_struct.h |
| 111 |
./inc/umock_c/umocktypes_wcharptr.h |
| 112 |
./inc/umock_c/umockcallpairs.h |
| 113 |
./inc/umock_c/umockstring.h |
| 114 |
./inc/umock_c/umockautoignoreargs.h |
| 115 |
./inc/umock_c/umock_log.h |
| 116 |
) |
| 117 |
|
| 118 |
IF(WIN32) |
| 119 |
#windows needs this define |
| 120 |
add_definitions(-D_CRT_SECURE_NO_WARNINGS) |
| 121 |
# Make warning as error |
| 122 |
add_definitions(/WX) |
| 123 |
ENDIF() |
| 124 |
|
| 125 |
FILE(GLOB umock_c_md_files "devdoc/*.md") |
| 126 |
SOURCE_GROUP(devdoc FILES ${umock_c_md_files}) |
| 127 |
|
| 128 |
add_library(umock_c ${umock_c_c_files} ${umock_c_h_files} ${umock_c_md_files}) |
| 129 |
|
| 130 |
if(${use_installed_dependencies}) |
| 131 |
target_link_libraries(umock_c azure_macro_utils_c) |
| 132 |
endif() |
| 133 |
|
| 134 |
target_include_directories(umock_c |
| 135 |
PUBLIC |
| 136 |
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/inc> |
| 137 |
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> |
| 138 |
) |
| 139 |
|
| 140 |
set_target_properties(umock_c |
| 141 |
PROPERTIES |
| 142 |
FOLDER "test_tools") |
| 143 |
|
| 144 |
#these are the include folders |
| 145 |
#the following "set" statetement exports across the project a global variable called UMOCK_C_INC_FOLDER that expands to whatever needs to included when using umock_c library |
| 146 |
set(UMOCK_C_INC_FOLDER ${CMAKE_CURRENT_LIST_DIR}/inc CACHE INTERNAL "this is what needs to be included if using umock_c lib" FORCE) |
| 147 |
|
| 148 |
include_directories(${UMOCK_C_INC_FOLDER} ${SHARED_UTIL_INC_FOLDER}) |
| 149 |
|
| 150 |
CHECK_INCLUDE_FILES(stdint.h HAVE_STDINT_H) |
| 151 |
CHECK_INCLUDE_FILES(stdbool.h HAVE_STDBOOL_H) |
| 152 |
|
| 153 |
if ((NOT HAVE_STDINT_H) OR (NOT HAVE_STDBOOL_H)) |
| 154 |
include_directories(${UMOCK_C_INC_FOLDER}/umock_c/aux_inc) |
| 155 |
endif() |
| 156 |
|
| 157 |
include("configs/umock_cFunctions.cmake") |
| 158 |
|
| 159 |
if (${run_unittests} OR ${run_int_tests}) |
| 160 |
add_subdirectory(tests) |
| 161 |
endif() |
| 162 |
|
| 163 |
# Set CMAKE_INSTALL_* if not defined |
| 164 |
include(GNUInstallDirs) |
| 165 |
|
| 166 |
if(NOT DEFINED CMAKE_INSTALL_LIBDIR) |
| 167 |
set(CMAKE_INSTALL_LIBDIR "lib") |
| 168 |
endif() |
| 169 |
|
| 170 |
# Install UMock C |
| 171 |
set(package_location "cmake") |
| 172 |
|
| 173 |
install(TARGETS umock_c EXPORT umock_cTargets |
| 174 |
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 175 |
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 176 |
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/../bin |
| 177 |
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 178 |
) |
| 179 |
install(FILES ${umock_c_h_files} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/umock_c) |
| 180 |
|
| 181 |
include(CMakePackageConfigHelpers) |
| 182 |
|
| 183 |
write_basic_package_version_file( |
| 184 |
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake" |
| 185 |
VERSION ${UMOCK_C_VERSION} |
| 186 |
COMPATIBILITY SameMajorVersion |
| 187 |
) |
| 188 |
|
| 189 |
configure_file("configs/${PROJECT_NAME}Config.cmake" |
| 190 |
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Config.cmake" |
| 191 |
COPYONLY |
| 192 |
) |
| 193 |
|
| 194 |
install(EXPORT umock_cTargets |
| 195 |
FILE |
| 196 |
"${PROJECT_NAME}Targets.cmake" |
| 197 |
DESTINATION |
| 198 |
${package_location} |
| 199 |
) |
| 200 |
|
| 201 |
install( |
| 202 |
FILES |
| 203 |
"configs/${PROJECT_NAME}Functions.cmake" |
| 204 |
"configs/${PROJECT_NAME}Config.cmake" |
| 205 |
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake" |
| 206 |
DESTINATION |
| 207 |
${package_location} |
| 208 |
) |
| 209 |
|