CMakeLists.txt 7.92 KB
Newer Older
jehan's avatar
jehan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
############################################################################
# CMakeLists.txt
# Copyright (C) 2016  Belledonne Communications, Grenoble France
#
############################################################################
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
jehan's avatar
jehan committed
20 21 22
#
############################################################################

23 24 25 26
set(BCTOOLBOX_C_SOURCE_FILES
	containers/list.c
	logging/logging.c
	utils/port.c
27
	vfs.c
28
	vconnect.c
29
)
jehan's avatar
jehan committed
30

31 32
set(BCTOOLBOX_CXX_SOURCE_FILES containers/map.cc)

33
if(HAVE_EXECINFO) 
34
	list(APPEND BCTOOLBOX_CXX_SOURCE_FILES utils/exception.cc)
35
endif()
jehan's avatar
jehan committed
36

37
if(MBEDTLS_FOUND)
38
	list(APPEND BCTOOLBOX_C_SOURCE_FILES crypto/mbedtls.c)
39
endif()
40
if(POLARSSL_FOUND)
johan's avatar
johan committed
41
	if(POLARSSL_VERSION13_OK)
42
		list(APPEND BCTOOLBOX_C_SOURCE_FILES crypto/polarssl.c)
johan's avatar
johan committed
43
	else()
44
		list(APPEND BCTOOLBOX_C_SOURCE_FILES crypto/polarssl1.2.c)
johan's avatar
johan committed
45
	endif()
johan's avatar
johan committed
46
endif()
47
if(BCUNIT_FOUND)
48
	set(BCTOOLBOX_C_TESTER_SOURCE_FILES tester.c)
49
endif()
jehan's avatar
jehan committed
50

51 52
set(BCTOOLBOX_SOURCE_FILES ${BCTOOLBOX_C_SOURCE_FILES} ${BCTOOLBOX_CXX_SOURCE_FILES})
set(BCTOOLBOX_TESTER_SOURCE_FILES ${BCTOOLBOX_C_TESTER_SOURCE_FILES})
53

54 55 56
bc_apply_compile_flags(BCTOOLBOX_C_SOURCE_FILES STRICT_OPTIONS_CPP STRICT_OPTIONS_C)
bc_apply_compile_flags(BCTOOLBOX_C_TESTER_SOURCE_FILES STRICT_OPTIONS_CPP STRICT_OPTIONS_C)
bc_apply_compile_flags(BCTOOLBOX_CXX_SOURCE_FILES STRICT_OPTIONS_CPP STRICT_OPTIONS_CXX)
57

jehan's avatar
jehan committed
58
if(ENABLE_STATIC)
jehan's avatar
jehan committed
59
	add_library(bctoolbox-static STATIC ${BCTOOLBOX_SOURCE_FILES} ${BCTOOLBOX_HEADER_FILES})
60
	target_link_libraries(bctoolbox-static INTERFACE ${CMAKE_THREAD_LIBS_INIT})
61
	if(WIN32)
62
		target_link_libraries(bctoolbox-static INTERFACE "Winmm" "Ws2_32")
63
	endif()
64
	set_target_properties(bctoolbox-static PROPERTIES LINKER_LANGUAGE "CXX")
65 66 67
	if(NOT CMAKE_VERSION VERSION_LESS 3.1)
		set_target_properties(bctoolbox-static PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON)
	endif()
68
	set_target_properties(bctoolbox-static PROPERTIES OUTPUT_NAME bctoolbox)
69
	if(HAVE_LIBRT)
70
		target_link_libraries(bctoolbox-static INTERFACE rt)
71
	endif()
jehan's avatar
jehan committed
72
	if(HAVE_LIBDL)
73
		target_link_libraries(bctoolbox-static INTERFACE dl)
jehan's avatar
jehan committed
74
	endif()
75
	if(BCUNIT_FOUND)
76 77
		add_library(bctoolbox-tester-static STATIC ${BCTOOLBOX_TESTER_SOURCE_FILES})
		set_target_properties(bctoolbox-tester-static PROPERTIES OUTPUT_NAME bctoolbox-tester)
78
		target_link_libraries(bctoolbox-tester-static INTERFACE bctoolbox-static)
79
	endif()
80 81
endif()
if(ENABLE_SHARED)
jehan's avatar
jehan committed
82
	add_library(bctoolbox SHARED ${BCTOOLBOX_SOURCE_FILES} ${BCTOOLBOX_HEADER_FILES})
83
	target_link_libraries(bctoolbox PRIVATE ${CMAKE_THREAD_LIBS_INIT})
84
	if(WIN32)
85
		target_link_libraries(bctoolbox PRIVATE "Winmm" "Ws2_32")
86
		target_compile_definitions(bctoolbox PRIVATE "-DBCTBX_EXPORTS")
87
	endif()
Ghislain MARY's avatar
Ghislain MARY committed
88
	set_target_properties(bctoolbox PROPERTIES LINKER_LANGUAGE "CXX")
89 90 91
	if(NOT CMAKE_VERSION VERSION_LESS 3.1)
		set_target_properties(bctoolbox PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON)
	endif()
92
	if(ANDROID)
93 94 95 96 97
		if(ENABLE_ARCH_SUFFIX)
			set_target_properties(bctoolbox PROPERTIES OUTPUT_NAME "bctoolbox-${CMAKE_ANDROID_ARCH_ABI}")
		else()
			set_target_properties(bctoolbox PROPERTIES OUTPUT_NAME "bctoolbox")
		endif()
