diff options
author | Vincent Richard <[email protected]> | 2012-11-01 17:20:06 +0000 |
---|---|---|
committer | Vincent Richard <[email protected]> | 2012-11-01 17:20:06 +0000 |
commit | cce1c28bcecec87f34983599441ce16f7c2cf829 (patch) | |
tree | 0d94e042fce797cfe0a0cfbb11484de3fc969add /cmake | |
parent | Fixed typo in doc. (diff) | |
download | vmime-cce1c28bcecec87f34983599441ce16f7c2cf829.tar.gz vmime-cce1c28bcecec87f34983599441ce16f7c2cf829.zip |
Migrated build system to CMake. Conditional file compilation. Automatic selection of platform handler.
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/FindCppUnit.cmake | 34 | ||||
-rw-r--r-- | cmake/FindGSasl.cmake | 51 | ||||
-rw-r--r-- | cmake/FindIconv.cmake | 61 | ||||
-rw-r--r-- | cmake/TargetArch.cmake | 136 | ||||
-rw-r--r-- | cmake/Utils.cmake | 13 | ||||
-rw-r--r-- | cmake/config.hpp.cmake | 66 |
6 files changed, 361 insertions, 0 deletions
diff --git a/cmake/FindCppUnit.cmake b/cmake/FindCppUnit.cmake new file mode 100644 index 00000000..d74a4f3a --- /dev/null +++ b/cmake/FindCppUnit.cmake @@ -0,0 +1,34 @@ +# +# http://root.cern.ch/viewvc/trunk/cint/reflex/cmake/modules/FindCppUnit.cmake +# +# - Find CppUnit +# This module finds an installed CppUnit package. +# +# It sets the following variables: +# CPPUNIT_FOUND - Set to false, or undefined, if CppUnit isn't found. +# CPPUNIT_INCLUDE_DIR - The CppUnit include directory. +# CPPUNIT_LIBRARY - The CppUnit library to link against. + +FIND_PATH(CPPUNIT_INCLUDE_DIR cppunit/Test.h) +FIND_LIBRARY(CPPUNIT_LIBRARY NAMES cppunit) + +IF (CPPUNIT_INCLUDE_DIR AND CPPUNIT_LIBRARY) + SET(CPPUNIT_FOUND TRUE) +ENDIF (CPPUNIT_INCLUDE_DIR AND CPPUNIT_LIBRARY) + +IF (CPPUNIT_FOUND) + + # show which CppUnit was found only if not quiet + IF (NOT CppUnit_FIND_QUIETLY) + MESSAGE(STATUS "Found CppUnit: ${CPPUNIT_LIBRARY}") + ENDIF (NOT CppUnit_FIND_QUIETLY) + +ELSE (CPPUNIT_FOUND) + + # fatal error if CppUnit is required but not found + IF (CppUnit_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find CppUnit") + ENDIF (CppUnit_FIND_REQUIRED) + +ENDIF (CPPUNIT_FOUND) + diff --git a/cmake/FindGSasl.cmake b/cmake/FindGSasl.cmake new file mode 100644 index 00000000..31890a23 --- /dev/null +++ b/cmake/FindGSasl.cmake @@ -0,0 +1,51 @@ +# - Try to find the GNU sasl library (gsasl) +# +# Once done this will define +# +# GNUTLS_FOUND - System has gnutls +# GNUTLS_INCLUDE_DIR - The gnutls include directory +# GNUTLS_LIBRARIES - The libraries needed to use gnutls +# GNUTLS_DEFINITIONS - Compiler switches required for using gnutls + +# Adapted from FindGnuTLS.cmake, which is: +# Copyright 2009, Brad Hards, <[email protected]> +# +# Changes are Copyright 2009, Michele Caini, <[email protected]> +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + + +IF (GSASL_INCLUDE_DIR AND GSASL_LIBRARIES) + # in cache already + SET(GSasl_FIND_QUIETLY TRUE) +ENDIF (GSASL_INCLUDE_DIR AND GSASL_LIBRARIES) + +IF (NOT WIN32) + # use pkg-config to get the directories and then use these values + # in the FIND_PATH() and FIND_LIBRARY() calls + find_package(PkgConfig) + pkg_check_modules(PC_GSASL libgsasl) + SET(GSASL_DEFINITIONS ${PC_GSASL_CFLAGS_OTHER}) +ENDIF (NOT WIN32) + +FIND_PATH(GSASL_INCLUDE_DIR gsasl.h + HINTS + ${PC_GSASL_INCLUDEDIR} + ${PC_GSASL_INCLUDE_DIRS} + PATH_SUFFIXES gsasl + ) + +FIND_LIBRARY(GSASL_LIBRARIES NAMES gsasl libgsasl + HINTS + ${PC_GSASL_LIBDIR} + ${PC_GSASL_LIBRARY_DIRS} + ) + +INCLUDE(FindPackageHandleStandardArgs) + +# handle the QUIETLY and REQUIRED arguments and set GSASL_FOUND to TRUE if +# all listed variables are TRUE +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GSASL DEFAULT_MSG GSASL_LIBRARIES GSASL_INCLUDE_DIR) + +MARK_AS_ADVANCED(GSASL_INCLUDE_DIR GSASL_LIBRARIES) diff --git a/cmake/FindIconv.cmake b/cmake/FindIconv.cmake new file mode 100644 index 00000000..62336576 --- /dev/null +++ b/cmake/FindIconv.cmake @@ -0,0 +1,61 @@ +# - Try to find Iconv +# Once done this will define +# +# ICONV_FOUND - system has Iconv +# ICONV_INCLUDE_DIR - the Iconv include directory +# ICONV_LIBRARIES - Link these to use Iconv +# ICONV_SECOND_ARGUMENT_IS_CONST - the second argument for iconv() is const +# +include(CheckCXXSourceCompiles) + +IF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) + # Already in cache, be silent + SET(ICONV_FIND_QUIETLY TRUE) +ENDIF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) + +FIND_PATH(ICONV_INCLUDE_DIR iconv.h) + +IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + FIND_LIBRARY(ICONV_LIBRARIES NAMES iconv libiconv libiconv-2 c HINTS "/opt/local/lib") +ELSE() + FIND_LIBRARY(ICONV_LIBRARIES NAMES iconv libiconv libiconv-2 c) +ENDIF() + +IF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) + SET(ICONV_FOUND TRUE) +ENDIF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) + +set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR}) +set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES}) +IF(ICONV_FOUND) + check_cxx_source_compiles(" + #include <iconv.h> + int main(){ + iconv_t conv = 0; + const char* in = 0; + size_t ilen = 0; + char* out = 0; + size_t olen = 0; + iconv(conv, &in, &ilen, &out, &olen); + return 0; + } +" ICONV_SECOND_ARGUMENT_IS_CONST ) +ENDIF(ICONV_FOUND) +set(CMAKE_REQUIRED_INCLUDES) +set(CMAKE_REQUIRED_LIBRARIES) + +IF(ICONV_FOUND) + IF(NOT ICONV_FIND_QUIETLY) + MESSAGE(STATUS "Found Iconv: ${ICONV_LIBRARIES}") + ENDIF(NOT ICONV_FIND_QUIETLY) +ELSE(ICONV_FOUND) + IF(Iconv_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find Iconv") + ENDIF(Iconv_FIND_REQUIRED) +ENDIF(ICONV_FOUND) + +MARK_AS_ADVANCED( + ICONV_INCLUDE_DIR + ICONV_LIBRARIES + ICONV_SECOND_ARGUMENT_IS_CONST +) diff --git a/cmake/TargetArch.cmake b/cmake/TargetArch.cmake new file mode 100644 index 00000000..df038f73 --- /dev/null +++ b/cmake/TargetArch.cmake @@ -0,0 +1,136 @@ +# https://github.com/petroules/solar-cmake +# +# Based on the Qt 5 processor detection code, so should be very accurate +# https://qt.gitorious.org/qt/qtbase/blobs/master/src/corelib/global/qprocessordetection.h +# Currently handles arm (v5, v6, v7), x86 (32/64), ia64, and ppc (32/64) + +# Regarding POWER/PowerPC, just as is noted in the Qt source, +# "There are many more known variants/revisions that we do not handle/detect." + +set(archdetect_c_code " +#if defined(__arm__) || defined(__TARGET_ARCH_ARM) + #if defined(__ARM_ARCH_7__) \\ + || defined(__ARM_ARCH_7A__) \\ + || defined(__ARM_ARCH_7R__) \\ + || defined(__ARM_ARCH_7M__) \\ + || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 7) + #error cmake_ARCH armv7 + #elif defined(__ARM_ARCH_6__) \\ + || defined(__ARM_ARCH_6J__) \\ + || defined(__ARM_ARCH_6T2__) \\ + || defined(__ARM_ARCH_6Z__) \\ + || defined(__ARM_ARCH_6K__) \\ + || defined(__ARM_ARCH_6ZK__) \\ + || defined(__ARM_ARCH_6M__) \\ + || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 6) + #error cmake_ARCH armv6 + #elif defined(__ARM_ARCH_5TEJ__) \\ + || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 5) + #error cmake_ARCH armv5 + #else + #error cmake_ARCH arm + #endif +#elif defined(__i386) || defined(__i386__) || defined(_M_IX86) + #error cmake_ARCH i386 +#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64) + #error cmake_ARCH x86_64 +#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64) + #error cmake_ARCH ia64 +#elif defined(__ppc__) || defined(__ppc) || defined(__powerpc__) \\ + || defined(_ARCH_COM) || defined(_ARCH_PWR) || defined(_ARCH_PPC) \\ + || defined(_M_MPPC) || defined(_M_PPC) + #if defined(__ppc64__) || defined(__powerpc64__) || defined(__64BIT__) + #error cmake_ARCH ppc64 + #else + #error cmake_ARCH ppc + #endif +#endif + +#error cmake_ARCH unknown +") + +# Set ppc_support to TRUE before including this file or ppc and ppc64 +# will be treated as invalid architectures since they are no longer supported by Apple + +function(target_architecture output_var) + if(APPLE AND CMAKE_OSX_ARCHITECTURES) + # On OS X we use CMAKE_OSX_ARCHITECTURES *if* it was set + # First let's normalize the order of the values + + # Note that it's not possible to compile PowerPC applications if you are using + # the OS X SDK version 10.6 or later - you'll need 10.4/10.5 for that, so we + # disable it by default + # See this page for more information: + # http://stackoverflow.com/questions/5333490/how-can-we-restore-ppc-ppc64-as-well-as-full-10-4-10-5-sdk-support-to-xcode-4 + + # Architecture defaults to i386 or ppc on OS X 10.5 and earlier, depending on the CPU type detected at runtime. + # On OS X 10.6+ the default is x86_64 if the CPU supports it, i386 otherwise. + + foreach(osx_arch ${CMAKE_OSX_ARCHITECTURES}) + if("${osx_arch}" STREQUAL "ppc" AND ppc_support) + set(osx_arch_ppc TRUE) + elseif("${osx_arch}" STREQUAL "i386") + set(osx_arch_i386 TRUE) + elseif("${osx_arch}" STREQUAL "x86_64") + set(osx_arch_x86_64 TRUE) + elseif("${osx_arch}" STREQUAL "ppc64" AND ppc_support) + set(osx_arch_ppc64 TRUE) + else() + message(FATAL_ERROR "Invalid OS X arch name: ${osx_arch}") + endif() + endforeach() + + # Now add all the architectures in our normalized order + if(osx_arch_ppc) + list(APPEND ARCH ppc) + endif() + + if(osx_arch_i386) + list(APPEND ARCH i386) + endif() + + if(osx_arch_x86_64) + list(APPEND ARCH x86_64) + endif() + + if(osx_arch_ppc64) + list(APPEND ARCH ppc64) + endif() + else() + file(WRITE "${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/arch.c" "${archdetect_c_code}") + + enable_language(C) + + # Detect the architecture in a rather creative way... + # This compiles a small C program which is a series of ifdefs that selects a + # particular #error preprocessor directive whose message string contains the + # target architecture. The program will always fail to compile (both because + # file is not a valid C program, and obviously because of the presence of the + # #error preprocessor directives... but by exploiting the preprocessor in this + # way, we can detect the correct target architecture even when cross-compiling, + # since the program itself never needs to be run (only the compiler/preprocessor) + try_run( + run_result_unused + compile_result_unused + "${CMAKE_BINARY_DIR}" + "${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/arch.c" + COMPILE_OUTPUT_VARIABLE ARCH + CMAKE_FLAGS CMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES} + ) + + # Parse the architecture name from the compiler output + string(REGEX MATCH "cmake_ARCH ([a-zA-Z0-9_]+)" ARCH "${ARCH}") + + # Get rid of the value marker leaving just the architecture name + string(REPLACE "cmake_ARCH " "" ARCH "${ARCH}") + + # If we are compiling with an unknown architecture this variable should + # already be set to "unknown" but in the case that it's empty (i.e. due + # to a typo in the code), then set it to unknown + if (NOT ARCH) + set(ARCH unknown) + endif() + endif() + + set(${output_var} "${ARCH}" PARENT_SCOPE) +endfunction() diff --git a/cmake/Utils.cmake b/cmake/Utils.cmake new file mode 100644 index 00000000..0abf5155 --- /dev/null +++ b/cmake/Utils.cmake @@ -0,0 +1,13 @@ + +# Installing headers and preserving the directory structure +# Found here: http://www.semipol.de/archives/251 +MACRO(INSTALL_HEADERS_WITH_DIRECTORY HEADER_LIST COMPONENT_NAME) + + FOREACH(HEADER ${${HEADER_LIST}}) + STRING(REGEX MATCH "(.*)[/\\]" DIR ${HEADER}) + STRING(REPLACE "${CMAKE_SOURCE_DIR}/" "" DIR ${DIR}) + INSTALL(FILES ${HEADER} DESTINATION include/${DIR} COMPONENT ${COMPONENT_NAME}) + ENDFOREACH(HEADER) + +ENDMACRO(INSTALL_HEADERS_WITH_DIRECTORY) + diff --git a/cmake/config.hpp.cmake b/cmake/config.hpp.cmake new file mode 100644 index 00000000..66c26b6c --- /dev/null +++ b/cmake/config.hpp.cmake @@ -0,0 +1,66 @@ +// +// This file was automatically generated by CMake. +// + +#ifndef VMIME_CONFIG_HPP_INCLUDED +#define VMIME_CONFIG_HPP_INCLUDED + + +// Name of package +#define VMIME_PACKAGE "@PROJECT_NAME@" + +// Version number of package +#define VMIME_VERSION "@VMIME_VERSION@" +#define VMIME_API "@VMIME_API_VERSION@" + +// Target OS and architecture +#define VMIME_TARGET_ARCH "@CMAKE_TARGET_ARCHITECTURES@" +#define VMIME_TARGET_OS "@CMAKE_SYSTEM_NAME@" + +// Set to 1 if debugging should be activated +#define VMIME_DEBUG @VMIME_DEBUG@ + +// Byte order (set one or the other, but not both!) +#define VMIME_BYTE_ORDER_BIG_ENDIAN @VMIME_BYTE_ORDER_BIG_ENDIAN@ +#define VMIME_BYTE_ORDER_LITTLE_ENDIAN @VMIME_BYTE_ORDER_LITTLE_ENDIAN@ + +// Generic types +// -- 8-bit +typedef signed @VMIME_8BIT_TYPE@ vmime_int8; +typedef unsigned @VMIME_8BIT_TYPE@ vmime_uint8; +// -- 16-bit +typedef signed @VMIME_16BIT_TYPE@ vmime_int16; +typedef unsigned @VMIME_16BIT_TYPE@ vmime_uint16; +// -- 32-bit +typedef signed @VMIME_32BIT_TYPE@ vmime_int32; +typedef unsigned @VMIME_32BIT_TYPE@ vmime_uint32; + +// Options +// -- File-system support +#cmakedefine01 VMIME_HAVE_FILESYSTEM_FEATURES +// -- SASL support +#cmakedefine01 VMIME_HAVE_SASL_SUPPORT +// -- TLS/SSL support +#cmakedefine01 VMIME_HAVE_TLS_SUPPORT +#cmakedefine01 VMIME_TLS_SUPPORT_LIB_IS_GNUTLS +#define VMIME_HAVE_GNUTLS_PRIORITY_FUNCS @VMIME_HAVE_GNUTLS_PRIORITY_FUNCS@ +// -- Messaging support +#cmakedefine01 VMIME_HAVE_MESSAGING_FEATURES +// -- Messaging protocols +#cmakedefine01 VMIME_HAVE_MESSAGING_PROTO_POP3 +#cmakedefine01 VMIME_HAVE_MESSAGING_PROTO_SMTP +#cmakedefine01 VMIME_HAVE_MESSAGING_PROTO_IMAP +#cmakedefine01 VMIME_HAVE_MESSAGING_PROTO_MAILDIR +#cmakedefine01 VMIME_HAVE_MESSAGING_PROTO_SENDMAIL +// -- Platform-specific code +#cmakedefine01 VMIME_PLATFORM_IS_POSIX +#cmakedefine01 VMIME_PLATFORM_IS_WINDOWS +#cmakedefine01 VMIME_HAVE_PTHREAD +#cmakedefine01 VMIME_HAVE_GETADDRINFO + + +#define VMIME_SENDMAIL_PATH "@VMIME_SENDMAIL_PATH@" + + +#endif // VMIME_CONFIG_HPP_INCLUDED + |