Ensure HAVE_PTHREAD_INIT is set similarly with Autoconf and CMake on MacOSX

This is done by setting HAVE_PTHREAD_INIT with the value
of CMAKE_USE_PTHREADS_INIT. Being itself set by FindThreads module which
checks for the presence of the "pthread_create" symbol.

Before this commit, the macro "check_symbol_exists" was used to check for
the "availability" of the "pthread_init" symbol. The macro was returning
false on both system as expected. Indeed, both system follows the UNIX
specification standard, the "pthread_init" function isn't part of
the documented API. See [1] and [2]

[1] http://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread.h.htmlhttps://www.kernel.org/doc/man-pages/online/pages/man7/pthreads.7.html
[2] https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/pthread.3.html

While the CMake macro was working as expected, the autoconf one is not as
robust and is returning true on MacOSX while false is expected.

Let's try to understand why by looking at the program generated by
both system:

* CMake

 The following code:

   check_symbol_exists(pthread_init "${CFG_HEADERS}" HAVE_PTHREAD_INIT)

 expands to:

   [...]
   #include <pthread.h>
   [...]

   int main(int argc, char* argv[])
   {
   return ((int*)(&pthread_init))[argc];
   }

* Autoconf:

  The following code:

    AC_CHECK_FUNC(pthread_init)

  expands to:

    /* confdefs.h */
    // [...]
    #define HAVE_PTHREAD_H
    // [...]
    /* end confdefs.h.  */

    // [...] Some HP-UX11i related stuff

    /* Override any GCC internal prototype to avoid an error.
       Use char because int might match the return type of a GCC
       builtin and then its argument prototype would still apply.  */
    #ifdef __cplusplus
    extern "C"
    #endif
    char pthread_init ();

    // [...] The GNU C library alias function test.

    int
    main (int argc, char * argv[])
    {
     return pthread_init ();
      ;
      return 0;
    }

In case of the CMake, the test checks that the function is publicly available
and linkable whereas the Autoconf one only verify that it is possible to
resolve the corresponding symbol.

Manually introspecting the system library, I found that

  (1) on MacOSX the libSystemB.dylib has a symbol named "_pthread_init"

  (2) on Linux, the libc exposes has the symbol "__libc_pthread_init".

This can be verified easily using nm.

  nm /usr/lib/libSystemB.dylib | grep pthread_init

                   U __pthread_init

  nm /usr/lib/libpthread.a | grep pthread_init

                   U __libc_pthread_init
                   U __pthread_init_static_tls
  0000000000000000 T __pthread_initialize_minimal
  0000000000000000 T __pthread_initialize_minimal_internal
  00000000000009f0 T __pthread_init_static_tls

Checking the associated source code [3][4] also confirm this.

[3] http://sourceware.org/git/?p=glibc.git;a=blob;f=nptl/pthreadP.h;h=d08b219b5db12f2b51a8579fe7112e1dd18149e9;hb=HEAD#l370
[4] http://www.opensource.apple.com/source/Libc/Libc-825.25/pthreads/pthread.c

This explains why the Autconf test was passing whereas the CMake test was
failing as expected.

As a side note, to be able to obtain the generate code for the autoconf
system, I added the following three line to the "ac_fn_c_check_func"
function in the "configure" script itself.

  echo "=================== " >> check_func.log
  echo "conftest.$ac_ext is " >> check_func.log
  cat conftest.$ac_ext >> check_func.log
  echo "=================== " >> check_func.log

Source: http://stackoverflow.com/questions/7207525/autotools-temporary-files

While investigating the issue, I also found an interesting reading about
symbol interposition:

See  http://stackoverflow.com/questions/11161462/why-glibc-and-pthread-library-both-defined-same-apis

--- cmake/ConfigureChecks.cmake
+++ cmake/ConfigureChecks.cmake
@@ -895,8 +895,11 @@
 set(HAVE_PTHREAD_DESTRUCTOR 0) # for Solaris 2.6
 add_cond(CFG_HEADERS  HAVE_PTHREAD_H  pthread.h)
 add_cond(CMAKE_REQUIRED_LIBRARIES  CMAKE_USE_PTHREADS_INIT  "${CMAKE_THREAD_LIBS_INIT}")
-
-check_symbol_exists(pthread_init "${CFG_HEADERS}" HAVE_PTHREAD_INIT)
+if(APPLE)
+  set(HAVE_PTHREAD_INIT ${CMAKE_USE_PTHREADS_INIT}) # See commit message for explanation.
+else()
+  check_symbol_exists(pthread_init "${CFG_HEADERS}" HAVE_PTHREAD_INIT)
+endif()
 check_symbol_exists(pthread_sigmask "${CFG_HEADERS}" HAVE_PTHREAD_SIGMASK)

 add_cond(CFG_HEADERS  HAVE_SEMAPHORE_H  semaphore.h)


