Prevent compile errors on OSX (#198)

build CHANGE prevent compile errors on OSX

* Prevent compile errors on OSX

clangtidy cmake files too
fix possible buffer overflow too

* Fix travis build error

The imported include path setting is only later needed!

* Fix libssh version detection

Cmake variable is now LIBSSH_VERSION!

* python: do not put generated files into the source tree

Untracked content shows up in git submodules, causing stuff to be marked
"dirty" by various git-level tools.

Tested by temporarily putting the resulting target within `ALL`. The
result is the same as without this change (and it remains unusable with
no generated index, at least when building out-of-tree, BTW).

* apply review  notes

* Prevent compile errors on OSX

clangtidy cmake files too
fix possible buffer overflow too

* Fix travis build error

The imported include path setting is only later needed!

* Fix libssh version detection

Cmake variable is now LIBSSH_VERSION!

* apply review  notes

Co-authored-by: Jan Kundrát <jkt@flaska.net>
diff --git a/CMakeModules/FindCMocka.cmake b/CMakeModules/FindCMocka.cmake
index 2dd9fc5..c8bd26f 100644
--- a/CMakeModules/FindCMocka.cmake
+++ b/CMakeModules/FindCMocka.cmake
@@ -35,15 +35,15 @@
         ${CMOCKA_ROOT_DIR}/include
 )
 
-if (CMOCKA_LIBRARY)
+if(CMOCKA_LIBRARY)
   set(CMOCKA_LIBRARIES
       ${CMOCKA_LIBRARIES}
       ${CMOCKA_LIBRARY}
   )
-endif (CMOCKA_LIBRARY)
+endif()
 
 include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(CMocka DEFAULT_MSG CMOCKA_LIBRARIES CMOCKA_INCLUDE_DIR)
+find_package_handle_standard_args(CMOCKA DEFAULT_MSG CMOCKA_LIBRARIES CMOCKA_INCLUDE_DIR)
 
 # show the CMOCKA_INCLUDE_DIR and CMOCKA_LIBRARIES variables only in the advanced view
 mark_as_advanced(CMOCKA_INCLUDE_DIR CMOCKA_LIBRARIES)
diff --git a/CMakeModules/FindLibSSH.cmake b/CMakeModules/FindLibSSH.cmake
index 49737ff..7e5fa33 100644
--- a/CMakeModules/FindLibSSH.cmake
+++ b/CMakeModules/FindLibSSH.cmake
@@ -31,10 +31,10 @@
 #  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
 
-if (LIBSSH_LIBRARY_DIR AND LIBSSH_INCLUDE_DIRS)
+if(LIBSSH_LIBRARY_DIR AND LIBSSH_INCLUDE_DIRS)
   # in cache already
   set(LIBSSH_FOUND TRUE)
-else (LIBSSH_LIBRARY_DIR AND LIBSSH_INCLUDE_DIRS)
+else()
 
   find_path(LIBSSH_INCLUDE_DIR
     NAMES
@@ -48,10 +48,11 @@
       ${CMAKE_INSTALL_PREFIX}/include
   )
 
