Fix check for pthreads library on Ubuntu.

This commit is contained in:
Andreas Schuh 2014-03-18 22:39:59 +00:00
parent b8f5717416
commit b18fe77ecd
3 changed files with 497 additions and 447 deletions

View file

@ -1,268 +1,278 @@
cmake_minimum_required(VERSION 2.8.4 FATAL_ERROR)
if (WIN32 AND NOT CYGWIN)
set (WINDOWS 1)
else ()
set (WINDOWS 0)
endif ()
# ----------------------------------------------------------------------------
# includes
set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include (utils)
# ----------------------------------------------------------------------------
# package information
set (PROJECT_NAME "gflags")
set (PACKAGE_NAME "${PROJECT_NAME}")
set (PACKAGE_VERSION "2.1.0")
set (PACKAGE_STRING "${PROJECT_NAME} ${PACKAGE_VERSION}")
set (PACKAGE_TARNAME "${PROJECT_NAME}-${PACKAGE_VERSION}")
set (PACKAGE_BUGREPORT "https://code.google.com/p/gflags/issues/")
project (${PROJECT_NAME} CXX)
version_numbers (
${PACKAGE_VERSION}
PACKAGE_VERSION_MAJOR
PACKAGE_VERSION_MINOR
PACKAGE_VERSION_PATCH
)
# ----------------------------------------------------------------------------
# configure options
option (BUILD_SHARED_LIBS "Request build of shared libraries." OFF)
if (WINDOWS AND BUILD_SHARED_LIBS)
set (GFLAGS_IS_A_DLL 1)
else ()
set (GFLAGS_IS_A_DLL 0)
endif ()
option (BUILD_gflags_LIB "Request build of the multi-threaded gflags library." ON)
option (BUILD_gflags_nothreads_LIB "Request build of the single-threaded gflags library." ON)
if (NOT BUILD_gflags_LIB AND NOT BUILD_gflags_nothreads_LIB)
message (FATAL_ERROR "At least one of BUILD_gflags_LIB and BUILD_gflags_nothreads_LIB must be ON.")
endif ()
option (BUILD_NEGATIVE_COMPILATION_TESTS "Request addition of negative compilation tests." OFF)
mark_as_advanced (BUILD_NEGATIVE_COMPILATION_TESTS)
set (GFLAGS_NAMESPACE "gflags" CACHE STRING "C++ namespace identifier of gflags library.")
mark_as_advanced (GFLAGS_NAMESPACE)
mark_as_advanced (CLEAR CMAKE_INSTALL_PREFIX)
mark_as_advanced (CMAKE_CONFIGURATION_TYPES)
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS AND NOT CMAKE_C_FLAGS)
set (
CMAKE_BUILD_TYPE "Release"
CACHE STRING "Choose the type of build, options are: None (CMAKE_C_FLAGS and CMAKE_CXX_FLAGS used) Debug Release RelWithDebInfo MinSizeRel."
FORCE
)
endif ()
if (APPLE)
mark_as_advanced(CMAKE_OSX_ARCHITECTURES
CMAKE_OSX_DEPLOYMENT_TARGET
CMAKE_OSX_SYSROOT)
endif ()
# ----------------------------------------------------------------------------
# system checks
include (CheckTypeSize)
include (CheckIncludeFileCXX)
include (CheckCXXSymbolExists)
set (GFLAGS_INTTYPES_FORMAT "" CACHE STRING "Format of integer types: \"C99\" (uint32_t), \"BSD\" (u_int32_t), \"VC7\" (__int32)")
set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY STRINGS "C99;BSD;VC7")
mark_as_advanced (GFLAGS_INTTYPES_FORMAT)
if (NOT GFLAGS_INTTYPES_FORMAT)
set (TYPES uint32_t u_int32_t)
if (MSVC)
list (INSERT TYPES 0 __int32)
endif ()
foreach (type IN LISTS TYPES)
check_type_size (${type} ${type} LANGUAGE CXX)
if (HAVE_${type})
break ()
endif ()
endforeach ()
if (HAVE_uint32_t)
set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE C99)
elseif (HAVE_u_int32_t)
set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE BSD)
elseif (HAVE___int32)
set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE VC7)
else ()
mark_as_advanced (CLEAR GFLAGS_INTTYPES_FORMAT)
message (FATAL_ERROR "Do not know how to define a 32-bit integer quantity on your system!"
" Neither uint32_t, u_int32_t, nor __int32 seem to be available."
" Set GFLAGS_INTTYPES_FORMAT to either C99, BSD, or VC7 and try again.")
endif ()
endif ()
# use of special characters in strings to circumvent bug #0008226
if ("^${GFLAGS_INTTYPES_FORMAT}$" STREQUAL "^WIN$")
set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE VC7)
endif ()
if (NOT GFLAGS_INTTYPES_FORMAT MATCHES "^(C99|BSD|VC7)$")
message (FATAL_ERROR "Invalid value for GFLAGS_INTTYPES_FORMAT! Choose one of \"C99\", \"BSD\", or \"VC7\"")
endif ()
set (GFLAGS_INTTYPES_FORMAT_C99 0)
set (GFLAGS_INTTYPES_FORMAT_BSD 0)
set (GFLAGS_INTTYPES_FORMAT_VC7 0)
set ("GFLAGS_INTTYPES_FORMAT_${GFLAGS_INTTYPES_FORMAT}" 1)
foreach (fname IN ITEMS stdint sys/types fnmatch inttypes unistd sys/stat)
string (TOUPPER "${fname}" FNAME)
string (REGEX REPLACE "/" "_" FNAME "${FNAME}")
if (HAVE_${FNAME}_H)
# set by check_type_size already
set (GFLAGS_HAVE_${FNAME}_H ${HAVE_${FNAME}_H})
else ()
check_include_file_cxx ("${fname}.h" GFLAGS_HAVE_${FNAME}_H)
endif ()
endforeach ()
if (NOT GFLAGS_HAVE_FNMATCH_H AND WINDOWS)
check_include_file_cxx ("shlwapi.h" GFLAGS_HAVE_SHLWAPI_H)
endif ()
bool_to_int(GFLAGS_HAVE_STDINT_H)
bool_to_int(GFLAGS_HAVE_SYS_TYPES_H)
bool_to_int(GFLAGS_HAVE_INTTYPES_H)
if (MSVC)
set (GFLAGS_HAVE_strtoll FALSE)
set (GFLAGS_HAVE_strtoq FALSE)
else ()
foreach (fname IN ITEMS strtoll strtoq)
string (TOUPPER "${fname}" FNAME)
check_cxx_symbol_exists ("${fname}" stdlib.h GFLAGS_HAVE_${FNAME})
endforeach ()
endif ()
set (CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package (ThreadsCXX)
if (Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
set (GFLAGS_HAVE_PTHREAD TRUE)
check_type_size (pthread_rwlock_t GFLAGS_HAVE_RWLOCK LANGUAGE CXX)
else ()
set (GFLAGS_HAVE_PTHREAD FALSE)
endif ()
if (UNIX AND NOT GFLAGS_HAVE_PTHREAD AND BUILD_gflags_LIB)
set_property (CACHE BUILD_gflags_LIB PROPERTY VALUE OFF)
message (WARNING "Could not find the <pthread.h> header file."
" Disabling the build of the multi-threaded gflags library.")
endif ()
# ----------------------------------------------------------------------------
# source files - excluding root subdirectory and/or .in suffix
set (PUBLIC_HDRS
"gflags.h"
"gflags_declare.h"
"gflags_completions.h"
)
set (PRIVATE_HDRS
"config.h"
)
set (GFLAGS_SRCS
"gflags.cc"
"gflags_reporting.cc"
"gflags_completions.cc"
)
if (WINDOWS)
list (APPEND PRIVATE_HDRS "windows_port.h")
list (APPEND GFLAGS_SRCS "windows_port.cc")
endif ()
# ----------------------------------------------------------------------------
# configure source files
if (CMAKE_COMPILER_IS_GNUCXX)
set (GFLAGS_ATTRIBUTE_UNUSED "__attribute((unused))")
else ()
set (GFLAGS_ATTRIBUTE_UNUSED)
endif ()
configure_headers (PUBLIC_HDRS ${PUBLIC_HDRS})
configure_sources (PRIVATE_HDRS ${PRIVATE_HDRS})
configure_sources (GFLAGS_SRCS ${GFLAGS_SRCS})
# ----------------------------------------------------------------------------
# output directories
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin")
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "lib")
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "lib")
# ----------------------------------------------------------------------------
# add library target
include_directories ("${PROJECT_SOURCE_DIR}/src")
include_directories ("${PROJECT_BINARY_DIR}/include")
include_directories ("${PROJECT_BINARY_DIR}/include/${GFLAGS_NAMESPACE}")
set (LIB_TARGETS)
if (BUILD_gflags_LIB)
add_library (gflags ${GFLAGS_SRCS} ${PRIVATE_HDRS} ${PUBLIC_HDRS})
list (APPEND LIB_TARGETS gflags)
endif ()
if (BUILD_gflags_nothreads_LIB)
add_library (gflags_nothreads ${GFLAGS_SRCS} ${PRIVATE_HDRS} ${PUBLIC_HDRS})
set_target_properties (gflags_nothreads PROPERTIES COMPILE_DEFINITIONS NO_THREADS)
list (APPEND LIB_TARGETS gflags_nothreads)
endif ()
# ----------------------------------------------------------------------------
# installation
if (WIN32)
set (RUNTIME_INSTALL_DIR Bin)
set (LIBRARY_INSTALL_DIR Lib)
set (INCLUDE_INSTALL_DIR Include)
set (CONFIG_INSTALL_DIR CMake)
else ()
set (RUNTIME_INSTALL_DIR bin)
set (LIBRARY_INSTALL_DIR lib)
set (INCLUDE_INSTALL_DIR include)
set (CONFIG_INSTALL_DIR lib/cmake/${PACKAGE_NAME})
endif ()
install (TARGETS ${LIB_TARGETS} DESTINATION ${LIBRARY_INSTALL_DIR} EXPORT gflags-lib)
install (FILES ${PUBLIC_HDRS} DESTINATION ${INCLUDE_INSTALL_DIR}/${GFLAGS_NAMESPACE})
file (RELATIVE_PATH INSTALL_PREFIX_REL2CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/${CONFIG_INSTALL_DIR}" "${CMAKE_INSTALL_PREFIX}")
configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake" @ONLY)
configure_file (cmake/version.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake" @ONLY)
install (
FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake"
RENAME ${PACKAGE_NAME}-config.cmake
DESTINATION ${CONFIG_INSTALL_DIR}
)
install (
FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake"
DESTINATION ${CONFIG_INSTALL_DIR}
)
install (EXPORT gflags-lib DESTINATION ${CONFIG_INSTALL_DIR} FILE ${PACKAGE_NAME}-export.cmake)
if (UNIX)
install (PROGRAMS src/gflags_completions.sh DESTINATION ${RUNTIME_INSTALL_DIR})
endif ()
# ----------------------------------------------------------------------------
# support direct use of build tree
set (INSTALL_PREFIX_REL2CONFIG_DIR .)
export (TARGETS ${LIB_TARGETS} FILE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-export.cmake")
export (PACKAGE gflags)
configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config.cmake" @ONLY)
# ----------------------------------------------------------------------------
# testing - MUST follow the generation of the build tree config file
include (CTest)
if (BUILD_TESTING)
enable_testing ()
add_subdirectory (test)
endif ()
cmake_minimum_required(VERSION 2.8.4 FATAL_ERROR)
if (WIN32 AND NOT CYGWIN)
set (WINDOWS 1)
else ()
set (WINDOWS 0)
endif ()
# ----------------------------------------------------------------------------
# includes
set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include (utils)
# ----------------------------------------------------------------------------
# package information
set (PROJECT_NAME "gflags")
set (PACKAGE_NAME "${PROJECT_NAME}")
set (PACKAGE_VERSION "2.1.0")
set (PACKAGE_STRING "${PROJECT_NAME} ${PACKAGE_VERSION}")
set (PACKAGE_TARNAME "${PROJECT_NAME}-${PACKAGE_VERSION}")
set (PACKAGE_BUGREPORT "https://code.google.com/p/gflags/issues/")
project (${PROJECT_NAME} CXX)
version_numbers (
${PACKAGE_VERSION}
PACKAGE_VERSION_MAJOR
PACKAGE_VERSION_MINOR
PACKAGE_VERSION_PATCH
)
# ----------------------------------------------------------------------------
# configure options
option (BUILD_SHARED_LIBS "Request build of shared libraries." OFF)
if (WINDOWS AND BUILD_SHARED_LIBS)
set (GFLAGS_IS_A_DLL 1)
else ()
set (GFLAGS_IS_A_DLL 0)
endif ()
option (BUILD_gflags_LIB "Request build of the multi-threaded gflags library." ON)
option (BUILD_gflags_nothreads_LIB "Request build of the single-threaded gflags library." ON)
if (NOT BUILD_gflags_LIB AND NOT BUILD_gflags_nothreads_LIB)
message (FATAL_ERROR "At least one of BUILD_gflags_LIB and BUILD_gflags_nothreads_LIB must be ON.")
endif ()
option (BUILD_NEGATIVE_COMPILATION_TESTS "Request addition of negative compilation tests." OFF)
mark_as_advanced (BUILD_NEGATIVE_COMPILATION_TESTS)
set (GFLAGS_NAMESPACE "gflags" CACHE STRING "C++ namespace identifier of gflags library.")
mark_as_advanced (GFLAGS_NAMESPACE)
mark_as_advanced (CLEAR CMAKE_INSTALL_PREFIX)
mark_as_advanced (CMAKE_CONFIGURATION_TYPES)
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS AND NOT CMAKE_C_FLAGS)
set (
CMAKE_BUILD_TYPE "Release"
CACHE STRING "Choose the type of build, options are: None (CMAKE_C_FLAGS and CMAKE_CXX_FLAGS used) Debug Release RelWithDebInfo MinSizeRel."
FORCE
)
endif ()
if (APPLE)
mark_as_advanced(CMAKE_OSX_ARCHITECTURES
CMAKE_OSX_DEPLOYMENT_TARGET
CMAKE_OSX_SYSROOT)
endif ()
# ----------------------------------------------------------------------------
# system checks
include (CheckTypeSize)
include (CheckIncludeFileCXX)
include (CheckCXXSymbolExists)
set (GFLAGS_INTTYPES_FORMAT "" CACHE STRING "Format of integer types: \"C99\" (uint32_t), \"BSD\" (u_int32_t), \"VC7\" (__int32)")
set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY STRINGS "C99;BSD;VC7")
mark_as_advanced (GFLAGS_INTTYPES_FORMAT)
if (NOT GFLAGS_INTTYPES_FORMAT)
set (TYPES uint32_t u_int32_t)
if (MSVC)
list (INSERT TYPES 0 __int32)
endif ()
foreach (type IN LISTS TYPES)
check_type_size (${type} ${type} LANGUAGE CXX)
if (HAVE_${type})
break ()
endif ()
endforeach ()
if (HAVE_uint32_t)
set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE C99)
elseif (HAVE_u_int32_t)
set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE BSD)
elseif (HAVE___int32)
set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE VC7)
else ()
mark_as_advanced (CLEAR GFLAGS_INTTYPES_FORMAT)
message (FATAL_ERROR "Do not know how to define a 32-bit integer quantity on your system!"
" Neither uint32_t, u_int32_t, nor __int32 seem to be available."
" Set GFLAGS_INTTYPES_FORMAT to either C99, BSD, or VC7 and try again.")
endif ()
endif ()
# use of special characters in strings to circumvent bug #0008226
if ("^${GFLAGS_INTTYPES_FORMAT}$" STREQUAL "^WIN$")
set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE VC7)
endif ()
if (NOT GFLAGS_INTTYPES_FORMAT MATCHES "^(C99|BSD|VC7)$")
message (FATAL_ERROR "Invalid value for GFLAGS_INTTYPES_FORMAT! Choose one of \"C99\", \"BSD\", or \"VC7\"")
endif ()
set (GFLAGS_INTTYPES_FORMAT_C99 0)
set (GFLAGS_INTTYPES_FORMAT_BSD 0)
set (GFLAGS_INTTYPES_FORMAT_VC7 0)
set ("GFLAGS_INTTYPES_FORMAT_${GFLAGS_INTTYPES_FORMAT}" 1)
foreach (fname IN ITEMS stdint sys/types fnmatch inttypes unistd sys/stat)
string (TOUPPER "${fname}" FNAME)
string (REGEX REPLACE "/" "_" FNAME "${FNAME}")
if (HAVE_${FNAME}_H)
# set by check_type_size already
set (GFLAGS_HAVE_${FNAME}_H ${HAVE_${FNAME}_H})
else ()
check_include_file_cxx ("${fname}.h" GFLAGS_HAVE_${FNAME}_H)
endif ()
endforeach ()
if (NOT GFLAGS_HAVE_FNMATCH_H AND WINDOWS)
check_include_file_cxx ("shlwapi.h" GFLAGS_HAVE_SHLWAPI_H)
endif ()
bool_to_int(GFLAGS_HAVE_STDINT_H)
bool_to_int(GFLAGS_HAVE_SYS_TYPES_H)
bool_to_int(GFLAGS_HAVE_INTTYPES_H)
if (MSVC)
set (GFLAGS_HAVE_strtoll FALSE)
set (GFLAGS_HAVE_strtoq FALSE)
else ()
foreach (fname IN ITEMS strtoll strtoq)
string (TOUPPER "${fname}" FNAME)
check_cxx_symbol_exists ("${fname}" stdlib.h GFLAGS_HAVE_${FNAME})
endforeach ()
endif ()
set (CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package (ThreadsCXX)
if (Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
set (GFLAGS_HAVE_PTHREAD TRUE)
check_type_size (pthread_rwlock_t RWLOCK LANGUAGE CXX)
if (HAVE_RWLOCK)
set (GFLAGS_HAVE_RWLOCK TRUE)
else ()
set (GFLAGS_HAVE_RWLOCK FALSE)
endif ()
else ()
set (GFLAGS_HAVE_PTHREAD FALSE)
endif ()
if (UNIX AND NOT GFLAGS_HAVE_PTHREAD AND BUILD_gflags_LIB)
set_property (CACHE BUILD_gflags_LIB PROPERTY VALUE OFF)
if (CMAKE_HAVE_PTHREAD_H)
message (WARNING "Could not find the pthread(s) library."
" Disabling the build of the multi-threaded gflags library.")
else ()
message (WARNING "Could not find the <pthread.h> header file."
" Disabling the build of the multi-threaded gflags library.")
endif ()
endif ()
# ----------------------------------------------------------------------------
# source files - excluding root subdirectory and/or .in suffix
set (PUBLIC_HDRS
"gflags.h"
"gflags_declare.h"
"gflags_completions.h"
)
set (PRIVATE_HDRS
"config.h"
)
set (GFLAGS_SRCS
"gflags.cc"
"gflags_reporting.cc"
"gflags_completions.cc"
)
if (WINDOWS)
list (APPEND PRIVATE_HDRS "windows_port.h")
list (APPEND GFLAGS_SRCS "windows_port.cc")
endif ()
# ----------------------------------------------------------------------------
# configure source files
if (CMAKE_COMPILER_IS_GNUCXX)
set (GFLAGS_ATTRIBUTE_UNUSED "__attribute((unused))")
else ()
set (GFLAGS_ATTRIBUTE_UNUSED)
endif ()
configure_headers (PUBLIC_HDRS ${PUBLIC_HDRS})
configure_sources (PRIVATE_HDRS ${PRIVATE_HDRS})
configure_sources (GFLAGS_SRCS ${GFLAGS_SRCS})
# ----------------------------------------------------------------------------
# output directories
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin")
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "lib")
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "lib")
# ----------------------------------------------------------------------------
# add library target
include_directories ("${PROJECT_SOURCE_DIR}/src")
include_directories ("${PROJECT_BINARY_DIR}/include")
include_directories ("${PROJECT_BINARY_DIR}/include/${GFLAGS_NAMESPACE}")
set (LIB_TARGETS)
if (BUILD_gflags_LIB)
add_library (gflags ${GFLAGS_SRCS} ${PRIVATE_HDRS} ${PUBLIC_HDRS})
list (APPEND LIB_TARGETS gflags)
endif ()
if (BUILD_gflags_nothreads_LIB)
add_library (gflags_nothreads ${GFLAGS_SRCS} ${PRIVATE_HDRS} ${PUBLIC_HDRS})
set_target_properties (gflags_nothreads PROPERTIES COMPILE_DEFINITIONS NO_THREADS)
list (APPEND LIB_TARGETS gflags_nothreads)
endif ()
# ----------------------------------------------------------------------------
# installation
if (WIN32)
set (RUNTIME_INSTALL_DIR Bin)
set (LIBRARY_INSTALL_DIR Lib)
set (INCLUDE_INSTALL_DIR Include)
set (CONFIG_INSTALL_DIR CMake)
else ()
set (RUNTIME_INSTALL_DIR bin)
set (LIBRARY_INSTALL_DIR lib)
set (INCLUDE_INSTALL_DIR include)
set (CONFIG_INSTALL_DIR lib/cmake/${PACKAGE_NAME})
endif ()
install (TARGETS ${LIB_TARGETS} DESTINATION ${LIBRARY_INSTALL_DIR} EXPORT gflags-lib)
install (FILES ${PUBLIC_HDRS} DESTINATION ${INCLUDE_INSTALL_DIR}/${GFLAGS_NAMESPACE})
file (RELATIVE_PATH INSTALL_PREFIX_REL2CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/${CONFIG_INSTALL_DIR}" "${CMAKE_INSTALL_PREFIX}")
configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake" @ONLY)
configure_file (cmake/version.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake" @ONLY)
install (
FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake"
RENAME ${PACKAGE_NAME}-config.cmake
DESTINATION ${CONFIG_INSTALL_DIR}
)
install (
FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake"
DESTINATION ${CONFIG_INSTALL_DIR}
)
install (EXPORT gflags-lib DESTINATION ${CONFIG_INSTALL_DIR} FILE ${PACKAGE_NAME}-export.cmake)
if (UNIX)
install (PROGRAMS src/gflags_completions.sh DESTINATION ${RUNTIME_INSTALL_DIR})
endif ()
# ----------------------------------------------------------------------------
# support direct use of build tree
set (INSTALL_PREFIX_REL2CONFIG_DIR .)
export (TARGETS ${LIB_TARGETS} FILE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-export.cmake")
export (PACKAGE gflags)
configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config.cmake" @ONLY)
# ----------------------------------------------------------------------------
# testing - MUST follow the generation of the build tree config file
include (CTest)
if (BUILD_TESTING)
enable_testing ()
add_subdirectory (test)
endif ()

View file

@ -0,0 +1,38 @@
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
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;
}

View file

@ -1,179 +1,181 @@
#.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, -lpthread, 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_ROOT}/Modules/CheckForPthreads.c" "${CMAKE_BINARY_DIR}/CheckForPthreads.cxx" COPYONLY)
try_run(THREADS_PTHREAD_ARG THREADS_HAVE_PTHREAD_ARG
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}/CheckForPthreads.cxx
CMAKE_FLAGS -DLINK_LIBRARIES:STRING=-pthread
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)
#.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)