summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--CMakeLists.txt124
-rw-r--r--cmake/CMakeCXXInformation.cmake300
-rw-r--r--cmake/CheckTypeSize.c.in37
-rw-r--r--cmake/CheckTypeSize.cmake267
-rw-r--r--cmake/FindThreadsCxx.cmake178
-rw-r--r--src/config.h.in31
-rw-r--r--src/gflags.cc22
-rw-r--r--src/gflags.h6
-rw-r--r--src/gflags_declare.h.in116
-rw-r--r--src/gflags_reporting.cc27
-rw-r--r--src/mutex.h14
-rw-r--r--src/util.h22
-rw-r--r--src/windows_port.cc4
-rw-r--r--src/windows_port.h13
-rw-r--r--test/gflags_unittest.cc6
16 files changed, 999 insertions, 169 deletions
diff --git a/.gitignore b/.gitignore
index 163602e..737f962 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,7 +2,6 @@
CMakeCache.txt
DartConfiguration.tcl
Makefile
-*.cmake
CMakeFiles/
/Testing/
/include/gflags/config.h
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 770c284..c90e5b1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,7 +15,7 @@ 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})
+project (${PROJECT_NAME} CXX)
version_numbers (
${PACKAGE_VERSION}
@@ -29,6 +29,13 @@ version_numbers (
option (BUILD_SHARED_LIBS "Request build of shared libraries." OFF)
set (GFLAGS_SHARED_LIBS ${BUILD_SHARED_LIBS})
+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)
@@ -45,54 +52,69 @@ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS AND NOT CMAKE_C_FLAGS)
)
endif ()
+if (APPLE)
+ mark_as_advanced(CMAKE_OSX_ARCHITECTURES
+ CMAKE_OSX_DEPLOYMENT_TARGET
+ CMAKE_OSX_SYSROOT)
+endif ()
+
# ----------------------------------------------------------------------------
# system checks
-include (CheckTypeSize)
-foreach (type IN ITEMS uint16_t u_int16_t __int16)
- CHECK_TYPE_SIZE (${type} SIZE)
- if (SIZE)
- set (HAVE_${type} 1)
+set (GFLAGS_INTTYPES_FORMAT "" CACHE STRING "Format of integer types: \"C99\" (uint32_t), \"BSD\" (u_int32_t), \"VC7\" (__int32)")
+mark_as_advanced(GFLAGS_INTTYPES_FORMAT)
+
+if (NOT GFLAGS_INTTYPES_FORMAT)
+ include (CheckTypeSize)
+ foreach (type IN ITEMS uint32_t u_int32_t __int32)
+ check_type_size (${type} SIZE LANGUAGE CXX)
+ if (SIZE)
+ set (HAVE_${type} TRUE)
+ else ()
+ set (HAVE_${type} FALSE)
+ 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)
+ set (GFLAGS_INTTYPES_FORMAT BSD)
+ elseif (HAVE___int32)
+ set_property (CACHE GFLAGS_INTTYPES_FORMAT PROPERTY VALUE VC7)
else ()
- set (HAVE_${type} 0)
+ 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 ()
-endforeach ()
+endif ()
+
+set ("GFLAGS_INTTYPES_FORMAT_${GFLAGS_INTTYPES_FORMAT}" TRUE)
include (CheckIncludeFileCXX)
-foreach (fname IN ITEMS fnmatch inttypes unistd sys/stat)
+foreach (fname IN ITEMS stdint sys/types fnmatch inttypes unistd sys/stat)
string (TOUPPER "${fname}" FNAME)
string (REGEX REPLACE "/" "_" FNAME "${FNAME}")
- CHECK_INCLUDE_FILE_CXX ("${fname}.h" HAVE_${FNAME}_H)
- if (HAVE_${FNAME}_H)
- set (HAVE_${FNAME}_H 1)
- else ()
- set (HAVE_${FNAME}_H 0)
- endif ()
+ check_include_file_cxx ("${fname}.h" GFLAGS_HAVE_${FNAME}_H)
endforeach ()
-include (CheckSymbolExists)
+include (CheckCxxSymbolExists)
foreach (fname IN ITEMS strtoll strtoq)
string (TOUPPER "${fname}" FNAME)
- CHECK_SYMBOL_EXISTS ("${fname}" stdlib.h HAVE_${FNAME})
- if (HAVE_${FNAME})
- set (HAVE_${FNAME} 1)
- else ()
- set (HAVE_${FNAME} 0)
- endif ()
+ check_cxx_symbol_exists ("${fname}" stdlib.h GFLAGS_HAVE_${FNAME})
endforeach ()
-find_package (Threads)
-if (Threads_FOUND)
- if (CMAKE_USE_PTHREADS_INIT)
- set (HAVE_PTHREAD 1)
- else ()
- set (HAVE_PTHREAD 0)
- endif ()
+set (CMAKE_THREAD_PREFER_PTHREAD TRUE)
+find_package (ThreadsCxx)
+if (Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
+ set (GFLAGS_HAVE_PTHREAD TRUE)
+else ()
+ set (GFLAGS_HAVE_PTHREAD FALSE)
endif ()
-if (BUILD_SHARED_LIBS)
- set (GFLAGS_SHARED 1)
-else ()
- set (GFLAGS_SHARED 0)
+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 ()
# ----------------------------------------------------------------------------
@@ -121,9 +143,9 @@ endif ()
# ----------------------------------------------------------------------------
# configure source files
if (CMAKE_COMPILER_IS_GNUCXX)
- set (__ATTRIBUTE__UNUSED "__attribute((unused))")
+ set (GFLAGS_ATTRIBUTE_UNUSED "__attribute((unused))")
else ()
- set (__ATTRIBUTE__UNUSED)
+ set (GFLAGS_ATTRIBUTE_UNUSED)
endif ()
configure_headers (PUBLIC_HDRS ${PUBLIC_HDRS})
@@ -142,14 +164,22 @@ include_directories ("${PROJECT_SOURCE_DIR}/src")
include_directories ("${PROJECT_BINARY_DIR}/include")
include_directories ("${PROJECT_BINARY_DIR}/include/${GFLAGS_NAMESPACE}")
-add_library (gflags ${GFLAGS_SRCS} ${PRIVATE_HDRS} ${PUBLIC_HDRS})
-add_library (gflags_nothreads ${GFLAGS_SRCS} ${PRIVATE_HDRS} ${PUBLIC_HDRS})
-
-if (WIN32 AND BUILD_SHARED_LIBS)
- set_target_properties (gflags PROPERTIES COMPILE_DEFINITIONS GFLAGS_DLL_EXPORT)
- set_target_properties (gflags_nothreads PROPERTIES COMPILE_DEFINITIONS "GFLAGS_DLL_EXPORT;NO_THREADS")
-else ()
- set_target_properties (gflags_nothreads PROPERTIES COMPILE_DEFINITIONS NO_THREADS)
+set (LIB_TARGETS)
+if (BUILD_gflags_LIB)
+ add_library (gflags ${GFLAGS_SRCS} ${PRIVATE_HDRS} ${PUBLIC_HDRS})
+ if (WIN32 AND BUILD_SHARED_LIBS)
+ set_target_properties (gflags PROPERTIES COMPILE_DEFINITIONS GFLAGS_DLL_EXPORT)
+ endif ()
+ list (APPEND LIB_TARGETS gflags)
+endif ()
+if (BUILD_gflags_nothreads_LIB)
+ add_library (gflags_nothreads ${GFLAGS_SRCS} ${PRIVATE_HDRS} ${PUBLIC_HDRS})
+ if (WIN32 AND BUILD_SHARED_LIBS)
+ set_target_properties (gflags_nothreads PROPERTIES COMPILE_DEFINITIONS "GFLAGS_DLL_EXPORT;NO_THREADS")
+ else ()
+ set_target_properties (gflags_nothreads PROPERTIES COMPILE_DEFINITIONS NO_THREADS)
+ endif ()
+ list (APPEND LIB_TARGETS gflags_nothreads)
endif ()
# ----------------------------------------------------------------------------
@@ -166,8 +196,8 @@ else ()
set (CONFIG_INSTALL_DIR lib/cmake/${PACKAGE_NAME})
endif ()
-install (TARGETS gflags gflags_nothreads DESTINATION ${LIBRARY_INSTALL_DIR} EXPORT gflags-lib)
-install (FILES ${PUBLIC_HDRS} DESTINATION ${INCLUDE_INSTALL_DIR}/${GFLAGS_NAMESPACE})
+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)
@@ -193,7 +223,7 @@ endif ()
# ----------------------------------------------------------------------------
# support direct use of build tree
set (INSTALL_PREFIX_REL2CONFIG_DIR .)
-export (TARGETS gflags gflags_nothreads FILE "${PROJECT_BINARY_DIR}/${PACKAGE_NAME}-export.cmake")
+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)
@@ -203,4 +233,4 @@ include (CTest)
if (BUILD_TESTING)
enable_testing ()
add_subdirectory (test)
-endif () \ No newline at end of file
+endif ()
diff --git a/cmake/CMakeCXXInformation.cmake b/cmake/CMakeCXXInformation.cmake
new file mode 100644
index 0000000..4d0a14a
--- /dev/null
+++ b/cmake/CMakeCXXInformation.cmake
@@ -0,0 +1,300 @@
+# 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
+# <TARGET>
+# <TARGET_BASE> the target without the suffix
+# <OBJECTS>
+# <OBJECT>
+# <LINK_LIBRARIES>
+# <FLAGS>
+# <LINK_FLAGS>
+
+# CXX compiler information
+# <CMAKE_CXX_COMPILER>
+# <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS>
+# <CMAKE_CXX_SHARED_MODULE_CREATE_FLAGS>
+# <CMAKE_CXX_LINK_FLAGS>
+
+# Static library tools
+# <CMAKE_AR>
+# <CMAKE_RANLIB>
+
+
+# create a shared C++ library
+if(NOT CMAKE_CXX_CREATE_SHARED_LIBRARY)
+ set(CMAKE_CXX_CREATE_SHARED_LIBRARY
+ "<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
+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 "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS>")
+endif()
+if(NOT DEFINED CMAKE_CXX_ARCHIVE_APPEND)
+ set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> r <TARGET> <LINK_FLAGS> <OBJECTS>")
+endif()
+if(NOT DEFINED CMAKE_CXX_ARCHIVE_FINISH)
+ set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
+endif()
+
+# compile a C++ file into an object file
+if(NOT CMAKE_CXX_COMPILE_OBJECT)
+ set(CMAKE_CXX_COMPILE_OBJECT
+ "<CMAKE_CXX_COMPILER> <DEFINES> <FLAGS> -o <OBJECT> -c <SOURCE>")
+endif()
+
+if(NOT CMAKE_CXX_LINK_EXECUTABLE)
+ set(CMAKE_CXX_LINK_EXECUTABLE
+ "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
+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/CheckTypeSize.c.in b/cmake/CheckTypeSize.c.in
new file mode 100644
index 0000000..b6c3688
--- /dev/null
+++ b/cmake/CheckTypeSize.c.in
@@ -0,0 +1,37 @@
+@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
new file mode 100644
index 0000000..51be833
--- /dev/null
+++ b/cmake/CheckTypeSize.cmake
@@ -0,0 +1,267 @@
+# Copied from master branch of CMake (commit SHA 34a49dea) and
+# modified to use CheckIncludeFileCXX instead of CheckIncludeFile
+# when the LANGUAGE is CXX.
+
+#.rst:
+# CheckTypeSize
+# -------------
+#
+# Check sizeof a type
+#
+# ::
+#
+# CHECK_TYPE_SIZE(TYPE VARIABLE [BUILTIN_TYPES_ONLY]
+# [LANGUAGE <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:
+#
+# ::
+#
+# <size> = type has non-zero size <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 <sys/types.h>, <stdint.h>, and <stddef.h>, 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_REQUIRED_LIBRARIES = list of libraries to link
+# 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 <sys/types.h>\n")
+ endif()
+ if(HAVE_STDINT_H)
+ set(headers "${headers}#include <stdint.h>\n")
+ endif()
+ if(HAVE_STDDEF_H)
+ set(headers "${headers}#include <stddef.h>\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}
+ LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}
+ 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/FindThreadsCxx.cmake b/cmake/FindThreadsCxx.cmake
new file mode 100644
index 0000000..0e33bf9
--- /dev/null
+++ b/cmake/FindThreadsCxx.cmake
@@ -0,0 +1,178 @@
+#.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 (CheckLibraryExists)
+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_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_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_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")
+ try_run(THREADS_PTHREAD_ARG THREADS_HAVE_PTHREAD_ARG
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_ROOT}/Modules/CheckForPthreads.c
+ 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_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)
diff --git a/src/config.h.in b/src/config.h.in
index 33987f9..ed254fe 100644
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -2,6 +2,8 @@
// Note: This header file is only used internally. It is not part of public interface!
+#include "gflags_declare.h" // system checks
+
// ---------------------------------------------------------------------------
// Additional meta-information
@@ -27,35 +29,6 @@
#define PACKAGE_BUGREPORT @PACKAGE_BUGREPORT@
// ---------------------------------------------------------------------------
-// Available system headers
-
-// Define to 1 if you have the <fnmatch.h> header file.
-#define HAVE_FNMATCH_H @HAVE_FNMATCH_H@
-
-// Define to 1 if you have the <inttypes.h> header file.
-#define HAVE_INTTYPES_H @HAVE_INTTYPES_H@
-
-// Define to 1 if you have the <unistd.h> header file.
-#define HAVE_UNISTD_H @HAVE_UNISTD_H@
-
-// Define to 1 if you have the <sys/stat.h> header file.
-#define HAVE_SYS_STAT_H @HAVE_SYS_STAT_H@
-
-// Define to 1 if you have the strtoll function.
-#define HAVE_STRTOLL @HAVE_STRTOLL@
-
-// Define to 1 if you have the strtoq function.
-#define HAVE_STRTOQ @HAVE_STRTOQ@
-
-// Define to 1 if you have the <pthread.h> header file.
-#define HAVE_PTHREAD @HAVE_PTHREAD@
-
-// gcc requires this to get PRId64, etc.
-#if HAVE_INTTYPES_H && !defined(__STDC_FORMAT_MACROS)
-# define __STDC_FORMAT_MACROS 1
-#endif
-
-// ---------------------------------------------------------------------------
// Path separator
#define PATH_SEPARATOR '/'
diff --git a/src/gflags.cc b/src/gflags.cc
index b273ddc..0e6ea7d 100644
--- a/src/gflags.cc
+++ b/src/gflags.cc
@@ -93,7 +93,7 @@
#include <assert.h>
#include <ctype.h>
#include <errno.h>
-#if HAVE_FNMATCH_H
+#ifdef HAVE_FNMATCH_H
# include <fnmatch.h>
#endif
#include <stdarg.h> // For va_list and related operations
@@ -111,20 +111,16 @@
// Special flags, type 1: the 'recursive' flags. They set another flag's val.
-DEFINE_string(flagfile, "",
- "load flags from file");
-DEFINE_string(fromenv, "",
- "set flags from the environment"
- " [use 'export FLAGS_flag1=value']");
-DEFINE_string(tryfromenv, "",
- "set flags from the environment if present");
+DEFINE_string(flagfile, "", "load flags from file");
+DEFINE_string(fromenv, "", "set flags from the environment"
+ " [use 'export FLAGS_flag1=value']");
+DEFINE_string(tryfromenv, "", "set flags from the environment if present");
// Special flags, type 2: the 'parsing' flags. They modify how we parse.
-DEFINE_string(undefok, "",
- "comma-separated list of flag names that it is okay to specify "
- "on the command line even if the program does not define a flag "
- "with that name. IMPORTANT: flags in this list that have "
- "arguments MUST use the flag=value format");
+DEFINE_string(undefok, "", "comma-separated list of flag names that it is okay to specify "
+ "on the command line even if the program does not define a flag "
+ "with that name. IMPORTANT: flags in this list that have "
+ "arguments MUST use the flag=value format");
namespace GFLAGS_NAMESPACE {
diff --git a/src/gflags.h b/src/gflags.h
index 3a16777..41f53d9 100644
--- a/src/gflags.h
+++ b/src/gflags.h
@@ -270,8 +270,8 @@ extern std::string SetCommandLineOptionWithMode(const char* name, const char* va
// // without worrying about restoring the FLAG values.
// }
//
-// Note: This class is marked with ATTRIBUTE_UNUSED because all the
-// work is done in the constructor and destructor, so in the standard
+// Note: This class is marked with GFLAGS_ATTRIBUTE_UNUSED because all
+// the work is done in the constructor and destructor, so in the standard
// usage example above, the compiler would complain that it's an
// unused variable.
//
@@ -291,7 +291,7 @@ class GFLAGS_DLL_DECL FlagSaver {
FlagSaver(const FlagSaver&); // no copying!
void operator=(const FlagSaver&);
}
-GFLAGS__ATTRIBUTE__UNUSED;
+GFLAGS_ATTRIBUTE_UNUSED;
// --------------------------------------------------------------------
// Some deprecated or hopefully-soon-to-be-deprecated functions.
diff --git a/src/gflags_declare.h.in b/src/gflags_declare.h.in
index 7141e99..2a25f1d 100644
--- a/src/gflags_declare.h.in
+++ b/src/gflags_declare.h.in
@@ -56,7 +56,7 @@
// ---------------------------------------------------------------------------
// Unused attribute declaration for GNU GCC.
-#define GFLAGS__ATTRIBUTE__UNUSED @GFLAGS__ATTRIBUTE_UNUSED@
+#define GFLAGS_ATTRIBUTE_UNUSED @GFLAGS_ATTRIBUTE_UNUSED@
// ---------------------------------------------------------------------------
// Windows DLL import/export.
@@ -97,32 +97,102 @@
#endif
// ---------------------------------------------------------------------------
-// Types
-#include <string>
-#if @HAVE_STDINT_H@
-# include <stdint.h> // the normal place uint16_t is defined
+// Available system headers
+
+// Define if you have the <stdint.h> header file.
+#cmakedefine GFLAGS_HAVE_STDINT_H
+
+// Define if you have the <sys/types.h> header file.
+#cmakedefine GFLAGS_HAVE_SYS_TYPES_H
+
+// Define if you have the <inttypes.h> header file.
+#cmakedefine GFLAGS_HAVE_INTTYPES_H
+
+// Define if you have the <sys/stat.h> header file.
+#cmakedefine GFLAGS_HAVE_SYS_STAT_H
+
+// Define if you have the <unistd.h> header file.
+#cmakedefine GFLAGS_HAVE_UNISTD_H
+
+// Define if you have the <fnmatch.h> header file.
+#cmakedefine GFLAGS_HAVE_FNMATCH_H
+
+// Define if you have the strtoll function.
+#cmakedefine GFLAGS_HAVE_STRTOLL
+
+// Define if you have the strtoq function.
+#cmakedefine GFLAGS_HAVE_STRTOQ
+
+// Define if you have the <pthread.h> header file.
+#cmakedefine GFLAGS_HAVE_PTHREAD
+
+// Backwards compatibility in case users defined these macros themselves
+// or allow users to use these more general macros if the gflags library
+// is build as part of a user project, e.g., included as Git submodule
+#if defined(HAVE_STDINT_H) && !defined(GFLAGS_HAVE_STDINT_H)
+# define GFLAGS_HAVE_STDINT_H
+#endif
+#if defined(HAVE_SYS_TYPES_H) && !defined(GFLAGS_HAVE_SYS_TYPES_H)
+# define GFLAGS_HAVE_SYS_TYPES_H
#endif
-#if @HAVE_SYS_TYPES_H@
-# include <sys/types.h> // the normal place u_int16_t is defined
+#if defined(HAVE_INTTYPES_H) && !defined(GFLAGS_HAVE_INTTYPES_H)
+# define GFLAGS_HAVE_INTTYPES_H
#endif
-#if @HAVE_INTTYPES_H@
-# include <inttypes.h> // a third place for uint16_t or u_int16_t
+#if defined(HAVE_SYS_STAT_H) && !defined(GFLAGS_HAVE_SYS_STAT_H)
+# define GFLAGS_HAVE_SYS_STAT_H
+#endif
+#if defined(HAVE_UNISTD_H) && !defined(GFLAGS_HAVE_UNISTD_H)
+# define GFLAGS_HAVE_UNISTD_H
+#endif
+#if defined(HAVE_FNMATCH_H) && !defined(GFLAGS_HAVE_FNMATCH_H)
+# define GFLAGS_HAVE_FNMATCH_H
+#endif
+#if defined(HAVE_STRTOLL) && !defined(GFLAGS_HAVE_STRTOLL)
+# define GFLAGS_HAVE_STRTOLL
+#endif
+#if defined(HAVE_STRTOLQ) && !defined(GFLAGS_HAVE_STRTOLQ)
+# define GFLAGS_HAVE_STRTOLQ
+#endif
+#if defined(HAVE_PTHREAD) && !defined(GFLAGS_HAVE_PTHREAD)
+# define GFLAGS_HAVE_PTHREAD
+#endif
+#if defined(HAVE_RWLOCK) && !defined(GFLAGS_HAVE_RWLOCK)
+# define GFLAGS_HAVE_RWLOCK
+#endif
+
+// gcc requires this to get PRId64, etc.
+#if defined(GFLAGS_HAVE_INTTYPES_H) && !defined(__STDC_FORMAT_MACROS)
+# define __STDC_FORMAT_MACROS 1
+#endif
+
+// ---------------------------------------------------------------------------
+// Flag types
+#include <string>
+#if defined(GFLAGS_HAVE_STDINT_H)
+# include <stdint.h> // the normal place uint32_t is defined
+#elif defined(GFLAGS_HAVE_SYS_TYPES_H)
+# include <sys/types.h> // the normal place u_int32_t is defined
+#elif defined(GFLAGS_HAVE_INTTYPES_H)
+# include <inttypes.h> // a third place for uint32_t or u_int32_t
#endif
+#cmakedefine GFLAGS_INTTYPES_FORMAT_C99
+#cmakedefine GFLAGS_INTTYPES_FORMAT_BSD
+#cmakedefine GFLAGS_INTTYPES_FORMAT_VC7
namespace GFLAGS_NAMESPACE {
-#if @HAVE_uint16_t@ // the C99 format
-typedef int32_t int32;
-typedef uint32_t uint32;
-typedef int64_t int64;
-typedef uint64_t uint64;
-#elif @HAVE_u_int16_t@ // the BSD format
-typedef int32_t int32;
-typedef u_int32_t uint32;
-typedef int64_t int64;
-typedef u_int64_t uint64;
-#elif @HAVE___int16@ // the windows (vc7) format
+#if defined(GFLAGS_INTTYPES_FORMAT_C99)
+typedef int32_t int32;
+typedef uint32_t uint32;
+typedef int64_t int64;
+typedef uint64_t uint64;
+#elif defined(GFLAGS_INTTYPES_FORMAT_BSD)
+typedef int32_t int32;
+typedef u_int32_t uint32;
+typedef int64_t int64;
+typedef u_int64_t uint64;
+#elif defined(GFLAGS_INTTYPES_FORMAT_VC7) // Windows
typedef __int32 int32;
typedef unsigned __int32 uint32;
typedef __int64 int64;
@@ -154,13 +224,13 @@ typedef std::string clstring;
DECLARE_VARIABLE(bool, B, name)
#define DECLARE_int32(name) \
- DECLARE_VARIABLE(@ac_google_namespace@::int32, I, name)
+ DECLARE_VARIABLE(GFLAGS_NAMESPACE::int32, I, name)
#define DECLARE_int64(name) \
- DECLARE_VARIABLE(@ac_google_namespace@::int64, I64, name)
+ DECLARE_VARIABLE(GFLAGS_NAMESPACE::int64, I64, name)
#define DECLARE_uint64(name) \
- DECLARE_VARIABLE(@ac_google_namespace@::uint64, U64, name)
+ DECLARE_VARIABLE(GFLAGS_NAMESPACE::uint64, U64, name)
#define DECLARE_double(name) \
DECLARE_VARIABLE(double, D, name)
diff --git a/src/gflags_reporting.cc b/src/gflags_reporting.cc
index 595af97..a33c553 100644
--- a/src/gflags_reporting.cc
+++ b/src/gflags_reporting.cc
@@ -48,8 +48,6 @@
// called after all flag-values have been assigned, that is, after
// parsing the command-line.
-#include "config.h"
-
#include <stdio.h>
#include <string.h>
#include <ctype.h>
@@ -57,28 +55,21 @@
#include <string>
#include <vector>
+#include "config.h"
#include "gflags.h"
#include "gflags_completions.h"
#include "util.h"
// The 'reporting' flags. They all call gflags_exitfunc().
-DEFINE_bool(help, false,
- "show help on all flags [tip: all flags can have two dashes]");
-DEFINE_bool(helpfull, false,
- "show help on all flags -- same as -help");
-DEFINE_bool(helpshort, false,
- "show help on only the main module for this program");
-DEFINE_string(helpon, "",
- "show help on the modules named by this flag value");
-DEFINE_string(helpmatch, "",
- "show help on modules whose name contains the specified substr");
-DEFINE_bool(helppackage, false,
- "show help on all modules in the main package");
-DEFINE_bool(helpxml, false,
- "produce an xml version of help");
-DEFINE_bool(version, false,
- "show version and build info and exit");
+DEFINE_bool (help, false, "show help on all flags [tip: all flags can have two dashes]");
+DEFINE_bool (helpfull, false, "show help on all flags -- same as -help");
+DEFINE_bool (helpshort, false, "show help on only the main module for this program");
+DEFINE_string(helpon, "", "show help on the modules named by this flag value");
+DEFINE_string(helpmatch, "", "show help on modules whose name contains the specified substr");
+DEFINE_bool (helppackage, false, "show help on all modules in the main package");
+DEFINE_bool (helpxml, false, "produce an xml version of help");
+DEFINE_bool (version, false, "show version and build info and exit");
namespace GFLAGS_NAMESPACE {
diff --git a/src/mutex.h b/src/mutex.h
index cfca32f..3b27f84 100644
--- a/src/mutex.h
+++ b/src/mutex.h
@@ -106,10 +106,10 @@
#ifndef GFLAGS_MUTEX_H_
#define GFLAGS_MUTEX_H_
-#include "config.h" // to figure out pthreads support
+#include "gflags_declare.h" // to figure out pthreads support
#if defined(NO_THREADS)
- typedef int MutexType; // to keep a lock-count
+ typedef int MutexType; // to keep a lock-count
#elif defined(_WIN32) || defined(__CYGWIN32__) || defined(__CYGWIN64__)
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN // We only need minimal includes
@@ -127,9 +127,9 @@
# endif
# include <windows.h>
typedef CRITICAL_SECTION MutexType;
-#elif defined(HAVE_PTHREAD) && defined(HAVE_RWLOCK)
+#elif defined(GFLAGS_HAVE_PTHREAD) && defined(GFLAGS_HAVE_RWLOCK)
// Needed for pthread_rwlock_*. If it causes problems, you could take it
- // out, but then you'd have to unset HAVE_RWLOCK (at least on linux -- it
+ // out, but then you'd have to unset GFLAGS_HAVE_RWLOCK (at least on linux -- it
// *does* cause problems for FreeBSD, or MacOSX, but isn't needed
// for locking there.)
# ifdef __linux__
@@ -140,7 +140,7 @@
# endif
# include <pthread.h>
typedef pthread_rwlock_t MutexType;
-#elif HAVE_PTHREAD
+#elif defined(GFLAGS_HAVE_PTHREAD)
# include <pthread.h>
typedef pthread_mutex_t MutexType;
#else
@@ -247,7 +247,7 @@ bool Mutex::TryLock() { return is_safe_ ?
void Mutex::ReaderLock() { Lock(); } // we don't have read-write locks
void Mutex::ReaderUnlock() { Unlock(); }
-#elif defined(HAVE_PTHREAD) && defined(HAVE_RWLOCK)
+#elif defined(GFLAGS_HAVE_PTHREAD) && defined(GFLAGS_HAVE_RWLOCK)
#define SAFE_PTHREAD(fncall) do { /* run fncall if is_safe_ is true */ \
if (is_safe_ && fncall(&mutex_) != 0) abort(); \
@@ -272,7 +272,7 @@ void Mutex::ReaderLock() { SAFE_PTHREAD(pthread_rwlock_rdlock); }
void Mutex::ReaderUnlock() { SAFE_PTHREAD(pthread_rwlock_unlock); }
#undef SAFE_PTHREAD
-#elif defined(HAVE_PTHREAD)
+#elif defined(GFLAGS_HAVE_PTHREAD)
#define SAFE_PTHREAD(fncall) do { /* run fncall if is_safe_ is true */ \
if (is_safe_ && fncall(&mutex_) != 0) abort(); \
diff --git a/src/util.h b/src/util.h
index caa50cf..9d6f8dc 100644
--- a/src/util.h
+++ b/src/util.h
@@ -38,7 +38,7 @@
#include <assert.h>
#include <config.h>
-#if HAVE_INTTYPES_H
+#ifdef GFLAGS_HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#include <stdarg.h> // for va_*
@@ -46,9 +46,9 @@
#include <stdio.h>
#include <iostream>
#include <string>
-#if HAVE_SYS_STAT_H
-# include <sys/stat.h>
-#endif // for mkdir()
+#ifdef GFLAGS_HAVE_SYS_STAT_H
+# include <sys/stat.h> // for mkdir
+#endif
namespace GFLAGS_NAMESPACE {
@@ -58,20 +58,20 @@ namespace GFLAGS_NAMESPACE {
extern GFLAGS_DLL_DECL void (*gflags_exitfunc)(int);
// Work properly if either strtoll or strtoq is on this system
-#if HAVE_STRTOLL
+#if defined(GFLAGS_HAVE_STRTOLL)
# define strto64 strtoll
-# define strtou64 strtoull
-#elif HAVE_STRTOQ
+# define strtou64 strtoull
+#elif defined(GFLAGS_HAVE_STRTOQ)
# define strto64 strtoq
-# define strtou64 strtouq
+# define strtou64 strtouq
#else
// Neither strtoll nor strtoq are defined. I hope strtol works!
-# define strto64 strtol
+# define strto64 strtol
# define strtou64 strtoul
#endif
-// If we have inttypes.h, it will have defined PRId32/etc for us. If
-// not, take our best guess.
+// If we have inttypes.h, it will have defined PRId32/etc for us.
+// If not, take our best guess.
#ifndef PRId32
# define PRId32 "d"
#endif
diff --git a/src/windows_port.cc b/src/windows_port.cc
index d122673..5511f8d 100644
--- a/src/windows_port.cc
+++ b/src/windows_port.cc
@@ -32,14 +32,14 @@
*/
#ifndef _WIN32
-# error You should only be including windows/port.cc in a windows environment!
+# error You should only be including windows/port.cc in a windows environment!
#endif
-#include <config.h>
#include <string.h> // for strlen(), memset(), memcmp()
#include <assert.h>
#include <stdarg.h> // for va_list, va_start, va_end
#include <windows.h>
+
#include "windows_port.h"
// These call the windows _vsnprintf, but always NUL-terminate.
diff --git a/src/windows_port.h b/src/windows_port.h
index 8a0e49b..6da8796 100644
--- a/src/windows_port.h
+++ b/src/windows_port.h
@@ -40,18 +40,7 @@
#ifndef GFLAGS_WINDOWS_PORT_H_
#define GFLAGS_WINDOWS_PORT_H_
-#ifndef GFLAGS_DLL_DECL
-# if defined(_MSC_VER) && defined(GFLAGS_SHARED_LIBS)
-# ifdef GFLAGS_DLL_EXPORT
-# define GFLAGS_DLL_DECL __declspec(dllexport)
-# else
-# define GFLAGS_DLL_DECL __declspec(dllimport)
-# endif
-# else
-# define GFLAGS_DLL_DECL
-# endif
-#endif
-
+#include "config.h"
#ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN /* We always want minimal includes */
diff --git a/test/gflags_unittest.cc b/test/gflags_unittest.cc
index a2a033a..5604cb1 100644
--- a/test/gflags_unittest.cc
+++ b/test/gflags_unittest.cc
@@ -39,9 +39,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#if HAVE_UNISTD_H
-# include <unistd.h>
-#endif // for unlink()
+#ifdef GFLAGS_HAVE_UNISTD_H
+# include <unistd.h> // for unlink()
+#endif
#include <vector>
#include <string>
#include "util.h"