98 99 100
	else()
		# Do not version shared library on Android
		set_target_properties(bctoolbox PROPERTIES SOVERSION ${BCTOOLBOX_SO_VERSION})
101
	endif()
jehan's avatar
jehan committed
102
	if(MSVC)
103 104
		if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
			install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bctoolbox.pdb
Ghislain MARY's avatar
Ghislain MARY committed
105
				DESTINATION ${CMAKE_INSTALL_BINDIR}
jehan's avatar
jehan committed
106 107 108 109
				PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
			)
		endif()
	endif()
110
	if(HAVE_LIBRT)
111
		target_link_libraries(bctoolbox PRIVATE rt)
112
	endif()
jehan's avatar
jehan committed
113 114 115
	if(HAVE_LIBDL)
		target_link_libraries(bctoolbox PRIVATE dl)
	endif()
116
	if(BCUNIT_FOUND)
117 118
		add_library(bctoolbox-tester SHARED ${BCTOOLBOX_TESTER_SOURCE_FILES})
		set_target_properties(bctoolbox-tester PROPERTIES LINKER_LANGUAGE "CXX")
119
		target_link_libraries(bctoolbox-tester PRIVATE bctoolbox)
120 121 122
		if(WIN32)
			target_compile_definitions(bctoolbox-tester PRIVATE "-DBCTBX_EXPORTS")
		endif()
123
		if(ANDROID)
124 125 126 127 128
			if(ENABLE_ARCH_SUFFIX)
				set_target_properties(bctoolbox-tester PROPERTIES OUTPUT_NAME "bctoolbox-tester-${CMAKE_ANDROID_ARCH_ABI}")
			else()
				set_target_properties(bctoolbox-tester PROPERTIES OUTPUT_NAME "bctoolbox-tester")
			endif()
129 130 131
		else()
			# Do not version shared library on Android
			set_target_properties(bctoolbox-tester PROPERTIES SOVERSION ${BCTOOLBOXTESTER_SO_VERSION})
132
		endif()
133
		if(MSVC)
134 135
			if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
				install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bctoolbox-tester.pdb
136 137 138 139 140 141
					DESTINATION ${CMAKE_INSTALL_BINDIR}
					PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
				)
			endif()
		endif()
	endif()
jehan's avatar
jehan committed
142 143
endif()

johan's avatar
johan committed
144

145
if(MBEDTLS_FOUND)
146 147
	if(ENABLE_STATIC)
		target_include_directories(bctoolbox-static PUBLIC ${MBEDTLS_INCLUDE_DIRS})
148 149
		target_include_directories(bctoolbox-static PRIVATE ${BCTOOLBOX_PRIVATE_INCLUDE_DIRS})
		target_link_libraries(bctoolbox-static INTERFACE ${MBEDTLS_LIBRARIES})
150 151 152
	endif()
	if(ENABLE_SHARED)
		target_include_directories(bctoolbox PUBLIC ${MBEDTLS_INCLUDE_DIRS})
153
		target_include_directories(bctoolbox PRIVATE ${BCTOOLBOX_PRIVATE_INCLUDE_DIRS})
154
		target_link_libraries(bctoolbox PRIVATE ${MBEDTLS_LIBRARIES})
155
	endif()
156
endif()
157
if(POLARSSL_FOUND)
158 159
	if(ENABLE_STATIC)
		target_include_directories(bctoolbox-static PUBLIC ${POLARSSL_INCLUDE_DIRS})
160
		target_link_libraries(bctoolbox-static INTERFACE ${POLARSSL_LIBRARIES})
161 162 163
	endif()
	if(ENABLE_SHARED)
		target_include_directories(bctoolbox PUBLIC ${POLARSSL_INCLUDE_DIRS})
164
		target_link_libraries(bctoolbox PRIVATE ${POLARSSL_LIBRARIES})
165
	endif()
johan's avatar
johan committed
166
endif()
167
if(BCUNIT_FOUND)
168
	if(ENABLE_STATIC)
169
		target_include_directories(bctoolbox-tester-static PUBLIC ${BCUNIT_INCLUDE_DIRS})
170
		target_link_libraries(bctoolbox-tester-static INTERFACE bctoolbox-static ${BCUNIT_LIBRARIES})
171 172
	endif()
	if(ENABLE_SHARED)
173 174
		target_include_directories(bctoolbox-tester PUBLIC ${BCUNIT_INCLUDE_DIRS})
		target_link_libraries(bctoolbox-tester PRIVATE bctoolbox ${BCUNIT_LIBRARIES})
175 176 177
	endif()
endif()

johan's avatar
johan committed
178

179 180 181 182
if(ENABLE_STATIC)
	install(TARGETS bctoolbox-static EXPORT ${EXPORT_TARGETS_NAME}Targets
		ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
		PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
183
		COMPONENT core
184
	)
185
	if(BCUNIT_FOUND)
186 187 188 189 190 191
		install(TARGETS bctoolbox-tester-static EXPORT ${EXPORT_TARGETS_NAME}Targets
			ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
			PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
			COMPONENT tester
		)
	endif()
192 193 194 195 196 197 198
endif()
if(ENABLE_SHARED)
	install(TARGETS bctoolbox EXPORT ${EXPORT_TARGETS_NAME}Targets
		RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
		LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
		ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
		PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
199
		COMPONENT core
200
	)
201
	if(BCUNIT_FOUND)
202 203 204 205 206 207 208 209
		install(TARGETS bctoolbox-tester EXPORT ${EXPORT_TARGETS_NAME}Targets
			RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
			LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
			ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
			PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
			COMPONENT tester
		)
	endif()
210
endif()