Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 1 | # 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 | |
| 19 | cmake_minimum_required(VERSION 2.6) |
| 20 | PROJECT(ucommon) |
| 21 | set (VERSION 6.0.7) |
| 22 | |
| 23 | set(RC_VERSION ${VERSION}) |
| 24 | STRING(REGEX REPLACE "[.]" "," RC_VERSION ${RC_VERSION}) |
| 25 | set(RC_VERSION "${RC_VERSION},0") |
| 26 | |
| 27 | set(SOVERSION ${VERSION}) |
| 28 | STRING(REGEX REPLACE "[.].*$" "" SOVERSION ${SOVERSION}) |
| 29 | |
| 30 | # when we override default install prefix, assume full path is used... |
| 31 | |
| 32 | set(INSTALL_INCLUDEDIR include) |
| 33 | set(INSTALL_BINDIR bin) |
| 34 | |
| 35 | if(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") |
| 44 | else() |
| 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") |
| 60 | endif() |
| 61 | |
| 62 | set(UCOMMON_LOCALE ${CMAKE_INSTALL_PREFIX}/${INSTALL_LOCALE}) |
| 63 | set(UCOMMON_PREFIX ${CMAKE_INSTALL_PREFIX}) |
| 64 | |
| 65 | set(UCOMMON_CFGPATH ${SYSCONFDIR}) |
| 66 | set(UCOMMON_VARPATH ${STATEDIR}) |
| 67 | |
| 68 | # project options |
| 69 | |
| 70 | if(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) |
| 76 | elseif(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) |
| 85 | else() |
| 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) |
| 90 | endif() |
| 91 | |
| 92 | MARK_AS_ADVANCED(POSIX_TIMERS GCC_ATOMICS) |
| 93 | |
| 94 | option(BUILD_TESTING "Set to ON to build test programs" OFF) |
| 95 | |
| 96 | MESSAGE( STATUS "Configuring GNU ${PROJECT_NAME} ${VERSION}...") |
| 97 | include(CheckFunctionExists) |
| 98 | include(CheckLibraryExists) |
| 99 | include(CheckIncludeFiles) |
| 100 | include(CTest) |
| 101 | |
| 102 | SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PROJECT_NAME} library") |
| 103 | SET(CPACK_PACKAGE_VENDOR "David Sugar") |
| 104 | SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README") |
| 105 | SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING") |
| 106 | set(PACKAGE_FILE_NAME ${PROJECT_NAME}) |
| 107 | set(PACKAGE_FILE_VERSION ${VERSION}) |
| 108 | |
| 109 | IF (WIN32) |
| 110 | SET(CPACK_PACKAGE_FILE_NAME "${PACKAGE_FILE_NAME}-${PACKAGE_FILE_VERSION}") |
| 111 | ELSE (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() |
| 116 | ENDIF (WIN32) |
| 117 | |
| 118 | IF(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 | |
| 131 | ENDIF(WIN32 AND NOT UNIX) |
| 132 | |
| 133 | set(CPACK_COMPONENTS_ALL libraries headers) |
| 134 | set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries") |
| 135 | set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ Headers") |
| 136 | set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION "Dynamic library") |
| 137 | set(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. |
| 143 | SET (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 | |
| 159 | SET(CPACK_SOURCE_GENERATOR "TBZ2") |
| 160 | SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${PACKAGE_FILE_NAME}-${PACKAGE_FILE_VERSION}") |
| 161 | |
| 162 | # This must always be last! |
| 163 | INCLUDE(CPack) |
| 164 | |
| 165 | # set to true for debug and trace during CMakeLists development |
| 166 | set(CMAKE_VERBOSE_MAKEFILE FALSE) |
| 167 | |
| 168 | # add module path of project if it exists... |
| 169 | if (EXISTS "${CMAKE_SOURCE_DIR}/inc/") |
| 170 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/inc/") |
| 171 | endif() |
| 172 | |
| 173 | include (inc/ucommon.cmake) |
| 174 | |
| 175 | find_package(Threads) |
| 176 | if (CMAKE_HAVE_PTHREAD_H) |
| 177 | set(HAVE_PTHREAD_H TRUE) |
| 178 | endif() |
| 179 | set (UCOMMON_LIBS ${UCOMMON_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${WITH_LDFLAGS}) |
| 180 | |
| 181 | if (MINGW OR MSYS) |
| 182 | set (UCOMMON_LIBS ${UCOMMON_LIBS} mingwex mingw32) |
| 183 | else() |
| 184 | if (WIN32 AND CMAKE_COMPILER_IS_GNUCXX) |
| 185 | set (UCOMMON_LIBS ${UCOMMON_LIBS} mingwex mingw32) |
| 186 | endif() |
| 187 | endif() |
| 188 | |
| 189 | if (WIN32 OR MINGW OR MSYS OR CMAKE_SYSTEM MATCHES "Windows") |
| 190 | set (UCOMMON_LIBS ${UCOMMON_LIBS} crypt32 advapi32 user32 ws2_32 wsock32 kernel32) |
| 191 | endif() |
| 192 | |
| 193 | if(UNIX AND NOT BUILD_STDLIB) |
| 194 | set(UCOMMON_LIBS ${UCOMMON_LIBS} c) |
| 195 | endif() |
| 196 | |
| 197 | if(MSYS OR MINGW) |
| 198 | set(UCOMMON_LIBS ${UCOMMON_LIBS} msvcrt) |
| 199 | endif() |
| 200 | |
| 201 | if(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() |
| 206 | endif() |
| 207 | |
| 208 | |
| 209 | if(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() |
| 239 | endif() |
| 240 | |
| 241 | set (CMAKE_REQUIRED_LIBRARIES ${UCOMMON_LIBS}) |
| 242 | check_function_exists(getaddrinfo HAVE_GETADDRINFO) |
| 243 | check_function_exists(socketpair HAVE_SOCKETPAIR) |
| 244 | check_function_exists(inet_ntop HAVE_INET_NTOP) |
| 245 | check_function_exists(gethostbyname2 HAVE_GETHOSTBYNAME2) |
| 246 | check_function_exists(strcoll HAVE_STRCOLL) |
| 247 | check_function_exists(stricmp HAVE_STRICMP) |
| 248 | check_function_exists(stristr HAVE_STRISTR) |
| 249 | check_function_exists(sysconf HAVE_SYSCONF) |
| 250 | check_function_exists(posix_memalign HAVE_POSIX_MEMALIGN) |
| 251 | check_function_exists(dlopen HAVE_DLOPEN) |
| 252 | check_function_exists(shl_open HAVE_SHL_OPEN) |
| 253 | check_function_exists(pthread_condattr_setclock HAVE_PTHREAD_CONDATTR_SETCLOCK) |
| 254 | check_function_exists(pthread_setconcurrency HAVE_PTHREAD_SETCONCURRENCY) |
| 255 | check_function_exists(pthread_yield HAVE_PTHREAD_YIELD) |
| 256 | check_function_exists(pthread_yield_np HAVE_PTHREAD_YIELD_NP) |
| 257 | check_function_exists(pthread_delay HAVE_PTHREAD_DELAY) |
| 258 | check_function_exists(pthread_delay_np HAVE_PTHREAD_DELAY_NP) |
| 259 | check_function_exists(pthread_setschedprio HAVE_PTHREAD_SETSCHEDPRIO) |
| 260 | check_function_exists(ftok HAVE_FTOK) |
| 261 | check_function_exists(shm_open HAVE_SHM_OPEN) |
| 262 | check_function_exists(localtime_r HAVE_LOCALTIME_R) |
| 263 | check_function_exists(gmtime_r HAVE_GMTIME_R) |
| 264 | check_function_exists(strerror_r HAVE_STRERROR_R) |
| 265 | check_function_exists(nanosleep HAVE_NANOSLEEP) |
| 266 | check_function_exists(clock_nanosleep HAVE_CLOCK_NANOSLEEP) |
| 267 | check_function_exists(clock_gettime HAVE_CLOCK_GETTIME) |
| 268 | check_function_exists(posix_fadvise HAVE_POSIX_FADVISE) |
| 269 | check_function_exists(ftruncate HAVE_FTRUNCATE) |
| 270 | check_function_exists(pwrite HAVE_PWRITE) |
| 271 | check_function_exists(setpgrp HAVE_SETPGRP) |
| 272 | check_function_exists(setlocale HAVE_SETLOCALE) |
| 273 | check_function_exists(gettext HAVE_GETTEXT) |
| 274 | check_function_exists(execvp HAVE_EXECVP) |
| 275 | check_function_exists(atexit HAVE_ATEXIT) |
| 276 | check_function_exists(lstat HAVE_LSTAT) |
| 277 | check_function_exists(realpath HAVE_REALPATH) |
| 278 | check_function_exists(symlink HAVE_SYMLINK) |
| 279 | check_function_exists(readlink HAVE_READLINK) |
| 280 | check_function_exists(waitpid HAVE_WAITPID) |
| 281 | check_function_exists(wait4 HAVE_WAIT4) |
| 282 | |
| 283 | check_include_files(sys/stat.h HAVE_SYS_STAT_H) |
| 284 | check_include_files(strings.h HAVE_STRINGS_H) |
| 285 | check_include_files(stdlib.h HAVE_STDLIB_H) |
| 286 | check_include_files(string.h HAVE_STRING_H) |
| 287 | check_include_files(memory.h HAVE_MEMORY_H) |
| 288 | check_include_files(inttypes.h HAVE_INTTYPES_H) |
| 289 | check_include_files(dlfcn.h HAVE_DLFCN_H) |
| 290 | check_include_files(stdint.h HAVE_STDINT_H) |
| 291 | check_include_files(poll.h HAVE_POLL_H) |
| 292 | check_include_files(sys/mman.h HAVE_SYS_MMAN_H) |
| 293 | check_include_files(sys/shm.h HAVE_SYS_SHM_H) |
| 294 | check_include_files(sys/poll.h HAVE_SYS_POLL_H) |
| 295 | check_include_files(sys/timeb.h HAVE_SYS_TIMEB_H) |
| 296 | check_include_files(sys/types.h HAVE_SYS_TYPES_H) |
| 297 | check_include_files(sys/wait.h HAVE_SYS_WAIT_H) |
| 298 | check_include_files(endian.h HAVE_ENDIAN_H) |
| 299 | check_include_files(sys/filio.h HAVE_SYS_FILIO_H) |
| 300 | check_include_files(dirent.h HAVE_DIRENT_H) |
| 301 | check_include_files(unistd.h HAVE_UNISTD_H) |
| 302 | check_include_files(sys/resource.h HAVE_SYS_RESOURCE_H) |
| 303 | check_include_files(wchar.h HAVE_WCHAR_H) |
| 304 | check_include_files(mach/clock.h HAVE_MACH_CLOCK_H) |
| 305 | check_include_files(mach-o/dyld.h HAVE_MACH_O_DYLD_H) |
| 306 | check_include_files(linux/version.h HAVE_LINUX_VERSION_H) |
| 307 | check_include_files(regex.h HAVE_REGEX_H) |
| 308 | check_include_files(sys/inotify.h HAVE_SYS_INOTIFY_H) |
| 309 | check_include_files(sys/event.h HAVE_SYS_EVENT_H) |
| 310 | check_include_files(syslog.h HAVE_SYSLOG_H) |
| 311 | check_include_files(openssl/ssl.h HAVE_OPENSSL) |
| 312 | check_include_files(openssl/fips.h HAVE_OPENSSL_FIPS_H) |
| 313 | check_include_files(libintl.h HAVE_LIBINTL_H) |
| 314 | check_include_files(netinet/in.h HAVE_NETINET_IN_H) |
| 315 | check_include_files(net/if.h HAVE_NET_IF_H) |
| 316 | check_include_files(fcntl.h HAVE_FCNTL_H) |
| 317 | check_include_files(termios.h HAVE_TERMIOS_H) |
| 318 | check_include_files(termio.h HAVE_TERMIO_H) |
| 319 | check_include_files(sys/param.h HAVE_SYS_PARAM_H) |
| 320 | check_include_files(sys/file.h HAVE_SYS_FILE_H) |
| 321 | check_include_files(sys/lockf.h HAVE_SYS_LOCKF_H) |
| 322 | check_include_files(regex.h HAVE_REGEX_H) |
| 323 | |
| 324 | if(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() |
| 329 | endif() |
| 330 | |
| 331 | set(UCOMMON_LIBS ${UCOMMON_LIBS} ${UCOMMON_LINKING}) |
| 332 | |
| 333 | # for some reason, normal library searches always fail on broken windows |
| 334 | if (WIN32 AND NOT UNIX AND NOT MINGW AND NOT MSYS) |
| 335 | set(HAVE_GETADDRINFO True) |
| 336 | set(HAVE_INET_NTOP True) |
| 337 | endif() |
| 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... |
| 342 | if(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() |
| 354 | endif() |
| 355 | |
| 356 | # alternate we use generic cmake openssl search... |
| 357 | if(NOT HAVE_OPENSSL AND NOT OPENSSL_FOUND) |
| 358 | FIND_PACKAGE(OpenSSL) |
| 359 | endif() |
| 360 | |
| 361 | # common build options can be passed to cmake using WITH_CFLAGS, WITH_LIBS, |
| 362 | # and WITH_INCLUDES. |
| 363 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc ${WITH_INCLUDES}) |
| 364 | add_definitions(${UCOMMON_FLAGS} ${WITH_CFLAGS}) |
| 365 | link_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 | |
| 370 | if(BUILD_STATIC) |
| 371 | set(BUILD_LIBRARY_TYPE STATIC) |
| 372 | else() |
| 373 | set(BUILD_LIBRARY_TYPE SHARED) |
| 374 | endif() |
| 375 | |
| 376 | if(NOT BUILD_RUNTIME_TYPE) |
| 377 | set(BUILD_RUNTIME_TYPE ${BUILD_LIBRARY_TYPE}) |
| 378 | endif() |
| 379 | |
| 380 | file(GLOB common_src corelib/*.cpp) |
| 381 | file(GLOB ucommon_inc inc/ucommon/*.h) |
| 382 | file(GLOB commoncpp_src commoncpp/*.cpp) |
| 383 | file(GLOB commoncpp_inc inc/commoncpp/*.h) |
| 384 | file(GLOB ucommon_man utils/*.1) |
| 385 | set(ucommon_man commoncpp-config.1 ucommon-config.1 ${ucommon_man}) |
| 386 | list(REMOVE_ITEM ucommon_inc inc/ucommon/secure.h) |
| 387 | |
| 388 | if(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() |
| 399 | elseif(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}) |
| 404 | else() |
| 405 | file(GLOB secure_src nossl/*.cpp nossl/*.h) |
| 406 | endif() |
| 407 | |
| 408 | if(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() |
| 428 | endif(NOT WIN32) |
| 429 | |
| 430 | configure_file(ucommon-config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/ucommon-config.h) |
| 431 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) |
| 432 | |
| 433 | add_library(ucommon ${BUILD_RUNTIME_TYPE} ${common_src} ${ucommon_inc}) |
| 434 | set_target_properties(ucommon PROPERTIES VERSION ${VERSION} SOVERSION ${SOVERSION}) |
| 435 | target_link_libraries(ucommon ${UCOMMON_LIBS} ${WITH_LIBS}) |
| 436 | |
| 437 | add_library(usecure ${BUILD_LIBRARY_TYPE} ${secure_src} ${secure_inc}) |
| 438 | set_target_properties(usecure PROPERTIES VERSION ${VERSION} SOVERSION ${SOVERSION}) |
| 439 | target_link_libraries(usecure ucommon ${WITH_LIBS} ${SECURE_LIBS} ${UCOMMON_LIBS}) |
| 440 | add_dependencies(usecure ucommon) |
| 441 | |
| 442 | if(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) |
| 447 | endif() |
| 448 | |
| 449 | add_executable(ucommon-args utils/args.cpp) |
| 450 | add_dependencies(ucommon-args ucommon) |
| 451 | set_target_properties(ucommon-args PROPERTIES OUTPUT_NAME args) |
| 452 | target_link_libraries(ucommon-args ucommon ${UCOMMON_LIBS} ${WITH_LIBS}) |
| 453 | |
| 454 | add_executable(usecure-car utils/car.cpp) |
| 455 | add_dependencies(usecure-car usecure ucommon) |
| 456 | set_target_properties(usecure-car PROPERTIES OUTPUT_NAME car) |
| 457 | target_link_libraries(usecure-car usecure ucommon ${SECURE_LIBS} ${UCOMMON_LIBS} ${WITH_LIBS}) |
| 458 | |
| 459 | add_executable(ucommon-pdetach utils/pdetach.cpp) |
| 460 | add_dependencies(ucommon-pdetach ucommon) |
| 461 | set_target_properties(ucommon-pdetach PROPERTIES OUTPUT_NAME pdetach) |
| 462 | target_link_libraries(ucommon-pdetach ucommon ${UCOMMON_LIBS} ${WITH_LIBS}) |
| 463 | |
| 464 | add_executable(ucommon-sockaddr utils/sockaddr.cpp) |
| 465 | add_dependencies(ucommon-sockaddr ucommon) |
| 466 | set_target_properties(ucommon-sockaddr PROPERTIES OUTPUT_NAME sockaddr) |
| 467 | target_link_libraries(ucommon-sockaddr ucommon ${UCOMMON_LIBS} ${WITH_LIBS}) |
| 468 | |
| 469 | add_executable(usecure-scrub utils/scrub.cpp) |
| 470 | add_dependencies(usecure-scrub usecure ucommon) |
| 471 | set_target_properties(usecure-scrub PROPERTIES OUTPUT_NAME scrub-files) |
| 472 | target_link_libraries(usecure-scrub usecure ucommon ${SECURE_LIBS} ${UCOMMON_LIBS} ${WITH_LIBS}) |
| 473 | |
| 474 | add_executable(usecure-mdsum utils/mdsum.cpp) |
| 475 | add_dependencies(usecure-mdsum usecure ucommon) |
| 476 | set_target_properties(usecure-mdsum PROPERTIES OUTPUT_NAME mdsum) |
| 477 | target_link_libraries(usecure-mdsum usecure ucommon ${SECURE_LIBS} ${UCOMMON_LIBS} ${WITH_LIBS}) |
| 478 | |
| 479 | add_executable(usecure-zerofill utils/zerofill.cpp) |
| 480 | add_dependencies(usecure-zerofill usecure ucommon) |
| 481 | set_target_properties(usecure-zerofill PROPERTIES OUTPUT_NAME zerofill) |
| 482 | target_link_libraries(usecure-zerofill usecure ucommon ${SECURE_LIBS} ${UCOMMON_LIBS} ${WITH_LIBS}) |
| 483 | |
| 484 | find_package(Doxygen) |
| 485 | |
| 486 | if (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) |
| 548 | ENDIF(DOXYGEN_FOUND) |
| 549 | |
| 550 | |
| 551 | message (STATUS) |
| 552 | message (STATUS "-------------------------------------------------------------------------------") |
| 553 | message (STATUS "CMAKE_INSTALL_PREFIX " ${CMAKE_INSTALL_PREFIX} ) |
| 554 | message (STATUS "LIB_SUFFIX " ${LIB_SUFFIX}) |
| 555 | message (STATUS "BUILD_STATIC " ${BUILD_STATIC}) |
| 556 | message (STATUS "BUILD STDLIB " ${BUILD_STDLIB}) |
| 557 | message (STATUS "BUILD_TESTING " ${BUILD_TESTING}) |
| 558 | message (STATUS "-------------------------------------------------------------------------------") |
| 559 | message (STATUS) |
| 560 | message (STATUS "Change a value with: cmake -D<Variable>=<Value>") |
| 561 | message (STATUS) |
| 562 | |
| 563 | if (BUILD_TESTING) |
| 564 | ENABLE_TESTING() |
| 565 | add_subdirectory(test) |
| 566 | endif() |
| 567 | |
| 568 | if(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() |
| 575 | endif(NOT WIN32) |
| 576 | |
| 577 | install(FILES ${ucommon_inc} ${secure_inc} DESTINATION ${INSTALL_INCLUDEDIR}/ucommon COMPONENT headers) |
| 578 | install(FILES ${commoncpp_inc} DESTINATION ${INSTALL_INCLUDEDIR}/commoncpp COMPONENT headers) |
| 579 | |
| 580 | if(BUILD_STDLIB) |
| 581 | install(TARGETS commoncpp DESTINATION ${INSTALL_LIBDIR} COMPONENT libraries) |
| 582 | endif() |
| 583 | |
| 584 | install(TARGETS ucommon usecure DESTINATION ${INSTALL_LIBDIR} COMPONENT libraries) |
| 585 | install(TARGETS ucommon-args ucommon-pdetach usecure-car usecure-scrub usecure-mdsum ucommon-sockaddr usecure-zerofill DESTINATION ${INSTALL_BINDIR}) |
| 586 | install(FILES ${ucommon_man} DESTINATION ${INSTALL_MANDIR}/man1) |
| 587 | |
| 588 | if(CMAKE_GENERATOR MATCHES "Unix Makefiles") |
| 589 | add_custom_target(uninstall |
| 590 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" |
| 591 | COMMAND xargs <install_manifest.txt |
| 592 | ) |
| 593 | endif() |