From 51f1db74312c4a9718dad77d2787d0ca22cce032 Mon Sep 17 00:00:00 2001 From: Andreas Schuh Date: Tue, 24 Mar 2015 15:36:26 +0000 Subject: [PATCH] #101 Enable C language again as long as FindThreads requires it This avoids having patched CMake modules in the source tree of the gflags library. Usually a C compiler is installed along a C++ compiler (or it is used for C as well). The only slight downside is the extra configuration time needed by CMake to check the C compiler. --- CMakeLists.txt | 10 +- cmake/CMakeCXXInformation.cmake | 300 -------------------------------------- cmake/CheckCXXLibraryExists.cmake | 80 ---------- cmake/CheckForPthreads.cxx | 38 ----- cmake/CheckTypeSize.c.in | 37 ----- cmake/CheckTypeSize.cmake | 268 ---------------------------------- cmake/CheckTypeSizeMap.cmake.in | 1 - cmake/FindThreadsCXX.cmake | 181 ----------------------- 8 files changed, 9 insertions(+), 906 deletions(-) delete mode 100644 cmake/CMakeCXXInformation.cmake delete mode 100644 cmake/CheckCXXLibraryExists.cmake delete mode 100644 cmake/CheckForPthreads.cxx delete mode 100644 cmake/CheckTypeSize.c.in delete mode 100644 cmake/CheckTypeSize.cmake delete mode 100644 cmake/CheckTypeSizeMap.cmake.in delete mode 100644 cmake/FindThreadsCXX.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 1272770..275426d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,14 @@ set (PACKAGE_TARNAME "${PACKAGE_NAME}-${PACKAGE_VERSION}") set (PACKAGE_BUGREPORT "https://github.com/schuhschuh/gflags/issues") project (${PACKAGE_NAME} CXX) +if (CMAKE_VERSION VERSION_LESS 100) + # C language still needed because the following required CMake modules + # (or their dependencies, respectively) are not correctly handling + # the case where only CXX is enabled. + # - CheckTypeSize.cmake (fixed in CMake 3.1, cf. http://www.cmake.org/Bug/view.php?id=14056) + # - FindThreads.cmake (--> CheckIncludeFiles.cmake <--) + enable_language (C) +endif () version_numbers ( ${PACKAGE_VERSION} @@ -179,7 +187,7 @@ else () endif () set (CMAKE_THREAD_PREFER_PTHREAD TRUE) -find_package (ThreadsCXX) +find_package (Threads) if (Threads_FOUND AND CMAKE_USE_PTHREADS_INIT) set (HAVE_PTHREAD 1) check_type_size (pthread_rwlock_t RWLOCK LANGUAGE CXX) diff --git a/cmake/CMakeCXXInformation.cmake b/cmake/CMakeCXXInformation.cmake deleted file mode 100644 index 9ddae4a..0000000 --- a/cmake/CMakeCXXInformation.cmake +++ /dev/null @@ -1,300 +0,0 @@ -# Copied from master branch of CMake (commit SHA 34a49dea) before release of -# this newer version which seems to fix a bug of the one coming with CMake 2.8-12. - -#============================================================================= -# Copyright 2004-2011 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -# This file sets the basic flags for the C++ language in CMake. -# It also loads the available platform file for the system-compiler -# if it exists. -# It also loads a system - compiler - processor (or target hardware) -# specific file, which is mainly useful for crosscompiling and embedded systems. - -# some compilers use different extensions (e.g. sdcc uses .rel) -# so set the extension here first so it can be overridden by the compiler specific file -if(UNIX) - set(CMAKE_CXX_OUTPUT_EXTENSION .o) -else() - set(CMAKE_CXX_OUTPUT_EXTENSION .obj) -endif() - -set(_INCLUDED_FILE 0) - -# Load compiler-specific information. -if(CMAKE_CXX_COMPILER_ID) - include(Compiler/${CMAKE_CXX_COMPILER_ID}-CXX OPTIONAL) -endif() - -set(CMAKE_BASE_NAME) -get_filename_component(CMAKE_BASE_NAME "${CMAKE_CXX_COMPILER}" NAME_WE) -# since the gnu compiler has several names force g++ -if(CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_BASE_NAME g++) -endif() - - -# load a hardware specific file, mostly useful for embedded compilers -if(CMAKE_SYSTEM_PROCESSOR) - if(CMAKE_CXX_COMPILER_ID) - include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_CXX_COMPILER_ID}-CXX-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL RESULT_VARIABLE _INCLUDED_FILE) - endif() - if (NOT _INCLUDED_FILE) - include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL) - endif () -endif() - -# load the system- and compiler specific files -if(CMAKE_CXX_COMPILER_ID) - include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_CXX_COMPILER_ID}-CXX OPTIONAL RESULT_VARIABLE _INCLUDED_FILE) -endif() -if (NOT _INCLUDED_FILE) - include(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL - RESULT_VARIABLE _INCLUDED_FILE) -endif () -# We specify the compiler information in the system file for some -# platforms, but this language may not have been enabled when the file -# was first included. Include it again to get the language info. -# Remove this when all compiler info is removed from system files. -if (NOT _INCLUDED_FILE) - include(Platform/${CMAKE_SYSTEM_NAME} OPTIONAL) -endif () - -if(CMAKE_CXX_SIZEOF_DATA_PTR) - foreach(f ${CMAKE_CXX_ABI_FILES}) - include(${f}) - endforeach() - unset(CMAKE_CXX_ABI_FILES) -endif() - -# This should be included before the _INIT variables are -# used to initialize the cache. Since the rule variables -# have if blocks on them, users can still define them here. -# But, it should still be after the platform file so changes can -# be made to those values. - -if(CMAKE_USER_MAKE_RULES_OVERRIDE) - # Save the full path of the file so try_compile can use it. - include(${CMAKE_USER_MAKE_RULES_OVERRIDE} RESULT_VARIABLE _override) - set(CMAKE_USER_MAKE_RULES_OVERRIDE "${_override}") -endif() - -if(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX) - # Save the full path of the file so try_compile can use it. - include(${CMAKE_USER_MAKE_RULES_OVERRIDE_CXX} RESULT_VARIABLE _override) - set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX "${_override}") -endif() - - -# Create a set of shared library variable specific to C++ -# For 90% of the systems, these are the same flags as the C versions -# so if these are not set just copy the flags from the c version -if(NOT CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS) - set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS}) -endif() - -if(NOT CMAKE_CXX_COMPILE_OPTIONS_PIC) - set(CMAKE_CXX_COMPILE_OPTIONS_PIC ${CMAKE_C_COMPILE_OPTIONS_PIC}) -endif() - -if(NOT CMAKE_CXX_COMPILE_OPTIONS_PIE) - set(CMAKE_CXX_COMPILE_OPTIONS_PIE ${CMAKE_C_COMPILE_OPTIONS_PIE}) -endif() - -if(NOT CMAKE_CXX_COMPILE_OPTIONS_DLL) - set(CMAKE_CXX_COMPILE_OPTIONS_DLL ${CMAKE_C_COMPILE_OPTIONS_DLL}) -endif() - -if(NOT CMAKE_SHARED_LIBRARY_CXX_FLAGS) - set(CMAKE_SHARED_LIBRARY_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS}) -endif() - -if(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS) - set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS}) -endif() - -if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG) - set(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG}) -endif() - -if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP) - set(CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP}) -endif() - -if(NOT CMAKE_SHARED_LIBRARY_RPATH_LINK_CXX_FLAG) - set(CMAKE_SHARED_LIBRARY_RPATH_LINK_CXX_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG}) -endif() - -if(NOT DEFINED CMAKE_EXE_EXPORTS_CXX_FLAG) - set(CMAKE_EXE_EXPORTS_CXX_FLAG ${CMAKE_EXE_EXPORTS_C_FLAG}) -endif() - -if(NOT DEFINED CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG) - set(CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG ${CMAKE_SHARED_LIBRARY_SONAME_C_FLAG}) -endif() - -if(NOT CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG) - set(CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG}) -endif() - -if(NOT CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG_SEP) - set(CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_CXX_FLAG_SEP}) -endif() - -if(NOT CMAKE_EXECUTABLE_RPATH_LINK_CXX_FLAG) - set(CMAKE_EXECUTABLE_RPATH_LINK_CXX_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_CXX_FLAG}) -endif() - -if(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_CXX_WITH_RUNTIME_PATH) - set(CMAKE_SHARED_LIBRARY_LINK_CXX_WITH_RUNTIME_PATH ${CMAKE_SHARED_LIBRARY_LINK_C_WITH_RUNTIME_PATH}) -endif() - -if(NOT CMAKE_INCLUDE_FLAG_CXX) - set(CMAKE_INCLUDE_FLAG_CXX ${CMAKE_INCLUDE_FLAG_C}) -endif() - -if(NOT CMAKE_INCLUDE_FLAG_SEP_CXX) - set(CMAKE_INCLUDE_FLAG_SEP_CXX ${CMAKE_INCLUDE_FLAG_SEP_C}) -endif() - -# for most systems a module is the same as a shared library -# so unless the variable CMAKE_MODULE_EXISTS is set just -# copy the values from the LIBRARY variables -if(NOT CMAKE_MODULE_EXISTS) - set(CMAKE_SHARED_MODULE_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) - set(CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS}) -endif() - -# repeat for modules -if(NOT CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS) - set(CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS ${CMAKE_SHARED_MODULE_CREATE_C_FLAGS}) -endif() - -if(NOT CMAKE_SHARED_MODULE_CXX_FLAGS) - set(CMAKE_SHARED_MODULE_CXX_FLAGS ${CMAKE_SHARED_MODULE_C_FLAGS}) -endif() - -# Initialize CXX link type selection flags from C versions. -foreach(type SHARED_LIBRARY SHARED_MODULE EXE) - if(NOT CMAKE_${type}_LINK_STATIC_CXX_FLAGS) - set(CMAKE_${type}_LINK_STATIC_CXX_FLAGS - ${CMAKE_${type}_LINK_STATIC_C_FLAGS}) - endif() - if(NOT CMAKE_${type}_LINK_DYNAMIC_CXX_FLAGS) - set(CMAKE_${type}_LINK_DYNAMIC_CXX_FLAGS - ${CMAKE_${type}_LINK_DYNAMIC_C_FLAGS}) - endif() -endforeach() - -# add the flags to the cache based -# on the initial values computed in the platform/*.cmake files -# use _INIT variables so that this only happens the first time -# and you can set these flags in the cmake cache -set(CMAKE_CXX_FLAGS_INIT "$ENV{CXXFLAGS} ${CMAKE_CXX_FLAGS_INIT}") -# avoid just having a space as the initial value for the cache -if(CMAKE_CXX_FLAGS_INIT STREQUAL " ") - set(CMAKE_CXX_FLAGS_INIT) -endif() -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT}" CACHE STRING - "Flags used by the compiler during all build types.") - -if(NOT CMAKE_NOT_USING_CONFIG_FLAGS) - set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG_INIT}" CACHE STRING - "Flags used by the compiler during debug builds.") - set (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL_INIT}" CACHE STRING - "Flags used by the compiler during release builds for minimum size.") - set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE_INIT}" CACHE STRING - "Flags used by the compiler during release builds.") - set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING - "Flags used by the compiler during release builds with debug info.") - -endif() - -if(CMAKE_CXX_STANDARD_LIBRARIES_INIT) - set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES_INIT}" - CACHE STRING "Libraries linked by default with all C++ applications.") - mark_as_advanced(CMAKE_CXX_STANDARD_LIBRARIES) -endif() - -include(CMakeCommonLanguageInclude) - -# now define the following rules: -# CMAKE_CXX_CREATE_SHARED_LIBRARY -# CMAKE_CXX_CREATE_SHARED_MODULE -# CMAKE_CXX_COMPILE_OBJECT -# CMAKE_CXX_LINK_EXECUTABLE - -# variables supplied by the generator at use time -# -# the target without the suffix -# -# -# -# -# - -# CXX compiler information -# -# -# -# - -# Static library tools -# -# - - -# create a shared C++ library -if(NOT CMAKE_CXX_CREATE_SHARED_LIBRARY) - set(CMAKE_CXX_CREATE_SHARED_LIBRARY - " -o ") -endif() - -# create a c++ shared module copy the shared library rule by default -if(NOT CMAKE_CXX_CREATE_SHARED_MODULE) - set(CMAKE_CXX_CREATE_SHARED_MODULE ${CMAKE_CXX_CREATE_SHARED_LIBRARY}) -endif() - - -# Create a static archive incrementally for large object file counts. -# If CMAKE_CXX_CREATE_STATIC_LIBRARY is set it will override these. -if(NOT DEFINED CMAKE_CXX_ARCHIVE_CREATE) - set(CMAKE_CXX_ARCHIVE_CREATE " cr ") -endif() -if(NOT DEFINED CMAKE_CXX_ARCHIVE_APPEND) - set(CMAKE_CXX_ARCHIVE_APPEND " r ") -endif() -if(NOT DEFINED CMAKE_CXX_ARCHIVE_FINISH) - set(CMAKE_CXX_ARCHIVE_FINISH " ") -endif() - -# compile a C++ file into an object file -if(NOT CMAKE_CXX_COMPILE_OBJECT) - set(CMAKE_CXX_COMPILE_OBJECT - " -o -c ") -endif() - -if(NOT CMAKE_CXX_LINK_EXECUTABLE) - set(CMAKE_CXX_LINK_EXECUTABLE - " -o ") -endif() - -mark_as_advanced( -CMAKE_VERBOSE_MAKEFILE -CMAKE_CXX_FLAGS -CMAKE_CXX_FLAGS_RELEASE -CMAKE_CXX_FLAGS_RELWITHDEBINFO -CMAKE_CXX_FLAGS_MINSIZEREL -CMAKE_CXX_FLAGS_DEBUG) - -set(CMAKE_CXX_INFORMATION_LOADED 1) - diff --git a/cmake/CheckCXXLibraryExists.cmake b/cmake/CheckCXXLibraryExists.cmake deleted file mode 100644 index 0d1747d..0000000 --- a/cmake/CheckCXXLibraryExists.cmake +++ /dev/null @@ -1,80 +0,0 @@ -#.rst: -# CheckLibraryExists -# ------------------ -# -# Check if the function exists. -# -# CHECK_LIBRARY_EXISTS (LIBRARY FUNCTION LOCATION VARIABLE) -# -# :: -# -# LIBRARY - the name of the library you are looking for -# FUNCTION - the name of the function -# LOCATION - location where the library should be found -# VARIABLE - variable to store the result -# -# -# -# The following variables may be set before calling this macro to modify -# the way the check is run: -# -# :: -# -# CMAKE_REQUIRED_FLAGS = string of compile command line flags -# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) -# CMAKE_REQUIRED_LIBRARIES = list of libraries to link - -#============================================================================= -# Copyright 2002-2009 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - - - -macro(CHECK_CXX_LIBRARY_EXISTS LIBRARY FUNCTION LOCATION VARIABLE) - if("${VARIABLE}" MATCHES "^${VARIABLE}$") - set(MACRO_CHECK_LIBRARY_EXISTS_DEFINITION - "-DCHECK_FUNCTION_EXISTS=${FUNCTION} ${CMAKE_REQUIRED_FLAGS}") - message(STATUS "Looking for ${FUNCTION} in ${LIBRARY}") - set(CHECK_LIBRARY_EXISTS_LIBRARIES ${LIBRARY}) - if(CMAKE_REQUIRED_LIBRARIES) - set(CHECK_LIBRARY_EXISTS_LIBRARIES - ${CHECK_LIBRARY_EXISTS_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES}) - endif() - configure_file(${CMAKE_ROOT}/Modules/CheckFunctionExists.c - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckFunctionExists.cxx COPYONLY) - try_compile(${VARIABLE} - ${CMAKE_BINARY_DIR} - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckFunctionExists.cxx - COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} - LINK_LIBRARIES ${CHECK_LIBRARY_EXISTS_LIBRARIES} - CMAKE_FLAGS - -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION} - -DLINK_DIRECTORIES:STRING=${LOCATION} - OUTPUT_VARIABLE OUTPUT) - - if(${VARIABLE}) - message(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - found") - set(${VARIABLE} 1 CACHE INTERNAL "Have library ${LIBRARY}") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Determining if the function ${FUNCTION} exists in the ${LIBRARY} " - "passed with the following output:\n" - "${OUTPUT}\n\n") - else() - message(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - not found") - set(${VARIABLE} "" CACHE INTERNAL "Have library ${LIBRARY}") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Determining if the function ${FUNCTION} exists in the ${LIBRARY} " - "failed with the following output:\n" - "${OUTPUT}\n\n") - endif() - endif() -endmacro() diff --git a/cmake/CheckForPthreads.cxx b/cmake/CheckForPthreads.cxx deleted file mode 100644 index 2732957..0000000 --- a/cmake/CheckForPthreads.cxx +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include -#include - -void* runner(void*); - -int res = 0; -#ifdef __CLASSIC_C__ -int main(){ - int ac; - char*av[]; -#else -int main(int ac, char*av[]){ -#endif - pthread_t tid[2]; - pthread_create(&tid[0], 0, runner, (void*)1); - pthread_create(&tid[1], 0, runner, (void*)2); - -#if defined(__BEOS__) && !defined(__ZETA__) // (no usleep on BeOS 5.) - usleep(1); // for strange behavior on single-processor sun -#endif - - pthread_join(tid[0], 0); - pthread_join(tid[1], 0); - if(ac > 1000){return *av[0];} - return res; -} - -void* runner(void* args) -{ - int cc; - for ( cc = 0; cc < 10; cc ++ ) - { - printf("%p CC: %d\n", args, cc); - } - res ++; - return 0; -} diff --git a/cmake/CheckTypeSize.c.in b/cmake/CheckTypeSize.c.in deleted file mode 100644 index b6c3688..0000000 --- a/cmake/CheckTypeSize.c.in +++ /dev/null @@ -1,37 +0,0 @@ -@headers@ - -#undef KEY -#if defined(__i386) -# define KEY '_','_','i','3','8','6' -#elif defined(__x86_64) -# define KEY '_','_','x','8','6','_','6','4' -#elif defined(__ppc__) -# define KEY '_','_','p','p','c','_','_' -#elif defined(__ppc64__) -# define KEY '_','_','p','p','c','6','4','_','_' -#endif - -#define SIZE (sizeof(@type@)) -char info_size[] = {'I', 'N', 'F', 'O', ':', 's','i','z','e','[', - ('0' + ((SIZE / 10000)%10)), - ('0' + ((SIZE / 1000)%10)), - ('0' + ((SIZE / 100)%10)), - ('0' + ((SIZE / 10)%10)), - ('0' + (SIZE % 10)), - ']', -#ifdef KEY - ' ','k','e','y','[', KEY, ']', -#endif - '\0'}; - -#ifdef __CLASSIC_C__ -int main(argc, argv) int argc; char *argv[]; -#else -int main(int argc, char *argv[]) -#endif -{ - int require = 0; - require += info_size[argc]; - (void)argv; - return require; -} diff --git a/cmake/CheckTypeSize.cmake b/cmake/CheckTypeSize.cmake deleted file mode 100644 index a437670..0000000 --- a/cmake/CheckTypeSize.cmake +++ /dev/null @@ -1,268 +0,0 @@ -# Copied from master branch of CMake (commit SHA 34a49dea) and -# modified to use CheckIncludeFileCXX instead of CheckIncludeFile -# when the LANGUAGE is CXX. Modified the try_compile call to -# not pass any LINK_LIBRARIES as this option is only supported by -# CMake since version 2.8.11 -# -andreas - -#.rst: -# CheckTypeSize -# ------------- -# -# Check sizeof a type -# -# :: -# -# CHECK_TYPE_SIZE(TYPE VARIABLE [BUILTIN_TYPES_ONLY] -# [LANGUAGE ]) -# -# Check if the type exists and determine its size. On return, -# "HAVE_${VARIABLE}" holds the existence of the type, and "${VARIABLE}" -# holds one of the following: -# -# :: -# -# = type has non-zero size -# "0" = type has arch-dependent size (see below) -# "" = type does not exist -# -# Furthermore, the variable "${VARIABLE}_CODE" holds C preprocessor code -# to define the macro "${VARIABLE}" to the size of the type, or leave -# the macro undefined if the type does not exist. -# -# The variable "${VARIABLE}" may be "0" when CMAKE_OSX_ARCHITECTURES has -# multiple architectures for building OS X universal binaries. This -# indicates that the type size varies across architectures. In this -# case "${VARIABLE}_CODE" contains C preprocessor tests mapping from -# each architecture macro to the corresponding type size. The list of -# architecture macros is stored in "${VARIABLE}_KEYS", and the value for -# each key is stored in "${VARIABLE}-${KEY}". -# -# If the BUILTIN_TYPES_ONLY option is not given, the macro checks for -# headers , , and , and saves results -# in HAVE_SYS_TYPES_H, HAVE_STDINT_H, and HAVE_STDDEF_H. The type size -# check automatically includes the available headers, thus supporting -# checks of types defined in the headers. -# -# If LANGUAGE is set, the specified compiler will be used to perform the -# check. Acceptable values are C and CXX -# -# Despite the name of the macro you may use it to check the size of more -# complex expressions, too. To check e.g. for the size of a struct -# member you can do something like this: -# -# :: -# -# check_type_size("((struct something*)0)->member" SIZEOF_MEMBER) -# -# -# -# The following variables may be set before calling this macro to modify -# the way the check is run: -# -# :: -# -# CMAKE_REQUIRED_FLAGS = string of compile command line flags -# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) -# CMAKE_REQUIRED_INCLUDES = list of include directories -# CMAKE_EXTRA_INCLUDE_FILES = list of extra headers to include - -#============================================================================= -# Copyright 2002-2009 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -include(CheckIncludeFile) -include(CheckIncludeFileCXX) - -cmake_policy(PUSH) -cmake_minimum_required(VERSION 2.6 FATAL_ERROR) - -get_filename_component(__check_type_size_dir "${CMAKE_CURRENT_LIST_FILE}" PATH) - -#----------------------------------------------------------------------------- -# Helper function. DO NOT CALL DIRECTLY. -function(__check_type_size_impl type var map builtin language) - message(STATUS "Check size of ${type}") - - # Include header files. - set(headers) - if(builtin) - if(HAVE_SYS_TYPES_H) - set(headers "${headers}#include \n") - endif() - if(HAVE_STDINT_H) - set(headers "${headers}#include \n") - endif() - if(HAVE_STDDEF_H) - set(headers "${headers}#include \n") - endif() - endif() - foreach(h ${CMAKE_EXTRA_INCLUDE_FILES}) - set(headers "${headers}#include \"${h}\"\n") - endforeach() - - # Perform the check. - - if("${language}" STREQUAL "C") - set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.c) - elseif("${language}" STREQUAL "CXX") - set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.cpp) - else() - message(FATAL_ERROR "Unknown language:\n ${language}\nSupported languages: C, CXX.\n") - endif() - set(bin ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.bin) - configure_file(${__check_type_size_dir}/CheckTypeSize.c.in ${src} @ONLY) - try_compile(HAVE_${var} ${CMAKE_BINARY_DIR} ${src} - COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} - CMAKE_FLAGS - "-DCOMPILE_DEFINITIONS:STRING=${CMAKE_REQUIRED_FLAGS}" - "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}" - OUTPUT_VARIABLE output - COPY_FILE ${bin} - ) - - if(HAVE_${var}) - # The check compiled. Load information from the binary. - file(STRINGS ${bin} strings LIMIT_COUNT 10 REGEX "INFO:size") - - # Parse the information strings. - set(regex_size ".*INFO:size\\[0*([^]]*)\\].*") - set(regex_key " key\\[([^]]*)\\]") - set(keys) - set(code) - set(mismatch) - set(first 1) - foreach(info ${strings}) - if("${info}" MATCHES "${regex_size}") - # Get the type size. - string(REGEX REPLACE "${regex_size}" "\\1" size "${info}") - if(first) - set(${var} ${size}) - elseif(NOT "${size}" STREQUAL "${${var}}") - set(mismatch 1) - endif() - set(first 0) - - # Get the architecture map key. - string(REGEX MATCH "${regex_key}" key "${info}") - string(REGEX REPLACE "${regex_key}" "\\1" key "${key}") - if(key) - set(code "${code}\nset(${var}-${key} \"${size}\")") - list(APPEND keys ${key}) - endif() - endif() - endforeach() - - # Update the architecture-to-size map. - if(mismatch AND keys) - configure_file(${__check_type_size_dir}/CheckTypeSizeMap.cmake.in ${map} @ONLY) - set(${var} 0) - else() - file(REMOVE ${map}) - endif() - - if(mismatch AND NOT keys) - message(SEND_ERROR "CHECK_TYPE_SIZE found different results, consider setting CMAKE_OSX_ARCHITECTURES or CMAKE_TRY_COMPILE_OSX_ARCHITECTURES to one or no architecture !") - endif() - - message(STATUS "Check size of ${type} - done") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Determining size of ${type} passed with the following output:\n${output}\n\n") - set(${var} "${${var}}" CACHE INTERNAL "CHECK_TYPE_SIZE: sizeof(${type})") - else() - # The check failed to compile. - message(STATUS "Check size of ${type} - failed") - file(READ ${src} content) - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Determining size of ${type} failed with the following output:\n${output}\n${src}:\n${content}\n\n") - set(${var} "" CACHE INTERNAL "CHECK_TYPE_SIZE: ${type} unknown") - file(REMOVE ${map}) - endif() -endfunction() - -#----------------------------------------------------------------------------- -macro(CHECK_TYPE_SIZE TYPE VARIABLE) - # parse arguments - unset(doing) - foreach(arg ${ARGN}) - if("x${arg}" STREQUAL "xBUILTIN_TYPES_ONLY") - set(_CHECK_TYPE_SIZE_${arg} 1) - unset(doing) - elseif("x${arg}" STREQUAL "xLANGUAGE") # change to MATCHES for more keys - set(doing "${arg}") - set(_CHECK_TYPE_SIZE_${doing} "") - elseif("x${doing}" STREQUAL "xLANGUAGE") - set(_CHECK_TYPE_SIZE_${doing} "${arg}") - unset(doing) - else() - message(FATAL_ERROR "Unknown argument:\n ${arg}\n") - endif() - endforeach() - if("x${doing}" MATCHES "^x(LANGUAGE)$") - message(FATAL_ERROR "Missing argument:\n ${doing} arguments requires a value\n") - endif() - if(DEFINED _CHECK_TYPE_SIZE_LANGUAGE) - if(NOT "x${_CHECK_TYPE_SIZE_LANGUAGE}" MATCHES "^x(C|CXX)$") - message(FATAL_ERROR "Unknown language:\n ${_CHECK_TYPE_SIZE_LANGUAGE}.\nSupported languages: C, CXX.\n") - endif() - set(_language ${_CHECK_TYPE_SIZE_LANGUAGE}) - else() - set(_language C) - endif() - - # Optionally check for standard headers. - if(_CHECK_TYPE_SIZE_BUILTIN_TYPES_ONLY) - set(_builtin 0) - else() - set(_builtin 1) - if ("x${_CHECK_TYPE_SIZE_LANGUAGE}" STREQUAL "xCXX") - check_include_file_cxx(sys/types.h HAVE_SYS_TYPES_H) - check_include_file_cxx(stdint.h HAVE_STDINT_H) - check_include_file_cxx(stddef.h HAVE_STDDEF_H) - else () - check_include_file(sys/types.h HAVE_SYS_TYPES_H) - check_include_file(stdint.h HAVE_STDINT_H) - check_include_file(stddef.h HAVE_STDDEF_H) - endif () - endif() - unset(_CHECK_TYPE_SIZE_BUILTIN_TYPES_ONLY) - unset(_CHECK_TYPE_SIZE_LANGUAGE) - - # Compute or load the size or size map. - set(${VARIABLE}_KEYS) - set(_map_file ${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${VARIABLE}.cmake) - if(NOT DEFINED HAVE_${VARIABLE}) - __check_type_size_impl(${TYPE} ${VARIABLE} ${_map_file} ${_builtin} ${_language}) - endif() - include(${_map_file} OPTIONAL) - set(_map_file) - set(_builtin) - - # Create preprocessor code. - if(${VARIABLE}_KEYS) - set(${VARIABLE}_CODE) - set(_if if) - foreach(key ${${VARIABLE}_KEYS}) - set(${VARIABLE}_CODE "${${VARIABLE}_CODE}#${_if} defined(${key})\n# define ${VARIABLE} ${${VARIABLE}-${key}}\n") - set(_if elif) - endforeach() - set(${VARIABLE}_CODE "${${VARIABLE}_CODE}#else\n# error ${VARIABLE} unknown\n#endif") - set(_if) - elseif(${VARIABLE}) - set(${VARIABLE}_CODE "#define ${VARIABLE} ${${VARIABLE}}") - else() - set(${VARIABLE}_CODE "/* #undef ${VARIABLE} */") - endif() -endmacro() - -#----------------------------------------------------------------------------- -cmake_policy(POP) diff --git a/cmake/CheckTypeSizeMap.cmake.in b/cmake/CheckTypeSizeMap.cmake.in deleted file mode 100644 index 1e73cff..0000000 --- a/cmake/CheckTypeSizeMap.cmake.in +++ /dev/null @@ -1 +0,0 @@ -set(@var@_KEYS "@keys@")@code@ diff --git a/cmake/FindThreadsCXX.cmake b/cmake/FindThreadsCXX.cmake deleted file mode 100644 index 91c795c..0000000 --- a/cmake/FindThreadsCXX.cmake +++ /dev/null @@ -1,181 +0,0 @@ -#.rst: -# FindThreads -# ----------- -# -# This module determines the thread library of the system. -# -# The following variables are set -# -# :: -# -# CMAKE_THREAD_LIBS_INIT - the thread library -# CMAKE_USE_SPROC_INIT - are we using sproc? -# CMAKE_USE_WIN32_THREADS_INIT - using WIN32 threads? -# CMAKE_USE_PTHREADS_INIT - are we using pthreads -# CMAKE_HP_PTHREADS_INIT - are we using hp pthreads -# -# For systems with multiple thread libraries, caller can set -# -# :: -# -# CMAKE_THREAD_PREFER_PTHREAD - -#============================================================================= -# Copyright 2002-2009 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -include (CheckIncludeFileCXX) -include (CheckCXXLibraryExists) -include (CheckCXXSymbolExists) -set(Threads_FOUND FALSE) - - -# Do we have sproc? -if(CMAKE_SYSTEM MATCHES IRIX AND NOT CMAKE_THREAD_PREFER_PTHREAD) - CHECK_INCLUDE_FILES_CXX("sys/types.h;sys/prctl.h" CMAKE_HAVE_SPROC_H) -endif() - -if(CMAKE_HAVE_SPROC_H AND NOT CMAKE_THREAD_PREFER_PTHREAD) - # We have sproc - set(CMAKE_USE_SPROC_INIT 1) -else() - # Do we have pthreads? - CHECK_INCLUDE_FILE_CXX("pthread.h" CMAKE_HAVE_PTHREAD_H) - if(CMAKE_HAVE_PTHREAD_H) - - # - # We have pthread.h - # Let's check for the library now. - # - set(CMAKE_HAVE_THREADS_LIBRARY) - if(NOT THREADS_HAVE_PTHREAD_ARG) - # Check if pthread functions are in normal C library - CHECK_CXX_SYMBOL_EXISTS(pthread_create pthread.h CMAKE_HAVE_LIBC_CREATE) - if(CMAKE_HAVE_LIBC_CREATE) - set(CMAKE_THREAD_LIBS_INIT "") - set(CMAKE_HAVE_THREADS_LIBRARY 1) - set(Threads_FOUND TRUE) - endif() - - if(NOT CMAKE_HAVE_THREADS_LIBRARY) - # Do we have -lpthreads - CHECK_CXX_LIBRARY_EXISTS(pthreads pthread_create "" CMAKE_HAVE_PTHREADS_CREATE) - if(CMAKE_HAVE_PTHREADS_CREATE) - set(CMAKE_THREAD_LIBS_INIT "-lpthreads") - set(CMAKE_HAVE_THREADS_LIBRARY 1) - set(Threads_FOUND TRUE) - endif() - - # Ok, how about -lpthread - CHECK_CXX_LIBRARY_EXISTS(pthread pthread_create "" CMAKE_HAVE_PTHREAD_CREATE) - if(CMAKE_HAVE_PTHREAD_CREATE) - set(CMAKE_THREAD_LIBS_INIT "-lpthread") - set(CMAKE_HAVE_THREADS_LIBRARY 1) - set(Threads_FOUND TRUE) - endif() - - if(CMAKE_SYSTEM MATCHES "SunOS.*") - # On sun also check for -lthread - CHECK_CXX_LIBRARY_EXISTS(thread thr_create "" CMAKE_HAVE_THR_CREATE) - if(CMAKE_HAVE_THR_CREATE) - set(CMAKE_THREAD_LIBS_INIT "-lthread") - set(CMAKE_HAVE_THREADS_LIBRARY 1) - set(Threads_FOUND TRUE) - endif() - endif() - endif() - endif() - - if(NOT CMAKE_HAVE_THREADS_LIBRARY) - # If we did not found -lpthread, -lpthreads, or -lthread, look for -pthread - if("THREADS_HAVE_PTHREAD_ARG" MATCHES "^THREADS_HAVE_PTHREAD_ARG") - message(STATUS "Check if compiler accepts -pthread") - configure_file ("${CMAKE_CURRENT_LIST_DIR}/CheckForPthreads.cxx" - "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckForPthreads.cxx" COPYONLY) - try_run(THREADS_PTHREAD_ARG THREADS_HAVE_PTHREAD_ARG - ${CMAKE_BINARY_DIR} - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckForPthreads.cxx - CMAKE_FLAGS "-DLINK_LIBRARIES:STRING=-pthread;-DCMAKE_CXX_FLAGS:STRING=-fpermissive" - COMPILE_OUTPUT_VARIABLE OUTPUT) - - if(THREADS_HAVE_PTHREAD_ARG) - if(THREADS_PTHREAD_ARG STREQUAL "2") - set(Threads_FOUND TRUE) - message(STATUS "Check if compiler accepts -pthread - yes") - else() - message(STATUS "Check if compiler accepts -pthread - no") - file(APPEND - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Determining if compiler accepts -pthread returned ${THREADS_PTHREAD_ARG} instead of 2. The compiler had the following output:\n${OUTPUT}\n\n") - endif() - else() - message(STATUS "Check if compiler accepts -pthread - no") - file(APPEND - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Determining if compiler accepts -pthread failed with the following output:\n${OUTPUT}\n\n") - endif() - - endif() - - if(THREADS_HAVE_PTHREAD_ARG) - set(Threads_FOUND TRUE) - set(CMAKE_THREAD_LIBS_INIT "-pthread") - endif() - - endif() - endif() -endif() - -if(CMAKE_THREAD_LIBS_INIT OR CMAKE_HAVE_LIBC_CREATE) - set(CMAKE_USE_PTHREADS_INIT 1) - set(Threads_FOUND TRUE) -endif() - -if(CMAKE_SYSTEM MATCHES "Windows") - set(CMAKE_USE_WIN32_THREADS_INIT 1) - set(Threads_FOUND TRUE) -endif() - -if(CMAKE_USE_PTHREADS_INIT) - if(CMAKE_SYSTEM MATCHES "HP-UX-*") - # Use libcma if it exists and can be used. It provides more - # symbols than the plain pthread library. CMA threads - # have actually been deprecated: - # http://docs.hp.com/en/B3920-90091/ch12s03.html#d0e11395 - # http://docs.hp.com/en/947/d8.html - # but we need to maintain compatibility here. - # The CMAKE_HP_PTHREADS setting actually indicates whether CMA threads - # are available. - CHECK_CXX_LIBRARY_EXISTS(cma pthread_attr_create "" CMAKE_HAVE_HP_CMA) - if(CMAKE_HAVE_HP_CMA) - set(CMAKE_THREAD_LIBS_INIT "-lcma") - set(CMAKE_HP_PTHREADS_INIT 1) - set(Threads_FOUND TRUE) - endif() - set(CMAKE_USE_PTHREADS_INIT 1) - endif() - - if(CMAKE_SYSTEM MATCHES "OSF1-V*") - set(CMAKE_USE_PTHREADS_INIT 0) - set(CMAKE_THREAD_LIBS_INIT ) - endif() - - if(CMAKE_SYSTEM MATCHES "CYGWIN_NT*") - set(CMAKE_USE_PTHREADS_INIT 1) - set(Threads_FOUND TRUE) - set(CMAKE_THREAD_LIBS_INIT ) - set(CMAKE_USE_WIN32_THREADS_INIT 0) - endif() -endif() - -include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Threads DEFAULT_MSG Threads_FOUND) -- 2.7.4