-  find_library(SSH_LIBRARY
+  find_library(LIBSSH_LIBRARY
     NAMES
       ssh.so
       libssh.so
+      libssh.dylib
     PATHS
       /usr/lib
       /usr/local/lib
@@ -61,58 +62,63 @@
       ${CMAKE_INSTALL_PREFIX}/lib
   )
 
-  if (LIBSSH_INCLUDE_DIR AND SSH_LIBRARY)
-    set(SSH_FOUND TRUE)
-  endif (LIBSSH_INCLUDE_DIR AND SSH_LIBRARY)
+  if(LIBSSH_INCLUDE_DIR AND LIBSSH_LIBRARY)
+    set(LIBSSH_FOUND TRUE)
+    message(STATUS "LIBSSH Found: ${LIBSSH_LIBRARY}")
+  endif()
 
-  set(LIBSSH_INCLUDE_DIRS
-    ${LIBSSH_INCLUDE_DIR}
-  )
+  set(LIBSSH_INCLUDE_DIRS ${LIBSSH_INCLUDE_DIR})
+  message(STATUS "LIBSSH_INCLUDE_DIR: ${LIBSSH_INCLUDE_DIR}")
 
-  if (SSH_FOUND)
+  if(LIBSSH_FOUND)
     string(REPLACE "libssh.so" ""
       LIBSSH_LIBRARY_DIR
-      ${SSH_LIBRARY}
+      ${LIBSSH_LIBRARY}
+    )
+    string(REPLACE "libssh.dylib" ""
+      LIBSSH_LIBRARY_DIR
+      ${LIBSSH_LIBRARY_DIR}
     )
     string(REPLACE "ssh.so" ""
       LIBSSH_LIBRARY_DIR
       ${LIBSSH_LIBRARY_DIR}
     )
+    message(STATUS "LIBSSH_LIBRARY_DIR: ${LIBSSH_LIBRARY_DIR}")
 
-    if (LibSSH_FIND_VERSION)
+    if(LIBSSH_FIND_VERSION)
       file(STRINGS ${LIBSSH_INCLUDE_DIR}/libssh/libssh.h LIBSSH_VERSION_MAJOR
         REGEX "#define[ ]+LIBSSH_VERSION_MAJOR[ ]+[0-9]+")
       # Older versions of libssh like libssh-0.2 have LIBSSH_VERSION but not LIBSSH_VERSION_MAJOR
-      if (LIBSSH_VERSION_MAJOR)
+      if(LIBSSH_VERSION_MAJOR)
         string(REGEX MATCH "[0-9]+" LIBSSH_VERSION_MAJOR ${LIBSSH_VERSION_MAJOR})
-	file(STRINGS ${LIBSSH_INCLUDE_DIR}/libssh/libssh.h LIBSSH_VERSION_MINOR
+        file(STRINGS ${LIBSSH_INCLUDE_DIR}/libssh/libssh.h LIBSSH_VERSION_MINOR
           REGEX "#define[ ]+LIBSSH_VERSION_MINOR[ ]+[0-9]+")
-	string(REGEX MATCH "[0-9]+" LIBSSH_VERSION_MINOR ${LIBSSH_VERSION_MINOR})
-	file(STRINGS ${LIBSSH_INCLUDE_DIR}/libssh/libssh.h LIBSSH_VERSION_PATCH
+        string(REGEX MATCH "[0-9]+" LIBSSH_VERSION_MINOR ${LIBSSH_VERSION_MINOR})
+        file(STRINGS ${LIBSSH_INCLUDE_DIR}/libssh/libssh.h LIBSSH_VERSION_PATCH
           REGEX "#define[ ]+LIBSSH_VERSION_MICRO[ ]+[0-9]+")
-	string(REGEX MATCH "[0-9]+" LIBSSH_VERSION_PATCH ${LIBSSH_VERSION_PATCH})
+        string(REGEX MATCH "[0-9]+" LIBSSH_VERSION_PATCH ${LIBSSH_VERSION_PATCH})
 
-	set(LibSSH_VERSION ${LIBSSH_VERSION_MAJOR}.${LIBSSH_VERSION_MINOR}.${LIBSSH_VERSION_PATCH})
+        set(LIBSSH_VERSION ${LIBSSH_VERSION_MAJOR}.${LIBSSH_VERSION_MINOR}.${LIBSSH_VERSION_PATCH})
 
-	include(FindPackageVersionCheck)
-	find_package_version_check(LibSSH DEFAULT_MSG)
-      else (LIBSSH_VERSION_MAJOR)
+        include(FindPackageVersionCheck)
+        find_package_version_check(LIBSSH DEFAULT_MSG)
+      else()
         message(STATUS "LIBSSH_VERSION_MAJOR not found in ${LIBSSH_INCLUDE_DIR}/libssh/libssh.h, assuming libssh is too old")
         set(LIBSSH_FOUND FALSE)
-      endif (LIBSSH_VERSION_MAJOR)
-    endif (LibSSH_FIND_VERSION)
-  endif (SSH_FOUND)
+      endif()
+    endif()
+  endif()
 
   # If the version is too old, but libs and includes are set,
   # find_package_handle_standard_args will set LIBSSH_FOUND to TRUE again,
   # so we need this if() here.
-  if (LIBSSH_FOUND)
+  if(LIBSSH_FOUND)
     include(FindPackageHandleStandardArgs)
-    find_package_handle_standard_args(LibSSH DEFAULT_MSG LIBSSH_LIBRARY_DIR LIBSSH_INCLUDE_DIRS)
-  endif (LIBSSH_FOUND)
+    find_package_handle_standard_args(LIBSSH DEFAULT_MSG LIBSSH_LIBRARY_DIR LIBSSH_INCLUDE_DIRS)
+  endif()
 
   # show the LIBSSH_INCLUDE_DIRS and LIBSSH_LIBRARY_DIR variables only in the advanced view
   mark_as_advanced(LIBSSH_INCLUDE_DIRS LIBSSH_LIBRARY_DIR)
 
-endif (LIBSSH_LIBRARY_DIR AND LIBSSH_INCLUDE_DIRS)
+endif()
 
diff --git a/CMakeModules/FindLibVAL.cmake b/CMakeModules/FindLibVAL.cmake
index 507bf8a..57d7db8 100644
--- a/CMakeModules/FindLibVAL.cmake
+++ b/CMakeModules/FindLibVAL.cmake
@@ -32,10 +32,10 @@
 #  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
 
-if (LIBVAL_LIBRARIES AND LIBVAL_INCLUDE_DIRS)
+if(LIBVAL_LIBRARIES AND LIBVAL_INCLUDE_DIRS)
   # in cache already
   set(LIBVAL_FOUND TRUE)
-else (LIBVAL_LIBRARIES AND LIBVAL_INCLUDE_DIRS)
+else()
 
   find_path(LIBVAL_INCLUDE_DIR
     NAMES
@@ -83,17 +83,20 @@
       ${CMAKE_INSTALL_PREFIX}/lib
   )
 
-  if (LIBVAL_INCLUDE_DIR AND LIBVAL_LIBRARY AND LIBSRES_LIBRARY)
+  if(LIBVAL_INCLUDE_DIR AND LIBVAL_LIBRARY AND LIBSRES_LIBRARY)
     set(LIBVAL_FOUND TRUE)
-  else (LIBVAL_INCLUDE_DIR AND LIBVAL_LIBRARY AND LIBSRES_LIBRARY)
+  else()
     set(LIBVAL_FOUND FALSE)
-  endif (LIBVAL_INCLUDE_DIR AND LIBVAL_LIBRARY AND LIBSRES_LIBRARY)
+  endif()
 
   set(LIBVAL_INCLUDE_DIRS ${LIBVAL_INCLUDE_DIR})
   set(LIBVAL_LIBRARIES ${LIBSRES_LIBRARY} ${LIBVAL_LIBRARY})
 
+  include(FindPackageHandleStandardArgs)
+  find_package_handle_standard_args(LIBVAL DEFAULT_MSG LIBVAL_LIBRARIES LIBVAL_INCLUDE_DIRS)
+
   # show the LIBVAL_INCLUDE_DIRS and LIBVAL_LIBRARIES variables only in the advanced view
   mark_as_advanced(LIBVAL_INCLUDE_DIRS LIBVAL_LIBRARIES)
 
-endif (LIBVAL_LIBRARIES AND LIBVAL_INCLUDE_DIRS)
+endif()
 
diff --git a/CMakeModules/FindLibYANG.cmake b/CMakeModules/FindLibYANG.cmake
index b3478b1..51fdc88 100644
--- a/CMakeModules/FindLibYANG.cmake
+++ b/CMakeModules/FindLibYANG.cmake
@@ -3,7 +3,7 @@
 #
 #  LIBYANG_FOUND - system has LibYANG
 #  LIBYANG_INCLUDE_DIRS - the LibYANG include directory
-#  LIBYANG_LIBRARIES - Link these to use LibSSH
+#  LIBYANG_LIBRARIES - Link these to use LibYANG
 #
 #  Author Radek Krejci <rkrejci@cesnet.cz>
 #  Copyright (c) 2015 CESNET, z.s.p.o.
@@ -17,7 +17,7 @@
 #  2. Redistributions in binary form must reproduce the copyright
 #     notice, this list of conditions and the following disclaimer in the
 #     documentation and/or other materials provided with the distribution.
-#  3. The name of the author may not be used to endorse or promote products 
+#  3. The name of the author may not be used to endorse or promote products
 #     derived from this software without specific prior written permission.
 #
 #  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
@@ -32,10 +32,10 @@
 #  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
 
-if (LIBYANG_LIBRARIES AND LIBYANG_INCLUDE_DIRS)
+if(LIBYANG_LIBRARIES AND LIBYANG_INCLUDE_DIRS)
   # in cache already
   set(LIBYANG_FOUND TRUE)
-else (LIBYANG_LIBRARIES AND LIBYANG_INCLUDE_DIRS)
+else()
 
   find_path(LIBYANG_INCLUDE_DIR
     NAMES
@@ -48,7 +48,7 @@
       ${CMAKE_INCLUDE_PATH}
       ${CMAKE_INSTALL_PREFIX}/include
   )
-  
+
   find_library(LIBYANG_LIBRARY
     NAMES
       yang
@@ -64,17 +64,20 @@
       ${CMAKE_INSTALL_PREFIX}/lib
   )
 
-  if (LIBYANG_INCLUDE_DIR AND LIBYANG_LIBRARY)
+  if(LIBYANG_INCLUDE_DIR AND LIBYANG_LIBRARY)
     set(LIBYANG_FOUND TRUE)
-  else (LIBYANG_INCLUDE_DIR AND LIBYANG_LIBRARY)
+  else()
     set(LIBYANG_FOUND FALSE)
-  endif (LIBYANG_INCLUDE_DIR AND LIBYANG_LIBRARY)
+  endif()
 
   set(LIBYANG_INCLUDE_DIRS ${LIBYANG_INCLUDE_DIR})
   set(LIBYANG_LIBRARIES ${LIBYANG_LIBRARY})
 
+  include(FindPackageHandleStandardArgs)
+  find_package_handle_standard_args(LIBYANG DEFAULT_MSG LIBYANG_LIBRARIES LIBYANG_INCLUDE_DIRS)
+
   # show the LIBYANG_INCLUDE_DIRS and LIBYANG_LIBRARIES variables only in the advanced view
   mark_as_advanced(LIBYANG_INCLUDE_DIRS LIBYANG_LIBRARIES)
 
-endif (LIBYANG_LIBRARIES AND LIBYANG_INCLUDE_DIRS)
+endif()
 
diff --git a/CMakeModules/FindPackageVersionCheck.cmake b/CMakeModules/FindPackageVersionCheck.cmake
index f0de790..48663cd 100644
--- a/CMakeModules/FindPackageVersionCheck.cmake
+++ b/CMakeModules/FindPackageVersionCheck.cmake
@@ -21,7 +21,7 @@
 #  2. Redistributions in binary form must reproduce the copyright
 #     notice, this list of conditions and the following disclaimer in the
 #     documentation and/or other materials provided with the distribution.
-#  3. The name of the author may not be used to endorse or promote products 
+#  3. The name of the author may not be used to endorse or promote products
 #     derived from this software without specific prior written permission.
 #
 #  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
@@ -41,49 +41,49 @@
   set(_AGE "old")
 
   if(${_NAME}_FIND_VERSION_EXACT)
-    if (${_NAME}_FIND_VERSION VERSION_EQUAL ${_NAME}_VERSION)
+    if(${_NAME}_FIND_VERSION VERSION_EQUAL ${_NAME}_VERSION)
       # exact version found
       set(${_NAME_UPPER}_FOUND TRUE)
-    else (${_NAME}_FIND_VERSION VERSION_EQUAL ${_NAME}_VERSION)
+    else()
       # exect version not found
       set(${_NAME_UPPER}_FOUND FALSE)
       # check if newer or older
-      if (${_NAME}_FIND_VERSION VERSION_LESS ${_NAME}_VERSION)
+      if(${_NAME}_FIND_VERSION VERSION_LESS ${_NAME}_VERSION)
         set(_AGE "new")
-      else (${_NAME}_FIND_VERSION VERSION_LESS ${_NAME}_VERSION)
+      else()
         set(_AGE "old")
-      endif (${_NAME}_FIND_VERSION VERSION_LESS ${_NAME}_VERSION)
-    endif (${_NAME}_FIND_VERSION VERSION_EQUAL ${_NAME}_VERSION)
-  else (${_NAME}_FIND_VERSION_EXACT)
-    if (${_NAME}_FIND_VERSION)
-      if (${_NAME}_VERSION VERSION_LESS ${_NAME}_FIND_VERSION)
+      endif()
+    endif()
+  else()
+    if(${_NAME}_FIND_VERSION)
+      if(${_NAME}_VERSION VERSION_LESS ${_NAME}_FIND_VERSION)
         set(${_NAME_UPPER}_FOUND FALSE)
         set(_AGE "old")
-      else (${_NAME}_VERSION VERSION_LESS ${_NAME}_FIND_VERSION)
+      else()
         set(${_NAME_UPPER}_FOUND TRUE)
-     endif (${_NAME}_VERSION VERSION_LESS ${_NAME}_FIND_VERSION)
-    endif (${_NAME}_FIND_VERSION)
-  endif(${_NAME}_FIND_VERSION_EXACT)
+      endif()
+    endif()
+  endif()
 
-  if ("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
-    if (${_NAME}_FIND_VERSION_EXACT)
+  if("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
+    if(${_NAME}_FIND_VERSION_EXACT)
       set(_FAIL_MESSAGE "The installed ${_NAME} version ${${_NAME}_VERSION} is too ${_AGE}, version ${${_NAME}_FIND_VERSION} is required.")
-    else (${_NAME}_FIND_VERSION_EXACT)
+    else()
       set(_FAIL_MESSAGE "The installed ${_NAME} version ${${_NAME}_VERSION} is too ${_AGE}, at least version ${${_NAME}_FIND_VERSION} is required.")
-    endif (${_NAME}_FIND_VERSION_EXACT)
-  else ("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
+    endif()
+  else()
     set(_FAIL_MESSAGE "${_FAIL_MSG}")
-  endif ("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
+  endif()
 
-  if (NOT ${_NAME_UPPER}_FOUND)
-    if (${_NAME}_FIND_REQUIRED)
+  if(NOT ${_NAME_UPPER}_FOUND)
+    if(${_NAME}_FIND_REQUIRED)
       message(FATAL_ERROR "${_FAIL_MESSAGE}")
-    else (${_NAME}_FIND_REQUIRED)
-      if (NOT ${_NAME}_FIND_QUIETLY)
+    else()
+      if(NOT ${_NAME}_FIND_QUIETLY)
         message(STATUS "${_FAIL_MESSAGE}")
-      endif (NOT ${_NAME}_FIND_QUIETLY)
-    endif (${_NAME}_FIND_REQUIRED)
-  endif (NOT ${_NAME_UPPER}_FOUND)
+      endif()
+    endif()
+  endif()
 
   set(${_NAME_UPPER}_FOUND ${${_NAME_UPPER}_FOUND} PARENT_SCOPE)
-endfunction(FIND_PACKAGE_VERSION_CHECK)
+endfunction()