Add macro CheckExternalsPrerequisite

Add macro CheckExternalsPrerequisite

--- cmake/ExternalInclude.cmake
+++ cmake/ExternalInclude.cmake
@@ -42,3 +42,7 @@
 macro(StatusMessage MODULE NAME VAR)
     message(STATUS "${MODULE} Using ${NAME} from ${VAR}")
 endmacro()
+
+macro(CheckExternalsPrerequisite)
+    find_package(Git REQUIRED)
+endmacro()


Added msvc 2015 support in FindOpenCASCADE.cmake

--- cmake/FindOpenCASCADE.cmake
+++ cmake/FindOpenCASCADE.cmake
@@ -39,9 +39,9 @@
   ELSE(UNIX)
     IF (WIN32)
       set( _incsearchpath ${CASROOT}\\inc ${CASROOT}\\include)
-	  set( _testdllname TKernel.dll )
-      set( _libsearchpath ${CASROOT}\\win32\\lib ${CASROOT}\\win${BITS}\\lib ${CASROOT}\\win${BITS}\\vc9\\lib ${CASROOT}\\win${BITS}\\vc10\\lib C:\\OpenCASCADE6.3.0\\ros\\win32\\lib )
-	  set( _dllsearchpath ${CASROOT}\\win32\\bin ${CASROOT}\\win${BITS}\\bin ${CASROOT}\\win${BITS}\\vc9\\bin ${CASROOT}\\win${BITS}\\vc10\\bin C:\\OpenCASCADE6.3.0\\ros\\win32\\bin )
+      set( _testdllname TKernel.dll )
+      set( _libsearchpath ${CASROOT}\\win32\\lib ${CASROOT}\\win${BITS}\\lib ${CASROOT}\\win${BITS}\\vc9\\lib ${CASROOT}\\win${BITS}\\vc10\\lib ${CASROOT}\\win${BITS}\\vc14\\lib)
+      set( _dllsearchpath ${CASROOT}\\win32\\bin ${CASROOT}\\win${BITS}\\bin ${CASROOT}\\win${BITS}\\vc9\\bin ${CASROOT}\\win${BITS}\\vc10\\bin ${CASROOT}\\win${BITS}\\vc14\\bin)
     ELSE(WIN32)
       message( FATAL_ERROR "Unknown system! Exiting." )
     ENDIF (WIN32)


cmake: Commands for clang-[tidy|format]

cmake: Commands for clang-[tidy|format]

--- cmake/clang-cpp-tools.cmake
+++ cmake/clang-cpp-tools.cmake
@@ -2,14 +2,15 @@
 # Additional targets to perform clang-format/clang-tidy
 #

