Fix check for pthreads library on Ubuntu.
authorAndreas Schuh <andreas.schuh.84@gmail.com>
Tue, 18 Mar 2014 22:39:59 +0000 (22:39 +0000)
committerAndreas Schuh <andreas.schuh.84@gmail.com>
Tue, 18 Mar 2014 22:39:59 +0000 (22:39 +0000)
CMakeLists.txt
cmake/CheckForPthreads.cxx [new file with mode: 0644]
cmake/FindThreadsCXX.cmake

index 5639411..18360f2 100644 (file)
-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)\r
+\r
+if (WIN32 AND NOT CYGWIN)\r
+  set (WINDOWS 1)\r
+else ()\r
+  set (WINDOWS 0)\r
+endif ()\r
+\r
+# ----------------------------------------------------------------------------\r
+# includes\r
+set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")\r
+\r
+include (utils)\r
+\r
+# ----------------------------------------------------------------------------\r
+# package information\r
+set (PROJECT_NAME      "gflags")\r
+set (PACKAGE_NAME      "${PROJECT_NAME}")\r
+set (PACKAGE_VERSION   "2.1.0")\r
+set (PACKAGE_STRING    "${PROJECT_NAME} ${PACKAGE_VERSION}")\r
+set (PACKAGE_TARNAME   "${PROJECT_NAME}-${PACKAGE_VERSION}")\r
+set (PACKAGE_BUGREPORT "https://code.google.com/p/gflags/issues/")\r
+\r
+project (${PROJECT_NAME} CXX)\r
+\r
+version_numbers (\r
+  ${PACKAGE_VERSION}\r
+    PACKAGE_VERSION_MAJOR\r
+    PACKAGE_VERSION_MINOR\r
+    PACKAGE_VERSION_PATCH\r
+)\r
+\r
+# ----------------------------------------------------------------------------\r
+# configure options\r
+option (BUILD_SHARED_LIBS "Request build of shared libraries." OFF)\r
+\r
+if (WINDOWS AND BUILD_SHARED_LIBS)\r
+  set (GFLAGS_IS_A_DLL 1)\r
+else ()\r
+  set (GFLAGS_IS_A_DLL 0)\r
+endif ()\r
+\r
+option (BUILD_gflags_LIB           "Request build of the multi-threaded gflags library."  ON)\r
+option (BUILD_gflags_nothreads_LIB "Request build of the single-threaded gflags library." ON)\r
+\r
+if (NOT BUILD_gflags_LIB AND NOT BUILD_gflags_nothreads_LIB)\r
+ message (FATAL_ERROR "At least one of BUILD_gflags_LIB and BUILD_gflags_nothreads_LIB must be ON.")\r
+endif ()\r
+\r
+option (BUILD_NEGATIVE_COMPILATION_TESTS "Request addition of negative compilation tests." OFF)\r
+mark_as_advanced (BUILD_NEGATIVE_COMPILATION_TESTS)\r
+\r
+set (GFLAGS_NAMESPACE "gflags" CACHE STRING "C++ namespace identifier of gflags library.")\r
+mark_as_advanced (GFLAGS_NAMESPACE)\r
+\r
+mark_as_advanced (CLEAR CMAKE_INSTALL_PREFIX)\r
+mark_as_advanced (CMAKE_CONFIGURATION_TYPES)\r
+if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS AND NOT CMAKE_C_FLAGS)\r
+  set (\r
+    CMAKE_BUILD_TYPE "Release"\r
+    CACHE STRING "Choose the type of build, options are: None (CMAKE_C_FLAGS and CMAKE_CXX_FLAGS used) Debug Release RelWithDebInfo MinSizeRel."\r
+    FORCE\r
+  )\r
+endif ()\r
+\r
+if (APPLE)\r
+  mark_as_advanced(CMAKE_OSX_ARCHITECTURES\r
+                   CMAKE_OSX_DEPLOYMENT_TARGET\r
+                   CMAKE_OSX_SYSROOT)\r
+endif ()\r
+\r
+# ----------------------------------------------------------------------------\r
+# system checks\r
+include (CheckTypeSize)\r
+include (CheckIncludeFileCXX)\r
+include (CheckCXXSymbolExists)\r
+\r
+set (GFLAGS_INTTYPES_FORMAT "" CACHE STRING "Format of integer types: \"C99\" (uint32_t), \"BSD\" (u_int32_t), \"VC7\" (__int32)")\r
+set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY STRINGS "C99;BSD;VC7")\r
+mark_as_advanced (GFLAGS_INTTYPES_FORMAT)\r
+if (NOT GFLAGS_INTTYPES_FORMAT)\r
+  set (TYPES uint32_t u_int32_t)\r
+  if (MSVC)\r
+    list (INSERT TYPES 0 __int32)\r
+  endif ()\r
+  foreach (type IN LISTS TYPES)\r
+    check_type_size (${type} ${type} LANGUAGE CXX)\r
+    if (HAVE_${type})\r
+      break ()\r
+    endif ()\r
+  endforeach ()\r
+  if (HAVE_uint32_t)\r
+    set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE C99)\r
+  elseif (HAVE_u_int32_t)\r
+    set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE BSD)\r
+  elseif (HAVE___int32)\r
+    set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE VC7)\r
+  else ()\r
+    mark_as_advanced (CLEAR GFLAGS_INTTYPES_FORMAT)\r
+    message (FATAL_ERROR "Do not know how to define a 32-bit integer quantity on your system!"\r
+                         " Neither uint32_t, u_int32_t, nor __int32 seem to be available."\r
+                         " Set GFLAGS_INTTYPES_FORMAT to either C99, BSD, or VC7 and try again.")\r
+  endif ()\r
+endif ()\r
+# use of special characters in strings to circumvent bug #0008226\r
+if ("^${GFLAGS_INTTYPES_FORMAT}$" STREQUAL "^WIN$")\r
+  set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE VC7)\r
+endif ()\r
+if (NOT GFLAGS_INTTYPES_FORMAT MATCHES "^(C99|BSD|VC7)$")\r
+  message (FATAL_ERROR "Invalid value for GFLAGS_INTTYPES_FORMAT! Choose one of \"C99\", \"BSD\", or \"VC7\"")\r
+endif ()\r
+set (GFLAGS_INTTYPES_FORMAT_C99 0)\r
+set (GFLAGS_INTTYPES_FORMAT_BSD 0)\r
+set (GFLAGS_INTTYPES_FORMAT_VC7 0)\r
+set ("GFLAGS_INTTYPES_FORMAT_${GFLAGS_INTTYPES_FORMAT}" 1)\r
+\r
+foreach (fname IN ITEMS stdint sys/types fnmatch inttypes unistd sys/stat)\r
+  string (TOUPPER "${fname}" FNAME)\r
+  string (REGEX REPLACE "/" "_" FNAME "${FNAME}")\r
+  if (HAVE_${FNAME}_H)\r
+    # set by check_type_size already\r
+    set (GFLAGS_HAVE_${FNAME}_H ${HAVE_${FNAME}_H})\r
+  else ()\r
+    check_include_file_cxx ("${fname}.h" GFLAGS_HAVE_${FNAME}_H)\r
+  endif ()\r
+endforeach ()\r
+if (NOT GFLAGS_HAVE_FNMATCH_H AND WINDOWS)\r
+  check_include_file_cxx ("shlwapi.h" GFLAGS_HAVE_SHLWAPI_H)\r
+endif ()\r
+bool_to_int(GFLAGS_HAVE_STDINT_H)\r
+bool_to_int(GFLAGS_HAVE_SYS_TYPES_H)\r
+bool_to_int(GFLAGS_HAVE_INTTYPES_H)\r
+\r
+if (MSVC)\r
+  set (GFLAGS_HAVE_strtoll FALSE)\r
+  set (GFLAGS_HAVE_strtoq  FALSE)\r
+else ()\r
+  foreach (fname IN ITEMS strtoll strtoq)\r
+    string (TOUPPER "${fname}" FNAME)\r
+    check_cxx_symbol_exists ("${fname}" stdlib.h GFLAGS_HAVE_${FNAME})\r
+  endforeach ()\r
+endif ()\r
+\r
+set (CMAKE_THREAD_PREFER_PTHREAD TRUE)\r
+find_package (ThreadsCXX)\r
+if (Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)\r
+  set (GFLAGS_HAVE_PTHREAD TRUE)\r
+  check_type_size (pthread_rwlock_t RWLOCK LANGUAGE CXX)\r
+  if (HAVE_RWLOCK)\r
+    set (GFLAGS_HAVE_RWLOCK TRUE)\r
+  else ()\r
+    set (GFLAGS_HAVE_RWLOCK FALSE)\r
+  endif ()\r
+else ()\r
+  set (GFLAGS_HAVE_PTHREAD FALSE)\r
+endif ()\r
+\r
+if (UNIX AND NOT GFLAGS_HAVE_PTHREAD AND BUILD_gflags_LIB)\r
+  set_property (CACHE BUILD_gflags_LIB PROPERTY VALUE OFF)\r
+  if (CMAKE_HAVE_PTHREAD_H)\r
+    message (WARNING "Could not find the pthread(s) library."\r
+                     " Disabling the build of the multi-threaded gflags library.")\r
+  else ()\r
+    message (WARNING "Could not find the <pthread.h> header file."\r
+                     " Disabling the build of the multi-threaded gflags library.")\r
+  endif ()\r
+endif ()\r
+\r
+# ----------------------------------------------------------------------------\r
+# source files - excluding root subdirectory and/or .in suffix\r
+set (PUBLIC_HDRS\r
+  "gflags.h"\r
+  "gflags_declare.h"\r
+  "gflags_completions.h"\r
+)\r
+\r
+set (PRIVATE_HDRS\r
+  "config.h"\r
+)\r
+\r
+set (GFLAGS_SRCS\r
+  "gflags.cc"\r
+  "gflags_reporting.cc"\r
+  "gflags_completions.cc"\r
+)\r
+\r
+if (WINDOWS)\r
+  list (APPEND PRIVATE_HDRS "windows_port.h")\r
+  list (APPEND GFLAGS_SRCS  "windows_port.cc")\r
+endif ()\r
+\r
+# ----------------------------------------------------------------------------\r
+# configure source files\r
+if (CMAKE_COMPILER_IS_GNUCXX)\r
+  set (GFLAGS_ATTRIBUTE_UNUSED "__attribute((unused))")\r
+else ()\r
+  set (GFLAGS_ATTRIBUTE_UNUSED)\r
+endif ()\r
+\r
+configure_headers (PUBLIC_HDRS  ${PUBLIC_HDRS})\r
+configure_sources (PRIVATE_HDRS ${PRIVATE_HDRS})\r
+configure_sources (GFLAGS_SRCS  ${GFLAGS_SRCS})\r
+\r
+# ----------------------------------------------------------------------------\r
+# output directories\r
+set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin")\r
+set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "lib")\r
+set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "lib")\r
+\r
+# ----------------------------------------------------------------------------\r
+# add library target\r
+include_directories ("${PROJECT_SOURCE_DIR}/src")\r
+include_directories ("${PROJECT_BINARY_DIR}/include")\r
+include_directories ("${PROJECT_BINARY_DIR}/include/${GFLAGS_NAMESPACE}")\r
+\r
+set (LIB_TARGETS)\r
+if (BUILD_gflags_LIB)\r
+  add_library (gflags ${GFLAGS_SRCS} ${PRIVATE_HDRS} ${PUBLIC_HDRS})\r
+  list (APPEND LIB_TARGETS gflags)\r
+endif ()\r
+if (BUILD_gflags_nothreads_LIB)\r
+  add_library (gflags_nothreads ${GFLAGS_SRCS} ${PRIVATE_HDRS} ${PUBLIC_HDRS})\r
+  set_target_properties (gflags_nothreads PROPERTIES COMPILE_DEFINITIONS NO_THREADS)\r
+  list (APPEND LIB_TARGETS gflags_nothreads)\r
+endif ()\r
+\r
+# ----------------------------------------------------------------------------\r
+# installation\r
+if (WIN32)\r
+  set (RUNTIME_INSTALL_DIR Bin)\r
+  set (LIBRARY_INSTALL_DIR Lib)\r
+  set (INCLUDE_INSTALL_DIR Include)\r
+  set (CONFIG_INSTALL_DIR  CMake)\r
+else ()\r
+  set (RUNTIME_INSTALL_DIR bin)\r
+  set (LIBRARY_INSTALL_DIR lib)\r
+  set (INCLUDE_INSTALL_DIR include)\r
+  set (CONFIG_INSTALL_DIR  lib/cmake/${PACKAGE_NAME})\r
+endif ()\r
+\r
+install (TARGETS ${LIB_TARGETS} DESTINATION ${LIBRARY_INSTALL_DIR} EXPORT gflags-lib)\r
+install (FILES   ${PUBLIC_HDRS} DESTINATION ${INCLUDE_INSTALL_DIR}/${GFLAGS_NAMESPACE})\r
+\r
+file (RELATIVE_PATH INSTALL_PREFIX_REL2CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/${CONFIG_INSTALL_DIR}" "${CMAKE_INSTALL_PREFIX}")\r
+configure_file (cmake/config.cmake.in  "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake" @ONLY)\r
+configure_file (cmake/version.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake" @ONLY)\r
+\r
+install (\r
+  FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-install.cmake"\r
+  RENAME ${PACKAGE_NAME}-config.cmake\r
+  DESTINATION ${CONFIG_INSTALL_DIR}\r
+)\r
+\r
+install (\r
+  FILES "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake"\r
+  DESTINATION ${CONFIG_INSTALL_DIR}\r
+)\r
+\r
+install (EXPORT gflags-lib DESTINATION ${CONFIG_INSTALL_DIR} FILE ${PACKAGE_NAME}-export.cmake)\r
+\r
+if (UNIX)\r
+  install (PROGRAMS src/gflags_completions.sh DESTINATION ${RUNTIME_INSTALL_DIR})\r
+endif ()\r
+\r
+# ----------------------------------------------------------------------------\r
+# support direct use of build tree\r
+set (INSTALL_PREFIX_REL2CONFIG_DIR .)\r
+export (TARGETS ${LIB_TARGETS} FILE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-export.cmake")\r
+export (PACKAGE gflags)\r
+configure_file (cmake/config.cmake.in "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-config.cmake" @ONLY)\r
+\r
+# ----------------------------------------------------------------------------\r
+# testing - MUST follow the generation of the build tree config file\r
+include (CTest)\r
+if (BUILD_TESTING)\r
+  enable_testing ()\r
+  add_subdirectory (test)\r
+endif ()\r
diff --git a/cmake/CheckForPthreads.cxx b/cmake/CheckForPthreads.cxx
new file mode 100644 (file)
index 0000000..2732957
--- /dev/null
@@ -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;
+}
index cfeb578..eea68f1 100644 (file)
-#.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:\r
+# FindThreads\r
+# -----------\r
+#\r
+# This module determines the thread library of the system.\r
+#\r
+# The following variables are set\r
+#\r
+# ::\r
+#\r
+#   CMAKE_THREAD_LIBS_INIT     - the thread library\r
+#   CMAKE_USE_SPROC_INIT       - are we using sproc?\r
+#   CMAKE_USE_WIN32_THREADS_INIT - using WIN32 threads?\r
+#   CMAKE_USE_PTHREADS_INIT    - are we using pthreads\r
+#   CMAKE_HP_PTHREADS_INIT     - are we using hp pthreads\r
+#\r
+# For systems with multiple thread libraries, caller can set\r
+#\r
+# ::\r
+#\r
+#   CMAKE_THREAD_PREFER_PTHREAD\r
+\r
+#=============================================================================\r
+# Copyright 2002-2009 Kitware, Inc.\r
+#\r
+# Distributed under the OSI-approved BSD License (the "License");\r
+# see accompanying file Copyright.txt for details.\r
+#\r
+# This software is distributed WITHOUT ANY WARRANTY; without even the\r
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r
+# See the License for more information.\r
+#=============================================================================\r
+# (To distribute this file outside of CMake, substitute the full\r
+#  License text for the above reference.)\r
+\r
+include (CheckIncludeFileCXX)\r
+include (CheckCXXLibraryExists)\r
+include (CheckCXXSymbolExists)\r
+set(Threads_FOUND FALSE)\r
+\r
+\r
+# Do we have sproc?\r
+if(CMAKE_SYSTEM MATCHES IRIX AND NOT CMAKE_THREAD_PREFER_PTHREAD)\r
+  CHECK_INCLUDE_FILES_CXX("sys/types.h;sys/prctl.h"  CMAKE_HAVE_SPROC_H)\r
+endif()\r
+\r
+if(CMAKE_HAVE_SPROC_H AND NOT CMAKE_THREAD_PREFER_PTHREAD)\r
+  # We have sproc\r
+  set(CMAKE_USE_SPROC_INIT 1)\r
+else()\r
+  # Do we have pthreads?\r
+  CHECK_INCLUDE_FILE_CXX("pthread.h" CMAKE_HAVE_PTHREAD_H)\r
+  if(CMAKE_HAVE_PTHREAD_H)\r
+\r
+    #\r
+    # We have pthread.h\r
+    # Let's check for the library now.\r
+    #\r
+    set(CMAKE_HAVE_THREADS_LIBRARY)\r
+    if(NOT THREADS_HAVE_PTHREAD_ARG)\r
+      # Check if pthread functions are in normal C library\r
+      CHECK_CXX_SYMBOL_EXISTS(pthread_create pthread.h CMAKE_HAVE_LIBC_CREATE)\r
+      if(CMAKE_HAVE_LIBC_CREATE)\r
+        set(CMAKE_THREAD_LIBS_INIT "")\r
+        set(CMAKE_HAVE_THREADS_LIBRARY 1)\r
+        set(Threads_FOUND TRUE)\r
+      endif()\r
+\r
+      if(NOT CMAKE_HAVE_THREADS_LIBRARY)\r
+        # Do we have -lpthreads\r
+        CHECK_CXX_LIBRARY_EXISTS(pthreads pthread_create "" CMAKE_HAVE_PTHREADS_CREATE)\r
+        if(CMAKE_HAVE_PTHREADS_CREATE)\r
+          set(CMAKE_THREAD_LIBS_INIT "-lpthreads")\r
+          set(CMAKE_HAVE_THREADS_LIBRARY 1)\r
+          set(Threads_FOUND TRUE)\r
+        endif()\r
+\r
+        # Ok, how about -lpthread\r
+        CHECK_CXX_LIBRARY_EXISTS(pthread pthread_create "" CMAKE_HAVE_PTHREAD_CREATE)\r
+        if(CMAKE_HAVE_PTHREAD_CREATE)\r
+          set(CMAKE_THREAD_LIBS_INIT "-lpthread")\r
+          set(CMAKE_HAVE_THREADS_LIBRARY 1)\r
+          set(Threads_FOUND TRUE)\r
+        endif()\r
+\r
+        if(CMAKE_SYSTEM MATCHES "SunOS.*")\r
+          # On sun also check for -lthread\r
+          CHECK_CXX_LIBRARY_EXISTS(thread thr_create "" CMAKE_HAVE_THR_CREATE)\r
+          if(CMAKE_HAVE_THR_CREATE)\r
+            set(CMAKE_THREAD_LIBS_INIT "-lthread")\r
+            set(CMAKE_HAVE_THREADS_LIBRARY 1)\r
+            set(Threads_FOUND TRUE)\r
+          endif()\r
+        endif()\r
+      endif()\r
+    endif()\r
+\r
+    if(NOT CMAKE_HAVE_THREADS_LIBRARY)\r
+      # If we did not found -lpthread, -lpthreads, or -lthread, look for -pthread\r
+      if("THREADS_HAVE_PTHREAD_ARG" MATCHES "^THREADS_HAVE_PTHREAD_ARG")\r
+        message(STATUS "Check if compiler accepts -pthread")\r
+        configure_file ("${CMAKE_CURRENT_LIST_DIR}/CheckForPthreads.cxx"\r
+                        "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckForPthreads.cxx" COPYONLY)\r
+        try_run(THREADS_PTHREAD_ARG THREADS_HAVE_PTHREAD_ARG\r
+          ${CMAKE_BINARY_DIR}\r
+          ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckForPthreads.cxx\r
+          CMAKE_FLAGS "-DLINK_LIBRARIES:STRING=-pthread;-DCMAKE_CXX_FLAGS:STRING=-fpermissive"\r
+          COMPILE_OUTPUT_VARIABLE OUTPUT)\r
+\r
+        if(THREADS_HAVE_PTHREAD_ARG)\r
+          if(THREADS_PTHREAD_ARG STREQUAL "2")\r
+            set(Threads_FOUND TRUE)\r
+            message(STATUS "Check if compiler accepts -pthread - yes")\r
+          else()\r
+            message(STATUS "Check if compiler accepts -pthread - no")\r
+            file(APPEND\r
+              ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log\r
+              "Determining if compiler accepts -pthread returned ${THREADS_PTHREAD_ARG} instead of 2. The compiler had the following output:\n${OUTPUT}\n\n")\r
+          endif()\r
+        else()\r
+          message(STATUS "Check if compiler accepts -pthread - no")\r
+          file(APPEND\r
+            ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log\r
+            "Determining if compiler accepts -pthread failed with the following output:\n${OUTPUT}\n\n")\r
+        endif()\r
+\r
+      endif()\r
+\r
+      if(THREADS_HAVE_PTHREAD_ARG)\r
+        set(Threads_FOUND TRUE)\r
+        set(CMAKE_THREAD_LIBS_INIT "-pthread")\r
+      endif()\r
+\r
+    endif()\r
+  endif()\r
+endif()\r
+\r
+if(CMAKE_THREAD_LIBS_INIT OR CMAKE_HAVE_LIBC_CREATE)\r
+  set(CMAKE_USE_PTHREADS_INIT 1)\r
+  set(Threads_FOUND TRUE)\r
+endif()\r
+\r
+if(CMAKE_SYSTEM MATCHES "Windows")\r
+  set(CMAKE_USE_WIN32_THREADS_INIT 1)\r
+  set(Threads_FOUND TRUE)\r
+endif()\r
+\r
+if(CMAKE_USE_PTHREADS_INIT)\r
+  if(CMAKE_SYSTEM MATCHES "HP-UX-*")\r
+    # Use libcma if it exists and can be used.  It provides more\r
+    # symbols than the plain pthread library.  CMA threads\r
+    # have actually been deprecated:\r
+    #   http://docs.hp.com/en/B3920-90091/ch12s03.html#d0e11395\r
+    #   http://docs.hp.com/en/947/d8.html\r
+    # but we need to maintain compatibility here.\r
+    # The CMAKE_HP_PTHREADS setting actually indicates whether CMA threads\r
+    # are available.\r
+    CHECK_CXX_LIBRARY_EXISTS(cma pthread_attr_create "" CMAKE_HAVE_HP_CMA)\r
+    if(CMAKE_HAVE_HP_CMA)\r
+      set(CMAKE_THREAD_LIBS_INIT "-lcma")\r
+      set(CMAKE_HP_PTHREADS_INIT 1)\r
+      set(Threads_FOUND TRUE)\r
+    endif()\r
+    set(CMAKE_USE_PTHREADS_INIT 1)\r
+  endif()\r
+\r
+  if(CMAKE_SYSTEM MATCHES "OSF1-V*")\r
+    set(CMAKE_USE_PTHREADS_INIT 0)\r
+    set(CMAKE_THREAD_LIBS_INIT )\r
+  endif()\r
+\r
+  if(CMAKE_SYSTEM MATCHES "CYGWIN_NT*")\r
+    set(CMAKE_USE_PTHREADS_INIT 1)\r
+    set(Threads_FOUND TRUE)\r
+    set(CMAKE_THREAD_LIBS_INIT )\r
+    set(CMAKE_USE_WIN32_THREADS_INIT 0)\r
+  endif()\r
+endif()\r
+\r
+include(FindPackageHandleStandardArgs)\r
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Threads DEFAULT_MSG Threads_FOUND)\r