forked from Azure/umock-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
147 lines (119 loc) · 4.15 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#Copyright (c) Microsoft. All rights reserved.
#Licensed under the MIT license. See LICENSE file in the project root for full license information.
cmake_minimum_required(VERSION 2.8.11)
if(TARGET umock_c)
return()
endif()
option(run_unittests "set run_unittests to ON to run unittests (default is OFF)" OFF)
option(run_int_tests "set run_int_tests to ON to run the integration tests (default is OFF)" OFF)
option(use_installed_dependencies "set use_installed_dependencies to ON to use installed packages instead of building dependencies from submodules" OFF)
project(umock_c)
set(UMOCK_C_VERSION 1.1.4)
#Use solution folders.
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Build with -fPIC always
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
# Build with -Werror
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
elseif(UNIX) # LINUX OR APPLE
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
endif()
include (CTest)
# Add dependencies or submodules if use_installed_dependencies is OFF
include(dependencies.cmake)
set(umock_c_c_files
./src/umock_c.c
./src/umock_c_negative_tests.c
./src/umockalloc.c
./src/umockcall.c
./src/umockcallrecorder.c
./src/umocktypename.c
./src/umocktypes.c
./src/umocktypes_bool.c
./src/umocktypes_c.c
./src/umocktypes_stdint.c
./src/umocktypes_charptr.c
./src/umockcallpairs.c
./src/umockstring.c
./src/umockautoignoreargs.c
./src/umock_log.c
)
set(umock_c_h_files
./inc/umock_c.h
./inc/umock_c_internal.h
./inc/umock_c_negative_tests.h
./inc/umockalloc.h
./inc/umockcall.h
./inc/umockcallrecorder.h
./inc/umocktypename.h
./inc/umocktypes.h
./inc/umocktypes_bool.h
./inc/umocktypes_c.h
./inc/umocktypes_stdint.h
./inc/umocktypes_charptr.h
./inc/umockcallpairs.h
./inc/umockstring.h
./inc/umockautoignoreargs.h
./inc/umock_log.h
)
IF(WIN32)
#windows needs this define
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
ENDIF()
add_library(umock_c ${umock_c_c_files} ${umock_c_h_files})
set_target_properties(umock_c
PROPERTIES
FOLDER "test_tools")
#these are the include folders
#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
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)
include_directories(${UMOCK_C_INC_FOLDER} ${SHARED_UTIL_INC_FOLDER})
include("configs/umock_cFunctions.cmake")
if (${run_unittests} OR ${run_int_tests})
add_subdirectory(tests)
endif()
if(${use_installed_dependencies})
# Set CMAKE_INSTALL_* if not defined
include(GNUInstallDirs)
if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
set(CMAKE_INSTALL_LIBDIR "lib")
endif()
# Install UMock C
set(package_location "cmake")
install(TARGETS umock_c EXPORT umock_cTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/../bin
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(FILES ${umock_c_h_files} "./inc/umock_c_prod.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${UMOCK_C_VERSION}
COMPATIBILITY SameMajorVersion
)
configure_file("configs/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Config.cmake"
COPYONLY
)
install(EXPORT umock_cTargets
FILE
"${PROJECT_NAME}Targets.cmake"
DESTINATION
${package_location}
)
install(
FILES
"configs/${PROJECT_NAME}Functions.cmake"
"configs/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION
${package_location}
)
else()
message(WARNING "This package may only be installed when 'use_installed_dependencies' is ON")
endif()