-file(GLOB_RECURSE SOURCE_FILES *.[chi]pp)
+file(GLOB_RECURSE header_files ${PROJECT_SOURCE_DIR}/include/*.hpp)
+file(GLOB_RECURSE source_files ${PROJECT_SOURCE_DIR}/src/*.cpp)

 # Add clang-format target if executable is found
 # --------------------------------------------------
 find_program(CLANG_FORMAT "clang-format")
 if(CLANG_FORMAT)
-  add_custom_target(clang-format COMMAND
-    ${CLANG_FORMAT} -i -style=file ${SOURCE_FILES})
+  add_custom_target(clang-format COMMAND ${CLANG_FORMAT}
+    -i -style=file ${header_files} ${source_files})
 endif()

 # Add clang-tidy target if executable is found
@@ -17,6 +18,5 @@
 find_program(CLANG_TIDY "clang-tidy")
 if(CLANG_TIDY)
   add_custom_target(clang-tidy COMMAND ${CLANG_TIDY}
-    ${SOURCE_FILES} -config='' -- -std=c++11
-    ${INCLUDE_DIRECTORIES})
+    -p ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/src/main.cpp)
 endif()


Sort packages

Sort packages

--- cmake/configs/default.cmake
+++ cmake/configs/default.cmake
@@ -62,11 +62,9 @@
 hunter_config(OpenCV-Extra VERSION 3.0.0)
 hunter_config(OpenSSL VERSION 1.0.2a)
 hunter_config(PNG VERSION 1.6.16-p3)
-hunter_config(rabbitmq-c VERSION 0.7.0-p1)
 hunter_config(RapidJSON VERSION 0.11-hunter)
 hunter_config(Sober VERSION 0.1.2)
 hunter_config(Sources-for-Android-SDK VERSION 21) # API 21
-hunter_config(sparsehash VERSION 2.0.2)
 hunter_config(Sugar VERSION 1.2.2)
 hunter_config(TIFF VERSION 4.0.2-p3)
 hunter_config(Washer VERSION 0.1.2)
@@ -78,4 +76,6 @@
 hunter_config(ios_sim VERSION 3.1.1)
 hunter_config(ippicv VERSION 20141027)
 hunter_config(odb VERSION 2.4.0)
+hunter_config(rabbitmq-c VERSION 0.7.0-p1)
+hunter_config(sparsehash VERSION 2.0.2)
 hunter_config(wxWidgets VERSION 3.0.2)


[CMake] set_target_properties doesn't append link flags

This fixes a bug introduced in r254627, and another occurance of the same bug in this file.

git-svn-id: 0ff597fd157e6f4fc38580e8d64ab130330d2411@254657 91177308-0d34-0410-b5e6-96231b3b80d8

--- cmake/modules/AddLLVM.cmake
+++ cmake/modules/AddLLVM.cmake
@@ -667,7 +667,7 @@
   if (NOT MSVC) # MSVC's linker doesn't support exporting all symbols.
     set_target_properties(${target} PROPERTIES ENABLE_EXPORTS 1)
     if (APPLE)
-      set_target_properties(${target} PROPERTIES
+      set_property(TARGET ${target} APPEND_STRING PROPERTY
         LINK_FLAGS "-rdynamic")
     endif()
   endif()
@@ -1185,8 +1185,8 @@
       OR CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE} MATCHES "-flto")

       set(lto_object ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${name}-lto.o)
-      set_target_properties(${name} PROPERTIES
-        LINK_FLAGS "-Wl,-object_path_lto -Wl,${lto_object}")
+      set_property(TARGET ${name} APPEND_STRING PROPERTY
+        LINK_FLAGS " -Wl,-object_path_lto,${lto_object}")
     endif()
     add_custom_command(TARGET ${name} POST_BUILD
       COMMAND xcrun dsymutil $<TARGET_FILE:${name}>


[CMake] Fix LLVM_ENABLE_EH and LLVM_ENABLE_RTTI on MSVC

Patch by Johannes Sebastian Mueller-Roemer.

Differential Revision: https://reviews.llvm.org/D23645

git-svn-id: 0ff597fd157e6f4fc38580e8d64ab130330d2411@280371 91177308-0d34-0410-b5e6-96231b3b80d8

--- cmake/modules/AddLLVM.cmake
+++ cmake/modules/AddLLVM.cmake
@@ -14,6 +14,9 @@
     if(NOT (LLVM_REQUIRES_RTTI OR LLVM_ENABLE_RTTI))
       message(AUTHOR_WARNING "Exception handling requires RTTI. Enabling RTTI for ${name}")
       set(LLVM_REQUIRES_RTTI ON)
+    endif()
+    if(MSVC)
+      list(APPEND LLVM_COMPILE_FLAGS "/EHsc")
     endif()
   else()
     if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
@@ -35,6 +38,8 @@
     elseif (MSVC)
       list(APPEND LLVM_COMPILE_FLAGS "/GR-")
     endif ()
+  elseif(MSVC)
+    list(APPEND LLVM_COMPILE_FLAGS "/GR")
   endif()

   # Assume that;


remove unneeded file

remove unneeded file

--- cmake/modules/FindKTp.cmake
+++ cmake/modules/FindKTp.cmake
@@ -1,38 +0,0 @@
-# Try to find the KTp library
-# KTP_FOUND
-# KTP_INCLUDE_DIR
-# KTP_LIBRARIES
-# KTP_MODELS_LIBRARIES
-# KTP_WIDGETS_LIBRARIES
-
-# Copyright (c) 2011, Dario Freddi <drf@kde.org>
-#
-# Redistribution and use is allowed according to the terms of the BSD license.
-# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
-
-if (NOT IS_KTP_INTERNAL_MODULE)
-   message (FATAL_ERROR "KTp can be used just from internal components at this time")
-endif (NOT IS_KTP_INTERNAL_MODULE)
-
-SET (KTP_FIND_REQUIRED ${KTp_FIND_REQUIRED})
-if (KTP_INCLUDE_DIRS AND KTP_LIBRARIES)
-  # Already in cache, be silent
-  set(KTP_FIND_QUIETLY TRUE)
-endif (KTP_INCLUDE_DIRS AND KTP_LIBRARIES)
-
-find_path(KTP_INCLUDE_DIR
-  NAMES KTp/presence.h
-  PATHS ${KDE4_INCLUDE_DIR}
-)
-
-find_library(KTP_LIBRARIES NAMES ktpcommoninternalsprivate )
-find_library(KTP_MODELS_LIBRARIES NAMES ktpmodelsprivate )
-find_library(KTP_WIDGETS_LIBRARIES NAMES ktpwidgetsprivate )
-
-include(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(KTp DEFAULT_MSG
-                                  KTP_LIBRARIES
-                                  KTP_MODELS_LIBRARIES
-                                  KTP_INCLUDE_DIR)
-
-mark_as_advanced(KTP_INCLUDE_DIRS KTP_LIBRARIES)


test that the MIC ICC is usable

test that the MIC ICC is usable

--- cmake/FindMIC.cmake
+++ cmake/FindMIC.cmake
@@ -128,13 +128,17 @@
    set(MIC_LIBS ${MIC_IMF_LIBRARY} ${MIC_SVML_LIBRARY} ${MIC_INTLC_LIBRARY})
    set(MIC_CFLAGS "-O2 -vec")

-   exec_program(${MIC_CXX} ARGS -V OUTPUT_VARIABLE _mic_icc_version_string)
-   string(REGEX MATCH "Version (Mainline)?[0-9. a-zA-Z]+" Vc_MIC_ICC_VERSION "${_mic_icc_version_string}")
-   string(SUBSTRING "${Vc_MIC_ICC_VERSION}" 8 -1 Vc_MIC_ICC_VERSION)
-   message(STATUS "MIC ICC Version: \"${Vc_MIC_ICC_VERSION}\"")
-
-   if(MIC_CC AND MIC_CXX AND MIC_IMF_LIBRARY AND MIC_SVML_LIBRARY AND MIC_INTLC_LIBRARY)
-      set(MIC_NATIVE_FOUND true)
+   exec_program(${MIC_CXX} ARGS -V OUTPUT_VARIABLE _mic_icc_version_string RETURN_VALUE _mic_icc_ok)
+   if(0 EQUAL _mic_icc_ok)
+      string(REGEX MATCH "Version (Mainline)?[0-9. a-zA-Z]+" Vc_MIC_ICC_VERSION "${_mic_icc_version_string}")
+      string(SUBSTRING "${Vc_MIC_ICC_VERSION}" 8 -1 Vc_MIC_ICC_VERSION)
+      message(STATUS "MIC ICC Version: \"${Vc_MIC_ICC_VERSION}\"")
+
+      if(MIC_CC AND MIC_CXX AND MIC_IMF_LIBRARY AND MIC_SVML_LIBRARY AND MIC_INTLC_LIBRARY)
+         set(MIC_NATIVE_FOUND true)
+      endif()
+   else()
+      message(STATUS "MIC ICC found, but not usable.")
    endif()
 endif()


added missing closing bracket for _cmakedir_desc in cmake/install.cmake line 88

--- cmake/install.cmake
+++ cmake/install.cmake
@@ -85,7 +85,7 @@
 # Export configuration
 set(_cmakedir_desc "Directory relative to CMAKE_INSTALL to install the cmake configuration files")
 if(NOT MSVC)
-  set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/protobuf" CACHE STRING "${_cmakedir_desc")
+  set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/protobuf" CACHE STRING "${_cmakedir_desc}")
 else()
   set(CMAKE_INSTALL_CMAKEDIR "cmake" CACHE STRING "${_cmakedir_desc}")
 endif()


Updates test discovery step in build (#29)

CMake will run built gtest executables as part of the build in order to
determine the tests in the executable. The default timeout for this run
was 5 seconds but our CI system has been hitting this recently. In order
to accomedating slow VMs in the cloud we are extending the timeout to 60
seconds.

--- cmake/k4aTest.cmake
+++ cmake/k4aTest.cmake
@@ -140,12 +140,20 @@
         list(APPEND GTEST_PROPERTIES "ENVIRONMENT;K4A_ENABLE_LOG_TO_STDOUT=1")
     endif()

+
+    set(TIMEOUT_VAR_NAME "DISCOVERY_TIMEOUT")
+    if ((${CMAKE_VERSION} VERSION_EQUAL "3.10.1") OR (${CMAKE_VERSION} VERSION_EQUAL "3.10.2"))
+        set(TIMEOUT_VAR_NAME "TIMEOUT")
+    endif()
+
     gtest_discover_tests(
         ${K4A_ADD_TESTS_TARGET}
         EXTRA_ARGS
             "--gtest_output=xml:TEST-${K4A_ADD_TESTS_TARGET}.xml"
         WORKING_DIRECTORY
             ${K4A_ADD_TESTS_WORKING_DIRECTORY}
+        ${TIMEOUT_VAR_NAME}
+            60
         PROPERTIES
             "${GTEST_PROPERTIES}")