blob: 43610f4556d800bc887abd6274c83cb6be996b88 [file] [log] [blame]
Alexandre Lisionddd731e2014-01-31 11:50:08 -05001# Copyright (C) 2009 David Sugar, Tycho Softworks
2#
3# This file is free software; as a special exception the author gives
4# unlimited permission to copy and/or distribute it, with or without
5# modifications, as long as this notice is preserved.
6#
7# This program is distributed in the hope that it will be useful, but
8# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
9# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10#
11# This is a simplified build system for GNU uCommon. In particular, it
12# offers limited cmodel linkage support, at least for mingw32 support (and
13# probably visual c 6 also). If one really needs to do such things outside
14# these use cases, it is suggested to continue using the existing autotools
15# configure script driven build environment instead. Mostly the cmake one is
16# meant for generating project files for those working with IDE's to do
17# otherwise generic builds of the library and supporting applications.
18
19cmake_minimum_required(VERSION 2.6)
20PROJECT(ucommon)
21set (VERSION 6.0.7)
22
23set(RC_VERSION ${VERSION})
24STRING(REGEX REPLACE "[.]" "," RC_VERSION ${RC_VERSION})
25set(RC_VERSION "${RC_VERSION},0")
26
27set(SOVERSION ${VERSION})
28STRING(REGEX REPLACE "[.].*$" "" SOVERSION ${SOVERSION})
29
30# when we override default install prefix, assume full path is used...
31
32set(INSTALL_INCLUDEDIR include)
33set(INSTALL_BINDIR bin)
34
35if(WIN32)
36 set(INSTALL_MANDIR man)
37 set(INSTALL_DOCDIR doc/${PROJECT_NAME})
38 set(INSTALL_LOCALE locale)
39 set(INSTALL_LIBDIR bin)
40 set(INSTALL_SBINDIR bin)
41 set(INSTALL_INFODIR info)
42 set(SYSCONFDIR "etc" CACHE PATH "config directory")
43 set(STATEDIR "var" CACHE PATH "state directory")
44else()
45 if (NOT LIB_SUFFIX)
46 if (NOT EXISTS /etc/debian_version)
47 if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
48 set(LIB_SUFFIX 64)
49 endif()
50 endif()
51 endif()
52 set(INSTALL_SBINDIR sbin)
53 set(INSTALL_MANDIR share/man)
54 set(INSTALL_LOCALE share/locale)
55 set(INSTALL_DOCDIR share/doc/${PROJECT_NAME})
56 set(INSTALL_INFODIR share/info)
57 set(INSTALL_LIBDIR lib${LIB_SUFFIX})
58 set(SYSCONFDIR "/etc" CACHE PATH "config directory")
59 set(STATEDIR "/var" CACHE PATH "state directory")
60endif()
61
62set(UCOMMON_LOCALE ${CMAKE_INSTALL_PREFIX}/${INSTALL_LOCALE})
63set(UCOMMON_PREFIX ${CMAKE_INSTALL_PREFIX})
64
65set(UCOMMON_CFGPATH ${SYSCONFDIR})
66set(UCOMMON_VARPATH ${STATEDIR})
67
68# project options
69
70if(MSVC60)
71 set(BUILD_STATIC ON CACHE BOOL "static linking only" FORCE)
72 set(BUILD_STDLIB OFF CACHE BOOL "disable C++ stdlib" FORCE)
73 set(POSIX_TIMERS OFF CACHE BOOL "does not use posix timers" FORCE)
74 set(GCC_ATOMICS OFF CACHE BOOL "does not use gcc atomics" FORCE)
75 MARK_AS_ADVANCED(FORCE BUILD_STDLIB BUILD_STATIC POSIX_TIMERS GCC_ATOMICS)
76elseif(WIN32)
77 option(BUILD_RUNTIME "Set to OFF to build static runtime" ON)
78 if(BUILD_RUNTIME)
79 set(BUILD_RUNTIME_TYPE SHARED)
80 endif()
81 option(BUILD_STATIC "Set to OFF to build shared libraries" ON)
82 option(BUILD_STDLIB "Set to OFF to disable C++ stdlib" ON)
83 set(POSIX_TIMERS OFF CACHE BOOL "does not use posix timers" FORCE)
84 set(GCC_ATOMICS OFF CACHE BOOL "does not use gcc atomics" FORCE)
85else()
86 option(BUILD_STATIC "Set to ON to build static libraries" OFF)
87 option(BUILD_STDLIB "Set to OFF to disable C++ stdlib" ON)
88 option(POSIX_TIMERS "Set to ON to enable" OFF)
89 option(GCC_ATOMICS "Set to ON to enable" OFF)
90endif()
91
92MARK_AS_ADVANCED(POSIX_TIMERS GCC_ATOMICS)
93
94option(BUILD_TESTING "Set to ON to build test programs" OFF)
95
96MESSAGE( STATUS "Configuring GNU ${PROJECT_NAME} ${VERSION}...")
97include(CheckFunctionExists)
98include(CheckLibraryExists)
99include(CheckIncludeFiles)
100include(CTest)
101
102SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PROJECT_NAME} library")
103SET(CPACK_PACKAGE_VENDOR "David Sugar")
104SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
105SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
106set(PACKAGE_FILE_NAME ${PROJECT_NAME})
107set(PACKAGE_FILE_VERSION ${VERSION})
108
109IF (WIN32)
110 SET(CPACK_PACKAGE_FILE_NAME "${PACKAGE_FILE_NAME}-${PACKAGE_FILE_VERSION}")
111ELSE (WIN32)
112 SET(CPACK_PACKAGE_FILE_NAME "${PACKAGE_FILE_NAME}-bin-${PACKAGE_FILE_VERSION}")
113 if (NOT CPACK_GENERATOR)
114 SET(CPACK_GENERATOR "TBZ2")
115 endif()
116ENDIF (WIN32)
117
118IF(WIN32 AND NOT UNIX)
119 SET(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_FILE_NAME}")
120
121 # There is a bug in NSI that does not handle full unix paths properly. Make
122 # sure there is at least one set of four (4) backlasshes.
123 # SET(CPACK_PACKAGE_ICON "${CMake_SOURCE_DIR}/Utilities/Release\\\\InstallIcon.bmp")
124 # SET(CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\MyExecutable.exe")
125 SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} ${PROJECT_NAME}$")
126 SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\www.gnutelephony.org")
127 SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.gnutelephony.org")
128 SET(CPACK_NSIS_CONTACT "dyfet@gnutelephony.org")
129 SET(CPACK_NSIS_MODIFY_PATH ON)
130
131ENDIF(WIN32 AND NOT UNIX)
132
133set(CPACK_COMPONENTS_ALL libraries headers)
134set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
135set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ Headers")
136set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION "Dynamic library")
137set(CPACK_COMPONENT_HEADERS_DESCRIPTION
138 "Header files needed to build applications using ucommon library")
139
140# The following components are regex's to match anywhere (unless anchored)
141# in absolute path + filename to find files or directories to be excluded
142# from source tarball.
143SET (CPACK_SOURCE_IGNORE_FILES
144#svn, git files
145"\\\\.svn/" "\\\\.cvsignore$" "/\\\\.git/"
146# temporary files
147"\\\\.swp$"
148# backup files
149"~$"
150# eclipse, kdevelop and othe IDE files
151"\\\\.cdtproject$" "\\\\.cproject$" "\\\\.project$" "\\\\.settings/" "\\\\.kdev4/" "\\\\.kdev4$"
152# others
153"\\\\.#" "/#"
154# don't copy build and other dirs used for building
155"/build/" "/autom4te\\\\.cache/" "/_build/"
156# used before
157"/CVS/" "/\\\\.libs/" "/\\\\.deps/" "\\\\.o$" "\\\\.lo$" "\\\\.la$" "\\\\.sh$" "Makefile\\\\.in$")
158
159SET(CPACK_SOURCE_GENERATOR "TBZ2")
160SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${PACKAGE_FILE_NAME}-${PACKAGE_FILE_VERSION}")
161
162# This must always be last!
163INCLUDE(CPack)
164
165# set to true for debug and trace during CMakeLists development
166set(CMAKE_VERBOSE_MAKEFILE FALSE)
167
168# add module path of project if it exists...
169if (EXISTS "${CMAKE_SOURCE_DIR}/inc/")
170 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/inc/")
171endif()
172
173include (inc/ucommon.cmake)
174
175find_package(Threads)
176if (CMAKE_HAVE_PTHREAD_H)
177 set(HAVE_PTHREAD_H TRUE)
178endif()
179set (UCOMMON_LIBS ${UCOMMON_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${WITH_LDFLAGS})
180
181if (MINGW OR MSYS)
182 set (UCOMMON_LIBS ${UCOMMON_LIBS} mingwex mingw32)
183else()
184 if (WIN32 AND CMAKE_COMPILER_IS_GNUCXX)
185 set (UCOMMON_LIBS ${UCOMMON_LIBS} mingwex mingw32)
186 endif()
187endif()
188
189if (WIN32 OR MINGW OR MSYS OR CMAKE_SYSTEM MATCHES "Windows")
190 set (UCOMMON_LIBS ${UCOMMON_LIBS} crypt32 advapi32 user32 ws2_32 wsock32 kernel32)
191endif()
192
193if(UNIX AND NOT BUILD_STDLIB)
194 set(UCOMMON_LIBS ${UCOMMON_LIBS} c)
195endif()
196
197if(MSYS OR MINGW)
198 set(UCOMMON_LIBS ${UCOMMON_LIBS} msvcrt)
199endif()
200
201if(CMAKE_COMPILER_IS_GNUCXX AND NOT BUILD_STDLIB)
202 check_library_exists(gcc __modsi3 "" HAVE_GCC_LIB)
203 if(HAVE_GCC_LIB)
204 set(UCOMMON_LIBS ${UCOMMON_LIBS} gcc)
205 endif()
206endif()
207
208
209if(UNIX OR MSYS OR MINGW OR CYGWIN)
210 check_library_exists(dl dlopen "" HAVE_DL_LIB)
211 if (HAVE_DL_LIB)
212 set (UCOMMON_LIBS ${UCOMMON_LIBS} dl)
213 else()
214 check_library_exists(compat dlopen "" HAVE_COMPAT_LIB)
215 if(HAVE_COMPAT_LIB)
216 set (UCOMMON_LIBS ${UCOMMON_LIBS} compat)
217 endif()
218 endif()
219
220 check_library_exists(dld shl_load "" HAVE DLD_LIB)
221 if (HAVE_DLD_LIB)
222 set (UCOMMON_LIBS ${UCOMMON_LIBS} dld)
223 endif()
224
225 check_library_exists(socket socket "" HAVE_SOCKET_LIB)
226 if (HAVE_SOCKET_LIB)
227 set (UCOMMON_LIBS ${UCOMMON_LIBS} socket)
228 endif()
229
230 check_library_exists(posix4 sem_wait "" HAVE_POSIX4_LIB)
231 if (HAVE_POSIX4_LIB)
232 set(UCOMMON_LIBS ${UCOMMON_LIBS} posix4)
233 endif()
234
235 check_library_exists(rt clock_gettime "" HAVE_RT_LIB)
236 if (HAVE_RT_LIB)
237 set(UCOMMON_LIBS ${UCOMMON_LIBS} rt)
238 endif()
239endif()
240
241set (CMAKE_REQUIRED_LIBRARIES ${UCOMMON_LIBS})
242check_function_exists(getaddrinfo HAVE_GETADDRINFO)
243check_function_exists(socketpair HAVE_SOCKETPAIR)
244check_function_exists(inet_ntop HAVE_INET_NTOP)
245check_function_exists(gethostbyname2 HAVE_GETHOSTBYNAME2)
246check_function_exists(strcoll HAVE_STRCOLL)
247check_function_exists(stricmp HAVE_STRICMP)
248check_function_exists(stristr HAVE_STRISTR)
249check_function_exists(sysconf HAVE_SYSCONF)
250check_function_exists(posix_memalign HAVE_POSIX_MEMALIGN)
251check_function_exists(dlopen HAVE_DLOPEN)
252check_function_exists(shl_open HAVE_SHL_OPEN)
253check_function_exists(pthread_condattr_setclock HAVE_PTHREAD_CONDATTR_SETCLOCK)
254check_function_exists(pthread_setconcurrency HAVE_PTHREAD_SETCONCURRENCY)
255check_function_exists(pthread_yield HAVE_PTHREAD_YIELD)
256check_function_exists(pthread_yield_np HAVE_PTHREAD_YIELD_NP)
257check_function_exists(pthread_delay HAVE_PTHREAD_DELAY)
258check_function_exists(pthread_delay_np HAVE_PTHREAD_DELAY_NP)
259check_function_exists(pthread_setschedprio HAVE_PTHREAD_SETSCHEDPRIO)
260check_function_exists(ftok HAVE_FTOK)
261check_function_exists(shm_open HAVE_SHM_OPEN)
262check_function_exists(localtime_r HAVE_LOCALTIME_R)
263check_function_exists(gmtime_r HAVE_GMTIME_R)
264check_function_exists(strerror_r HAVE_STRERROR_R)
265check_function_exists(nanosleep HAVE_NANOSLEEP)
266check_function_exists(clock_nanosleep HAVE_CLOCK_NANOSLEEP)
267check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
268check_function_exists(posix_fadvise HAVE_POSIX_FADVISE)
269check_function_exists(ftruncate HAVE_FTRUNCATE)
270check_function_exists(pwrite HAVE_PWRITE)
271check_function_exists(setpgrp HAVE_SETPGRP)
272check_function_exists(setlocale HAVE_SETLOCALE)
273check_function_exists(gettext HAVE_GETTEXT)
274check_function_exists(execvp HAVE_EXECVP)
275check_function_exists(atexit HAVE_ATEXIT)
276check_function_exists(lstat HAVE_LSTAT)
277check_function_exists(realpath HAVE_REALPATH)
278check_function_exists(symlink HAVE_SYMLINK)
279check_function_exists(readlink HAVE_READLINK)
280check_function_exists(waitpid HAVE_WAITPID)
281check_function_exists(wait4 HAVE_WAIT4)
282
283check_include_files(sys/stat.h HAVE_SYS_STAT_H)
284check_include_files(strings.h HAVE_STRINGS_H)
285check_include_files(stdlib.h HAVE_STDLIB_H)
286check_include_files(string.h HAVE_STRING_H)
287check_include_files(memory.h HAVE_MEMORY_H)
288check_include_files(inttypes.h HAVE_INTTYPES_H)
289check_include_files(dlfcn.h HAVE_DLFCN_H)
290check_include_files(stdint.h HAVE_STDINT_H)
291check_include_files(poll.h HAVE_POLL_H)
292check_include_files(sys/mman.h HAVE_SYS_MMAN_H)
293check_include_files(sys/shm.h HAVE_SYS_SHM_H)
294check_include_files(sys/poll.h HAVE_SYS_POLL_H)
295check_include_files(sys/timeb.h HAVE_SYS_TIMEB_H)
296check_include_files(sys/types.h HAVE_SYS_TYPES_H)
297check_include_files(sys/wait.h HAVE_SYS_WAIT_H)
298check_include_files(endian.h HAVE_ENDIAN_H)
299check_include_files(sys/filio.h HAVE_SYS_FILIO_H)
300check_include_files(dirent.h HAVE_DIRENT_H)
301check_include_files(unistd.h HAVE_UNISTD_H)
302check_include_files(sys/resource.h HAVE_SYS_RESOURCE_H)
303check_include_files(wchar.h HAVE_WCHAR_H)
304check_include_files(mach/clock.h HAVE_MACH_CLOCK_H)
305check_include_files(mach-o/dyld.h HAVE_MACH_O_DYLD_H)
306check_include_files(linux/version.h HAVE_LINUX_VERSION_H)
307check_include_files(regex.h HAVE_REGEX_H)
308check_include_files(sys/inotify.h HAVE_SYS_INOTIFY_H)
309check_include_files(sys/event.h HAVE_SYS_EVENT_H)
310check_include_files(syslog.h HAVE_SYSLOG_H)
311check_include_files(openssl/ssl.h HAVE_OPENSSL)
312check_include_files(openssl/fips.h HAVE_OPENSSL_FIPS_H)
313check_include_files(libintl.h HAVE_LIBINTL_H)
314check_include_files(netinet/in.h HAVE_NETINET_IN_H)
315check_include_files(net/if.h HAVE_NET_IF_H)
316check_include_files(fcntl.h HAVE_FCNTL_H)
317check_include_files(termios.h HAVE_TERMIOS_H)
318check_include_files(termio.h HAVE_TERMIO_H)
319check_include_files(sys/param.h HAVE_SYS_PARAM_H)
320check_include_files(sys/file.h HAVE_SYS_FILE_H)
321check_include_files(sys/lockf.h HAVE_SYS_LOCKF_H)
322check_include_files(regex.h HAVE_REGEX_H)
323
324if(HAVE_REGEX_H)
325 check_library_exists(regex regfree "" HAVE_REGEX_LIB)
326 if(HAVE_REGEX_LIB OR MINGW OR MSYS)
327 set(UCOMMON_LIBS ${UCOMMON_LIBS} "regex")
328 endif()
329endif()
330
331set(UCOMMON_LIBS ${UCOMMON_LIBS} ${UCOMMON_LINKING})
332
333# for some reason, normal library searches always fail on broken windows
334if (WIN32 AND NOT UNIX AND NOT MINGW AND NOT MSYS)
335 set(HAVE_GETADDRINFO True)
336 set(HAVE_INET_NTOP True)
337endif()
338
339# we can mklink a build framework to top directory of a project...
340# this is done because we may have a project specific optimized build of
341# common libraries such as openssl...
342if(WIN32 AND EXISTS "${CMAKE_BINARY_DIR}/Frameworks/OpenSSL")
343 set(OPENSSL_FOUND TRUE)
344 if(EXISTS ${CMAKE_BINARY_DIR}/Frameworks/OpenSSL/inc32)
345 set(OPENSSL_INCLUDE_DIR ${CMAKE_BINARY_DIR}/Frameworks/OpenSSL/inc32)
346 else()
347 set(OPENSSL_INCLUDE_DIR ${CMAKE_BINARY_DIR}/Frameworks/OpenSSL/include)
348 endif()
349 if(NOT BUILD_STATIC AND EXISTS ${CMAKE_BINARY_DIR}/Frameworks/OpenSSL/out32dll)
350 set(OPENSSL_LIBRARIES ${CMAKE_BINARY_DIR}/Frameworks/OpenSSL/out32dll/ssleay32.lib ${CMAKE_BINARY_DIR}/Frameworks/OpenSSL/lib/libeay32.lib)
351 else()
352 set(OPENSSL_LIBRARIES ${CMAKE_BINARY_DIR}/Frameworks/OpenSSL/out32dll/ssleay32.lib ${CMAKE_BINARY_DIR}/Frameworks/OpenSSL/lib/libeay32.lib)
353 endif()
354endif()
355
356# alternate we use generic cmake openssl search...
357if(NOT HAVE_OPENSSL AND NOT OPENSSL_FOUND)
358 FIND_PACKAGE(OpenSSL)
359endif()
360
361# common build options can be passed to cmake using WITH_CFLAGS, WITH_LIBS,
362# and WITH_INCLUDES.
363include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc ${WITH_INCLUDES})
364add_definitions(${UCOMMON_FLAGS} ${WITH_CFLAGS})
365link_libraries(${WITH_LIBS})
366
367# by default we build static libs for windows, shared libs for unix.
368# we may also set this from a top level cmake or -DWITH_XX_LIBS
369
370if(BUILD_STATIC)
371 set(BUILD_LIBRARY_TYPE STATIC)
372else()
373 set(BUILD_LIBRARY_TYPE SHARED)
374endif()
375
376if(NOT BUILD_RUNTIME_TYPE)
377 set(BUILD_RUNTIME_TYPE ${BUILD_LIBRARY_TYPE})
378endif()
379
380file(GLOB common_src corelib/*.cpp)
381file(GLOB ucommon_inc inc/ucommon/*.h)
382file(GLOB commoncpp_src commoncpp/*.cpp)
383file(GLOB commoncpp_inc inc/commoncpp/*.h)
384file(GLOB ucommon_man utils/*.1)
385set(ucommon_man commoncpp-config.1 ucommon-config.1 ${ucommon_man})
386list(REMOVE_ITEM ucommon_inc inc/ucommon/secure.h)
387
388if(HAVE_OPENSSL)
389 set(secure_inc inc/ucommon/secure.h)
390 file(GLOB secure_src openssl/*.cpp openssl/*.h)
391 list(APPEND secure_src nossl/common.cpp)
392 if(MINGW)
393 set(SECURE_LIBS ssl crypto gdi32 z)
394 elseif(WIN32 AND NOT CYGWIN)
395 set(SECURE_LIBS ssleay32 libeay32 gdi32)
396 else()
397 set(SECURE_LIBS ssl crypto)
398 endif()
399elseif(OPENSSL_FOUND)
400 file(GLOB secure_src openssl/*.cpp openssl/*.h)
401 list(APPEND secure_src nossl/common.cpp)
402 include_directories(${OPENSSL_INCLUDE_DIR})
403 set(SECURE_LIBS ${OPENSSL_LIBRARIES})
404else()
405 file(GLOB secure_src nossl/*.cpp nossl/*.h)
406endif()
407
408if(NOT WIN32)
409 foreach(flag ${UCOMMON_FLAGS})
410 set(PACKAGE_FLAGS "${PACKAGE_FLAGS} ${flag}")
411 endforeach()
412 foreach(lib ${UCOMMON_LIBS})
413 STRING(REGEX REPLACE "^[-]l" "" slib ${lib})
414 set(PACKAGE_LIBS "${PACKAGE_LIBS} -l${slib}")
415 endforeach()
416 foreach(lib ${SECURE_LIBS})
417 STRING(REGEX REPLACE "^[-]l" "" slib ${lib})
418 set(ADDITIONAL_LIBS "${ADDITIONAL_LIBS} -l${slib}")
419 endforeach()
420 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc)
421 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config)
422 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.spec.cmake ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.spec @ONLY)
423
424 if(BUILD_STDLIB)
425 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/commoncpp.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/commoncpp.pc)
426 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/commoncpp-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/commoncpp-config)
427 endif()
428endif(NOT WIN32)
429
430configure_file(ucommon-config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/ucommon-config.h)
431include_directories(${CMAKE_CURRENT_BINARY_DIR})
432
433add_library(ucommon ${BUILD_RUNTIME_TYPE} ${common_src} ${ucommon_inc})
434set_target_properties(ucommon PROPERTIES VERSION ${VERSION} SOVERSION ${SOVERSION})
435target_link_libraries(ucommon ${UCOMMON_LIBS} ${WITH_LIBS})
436
437add_library(usecure ${BUILD_LIBRARY_TYPE} ${secure_src} ${secure_inc})
438set_target_properties(usecure PROPERTIES VERSION ${VERSION} SOVERSION ${SOVERSION})
439target_link_libraries(usecure ucommon ${WITH_LIBS} ${SECURE_LIBS} ${UCOMMON_LIBS})
440add_dependencies(usecure ucommon)
441
442if(BUILD_STDLIB)
443 add_library(commoncpp ${BUILD_LIBRARY_TYPE} ${commoncpp_src} ${commoncpp_inc})
444 set_target_properties(commoncpp PROPERTIES VERSION ${VERSION} SOVERSION ${SOVERSION})
445 target_link_libraries(commoncpp ucommon ${UCOMMON_LIBS} ${WITH_LIBS} ${SECURE_LIBS})
446 add_dependencies(commoncpp ucommon)
447endif()
448
449add_executable(ucommon-args utils/args.cpp)
450add_dependencies(ucommon-args ucommon)
451set_target_properties(ucommon-args PROPERTIES OUTPUT_NAME args)
452target_link_libraries(ucommon-args ucommon ${UCOMMON_LIBS} ${WITH_LIBS})
453
454add_executable(usecure-car utils/car.cpp)
455add_dependencies(usecure-car usecure ucommon)
456set_target_properties(usecure-car PROPERTIES OUTPUT_NAME car)
457target_link_libraries(usecure-car usecure ucommon ${SECURE_LIBS} ${UCOMMON_LIBS} ${WITH_LIBS})
458
459add_executable(ucommon-pdetach utils/pdetach.cpp)
460add_dependencies(ucommon-pdetach ucommon)
461set_target_properties(ucommon-pdetach PROPERTIES OUTPUT_NAME pdetach)
462target_link_libraries(ucommon-pdetach ucommon ${UCOMMON_LIBS} ${WITH_LIBS})
463
464add_executable(ucommon-sockaddr utils/sockaddr.cpp)
465add_dependencies(ucommon-sockaddr ucommon)
466set_target_properties(ucommon-sockaddr PROPERTIES OUTPUT_NAME sockaddr)
467target_link_libraries(ucommon-sockaddr ucommon ${UCOMMON_LIBS} ${WITH_LIBS})
468
469add_executable(usecure-scrub utils/scrub.cpp)
470add_dependencies(usecure-scrub usecure ucommon)
471set_target_properties(usecure-scrub PROPERTIES OUTPUT_NAME scrub-files)
472target_link_libraries(usecure-scrub usecure ucommon ${SECURE_LIBS} ${UCOMMON_LIBS} ${WITH_LIBS})
473
474add_executable(usecure-mdsum utils/mdsum.cpp)
475add_dependencies(usecure-mdsum usecure ucommon)
476set_target_properties(usecure-mdsum PROPERTIES OUTPUT_NAME mdsum)
477target_link_libraries(usecure-mdsum usecure ucommon ${SECURE_LIBS} ${UCOMMON_LIBS} ${WITH_LIBS})
478
479add_executable(usecure-zerofill utils/zerofill.cpp)
480add_dependencies(usecure-zerofill usecure ucommon)
481set_target_properties(usecure-zerofill PROPERTIES OUTPUT_NAME zerofill)
482target_link_libraries(usecure-zerofill usecure ucommon ${SECURE_LIBS} ${UCOMMON_LIBS} ${WITH_LIBS})
483
484find_package(Doxygen)
485
486if (DOXYGEN_FOUND)
487 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxy.config.cmake
488 ${CMAKE_CURRENT_BINARY_DIR}/doxy.config
489 @ONLY )
490
491 seT(DOXY_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/doxy.config")
492
493 #add_custom_target(doc ${DOXYGEN_EXECUTABLE} ${DOXY_CONFIG})
494 add_custom_target(doc
495 ${DOXYGEN_EXECUTABLE} ${DOXY_CONFIG}
496 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
497 COMMENT "Generating API documentation with Doxygen" VERBATIM
498 )
499
500 #
501 # TODO an: taken from internet, to be tested
502 #
503 # create a windows help .chm file using hhc.exe
504 # HTMLHelp DLL must be in path!
505 # fallback: use hhw.exe interactively
506 IF (WIN32)
507 FIND_PACKAGE(HTMLHelp)
508 IF (HTML_HELP_COMPILER)
509 SET (TMP "${CMAKE_CURRENT_BINARY_DIR}\\Doc\\html\\index.hhp")
510 STRING(REGEX REPLACE "[/]" "\\\\" HHP_FILE ${TMP} )
511 # MESSAGE(SEND_ERROR "DBG HHP_FILE=${HHP_FILE}")
512 ADD_CUSTOM_TARGET(winhelp ${HTML_HELP_COMPILER} ${HHP_FILE})
513 ADD_DEPENDENCIES (winhelp doc)
514
515 IF (NOT TARGET_DOC_SKIP_INSTALL)
516 # install windows help?
517 # determine useful name for output file
518 # should be project and version unique to allow installing
519 # multiple projects into one global directory
520 IF (EXISTS "${PROJECT_BINARY_DIR}/Doc/html/index.chm")
521 IF (PROJECT_NAME)
522 SET(OUT "${PROJECT_NAME}")
523 ELSE (PROJECT_NAME)
524 SET(OUT "Documentation") # default
525 ENDIF(PROJECT_NAME)
526 IF (${PROJECT_NAME}_VERSION_MAJOR)
527 SET(OUT "${OUT}-${${PROJECT_NAME}_VERSION_MAJOR}")
528 IF (${PROJECT_NAME}_VERSION_MINOR)
529 SET(OUT "${OUT}.${${PROJECT_NAME}_VERSION_MINOR}")
530 IF (${PROJECT_NAME}_VERSION_PATCH)
531 SET(OUT "${OUT}.${${PROJECT_NAME}_VERSION_PATCH}")
532 ENDIF(${PROJECT_NAME}_VERSION_PATCH)
533 ENDIF(${PROJECT_NAME}_VERSION_MINOR)
534 ENDIF(${PROJECT_NAME}_VERSION_MAJOR)
535 # keep suffix
536 SET(OUT "${OUT}.chm")
537
538 #MESSAGE("DBG ${PROJECT_BINARY_DIR}/Doc/html/index.chm \n${OUT}")
539 # create target used by install and package commands
540 INSTALL(FILES "${PROJECT_BINARY_DIR}/Doc/html/index.chm"
541 DESTINATION ${INSTALL_DOCDIR} RENAME "${OUT}")
542 ENDIF(EXISTS "${PROJECT_BINARY_DIR}/Doc/html/index.chm")
543 ENDIF(NOT TARGET_DOC_SKIP_INSTALL)
544
545 ENDIF(HTML_HELP_COMPILER)
546 # MESSAGE(SEND_ERROR "HTML_HELP_COMPILER=${HTML_HELP_COMPILER}")
547 ENDIF (WIN32)
548ENDIF(DOXYGEN_FOUND)
549
550
551message (STATUS)
552message (STATUS "-------------------------------------------------------------------------------")
553message (STATUS "CMAKE_INSTALL_PREFIX " ${CMAKE_INSTALL_PREFIX} )
554message (STATUS "LIB_SUFFIX " ${LIB_SUFFIX})
555message (STATUS "BUILD_STATIC " ${BUILD_STATIC})
556message (STATUS "BUILD STDLIB " ${BUILD_STDLIB})
557message (STATUS "BUILD_TESTING " ${BUILD_TESTING})
558message (STATUS "-------------------------------------------------------------------------------")
559message (STATUS)
560message (STATUS "Change a value with: cmake -D<Variable>=<Value>")
561message (STATUS)
562
563if (BUILD_TESTING)
564 ENABLE_TESTING()
565 add_subdirectory(test)
566endif()
567
568if(NOT WIN32)
569 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${INSTALL_LIBDIR}/pkgconfig)
570 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ucommon-config DESTINATION ${INSTALL_BINDIR})
571 if(BUILD_STDLIB)
572 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/commoncpp-config DESTINATION ${INSTALL_BINDIR})
573 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/commoncpp.pc DESTINATION ${INSTALL_LIBDIR}/pkgconfig)
574 endif()
575endif(NOT WIN32)
576
577install(FILES ${ucommon_inc} ${secure_inc} DESTINATION ${INSTALL_INCLUDEDIR}/ucommon COMPONENT headers)
578install(FILES ${commoncpp_inc} DESTINATION ${INSTALL_INCLUDEDIR}/commoncpp COMPONENT headers)
579
580if(BUILD_STDLIB)
581 install(TARGETS commoncpp DESTINATION ${INSTALL_LIBDIR} COMPONENT libraries)
582endif()
583
584install(TARGETS ucommon usecure DESTINATION ${INSTALL_LIBDIR} COMPONENT libraries)
585install(TARGETS ucommon-args ucommon-pdetach usecure-car usecure-scrub usecure-mdsum ucommon-sockaddr usecure-zerofill DESTINATION ${INSTALL_BINDIR})
586install(FILES ${ucommon_man} DESTINATION ${INSTALL_MANDIR}/man1)
587
588if(CMAKE_GENERATOR MATCHES "Unix Makefiles")
589 add_custom_target(uninstall
590 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
591 COMMAND xargs <install_manifest.txt
592 )
593endif()