slight cleanup of config

slight cleanup of config

--- cmake/osvrRenderManagerConfig.cmake
+++ cmake/osvrRenderManagerConfig.cmake
@@ -2,20 +2,19 @@
 # Hook for a super-build to optionally inject hints before target import.
 include("${CMAKE_CURRENT_LIST_DIR}/osvrRenderManagerConfigSuperBuildPrefix.cmake" OPTIONAL)

-# TODO Dependencies
-#find_dependency(GLEW)

-# The actual exported targets
+
+set(OSVRRM_NEED_SDL2 @OSVRRM_NEED_SDL2@)
+set(OSVRRM_NEED_GLEW @OSVRRM_NEED_GLEW@)
+
 set(OSVRRM_PREV_CMAKE_MODULES ${CMAKE_MODULE_PATH})
 set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}" ${CMAKE_MODULE_PATH})
 include(osvrStashMapConfig)
 include(CMakeFindDependencyMacro)
-set(OSVRRM_NEED_SDL2 @OSVRRM_NEED_SDL2@)
 if(OSVRRM_NEED_SDL2)
     # TODO
 	#find_dependency(SDL2)
 endif()
-set(OSVRRM_NEED_GLEW @OSVRRM_NEED_GLEW@)
 if(OSVRRM_NEED_GLEW)
     # TODO
 	#find_dependency(GLEW)
@@ -43,6 +42,8 @@
 set(OSVRRM_REQUIRED_LIBRARIES_RELEASE "@OSVRRM_REQUIRED_LIBRARIES_RELEASE@")
 set(OSVRRM_REQUIRED_LIBRARIES_RELWITHDEBINFO "@OSVRRM_REQUIRED_LIBRARIES_RELWITHDEBINFO@")
 set(OSVRRM_REQUIRED_LIBRARIES_MINSIZEREL "@OSVRRM_REQUIRED_LIBRARIES_MINSIZEREL@")
+set(OSVRRM_NEED_SDL2_COPIED @OSVRRM_NEED_SDL2_COPIED@)
+set(OSVRRM_NEED_GLEW_COPIED @OSVRRM_NEED_GLEW_COPIED@)

 # Options
 set(OSVRRM_HAVE_D3D11_SUPPORT @OSVRRM_HAVE_D3D11_SUPPORT@)


Update sugar_fatal_error.cmake

Update sugar_fatal_error.cmake

--- cmake/print/sugar_fatal_error.cmake
+++ cmake/print/sugar_fatal_error.cmake
@@ -6,7 +6,7 @@

 # Warning:
 #     do not include/use 'sugar_improper_number_of_arguments',
-#     because it use 'sugar_fatal_error' macro
+#     because it use 'sugar_fatal_error' function

 function(sugar_fatal_error)
   if(${ARGC} EQUAL 0)


adds version of CIL repos

adds version of CIL repos

--- version_config.cmake
+++ version_config.cmake
@@ -136,12 +136,13 @@
   set(DEFAULT_ACE_TAG origin/master)

   # CCPi CIL
+  set(CIL_VERSION "19.02")
   set(DEFAULT_CCPi-Framework_URL https://github.com/vais-ral/CCPi-Framework.git)
-  set(DEFAULT_CCPi-Framework_TAG origin/master)
+  set(DEFAULT_CCPi-Framework_TAG d108cd7e9652992001a116347941eda7e75b3301)
   set(DEFAULT_CCPi-RGL_URL https://github.com/vais-ral/CCPi-Regularisation-Toolkit.git)
-  set(DEFAULT_CCPi-RGL_TAG origin/master)
+  set(DEFAULT_CCPi-RGL_TAG "v${CIL_VERSION}")
   set(DEFAULT_CCPi-FrameworkPlugins_URL https://github.com/vais-ral/CCPi-FrameworkPlugins.git)
-  set(DEFAULT_CCPi-FrameworkPlugins_TAG origin/master)
+  set(DEFAULT_CCPi-FrameworkPlugins_TAG b19a37714dcf8288a55bcd41a2a78dd6f8164e7f)
   # For OSX, Gadgetron v3.17.0 doesn't work. So even in devel build, use same version
   # as for non-devel build
   if (APPLE)


[cmake] openexr print no warning in success case

--- src/cmakeFindModules/FindOpenEXR.cmake
+++ src/cmakeFindModules/FindOpenEXR.cmake
@@ -53,13 +53,13 @@
            PATHS ${GENERIC_INCLUDE_PATHS})
 #find_path (OPENEXR_INCLUDE_PATH OpenEXR/OpenEXRConfig.h)

-message(WARNING "GENERIC_INCLUDE_PATHS: ${GENERIC_INCLUDE_PATHS}")
-message(WARNING "Test if file exist: ${OPENEXR_INCLUDE_PATH}/OpenEXR/ImfMultiPartInputFile.h")
+# message(WARNING "GENERIC_INCLUDE_PATHS: ${GENERIC_INCLUDE_PATHS}")
+# message(WARNING "Test if file exist: ${OPENEXR_INCLUDE_PATH}/OpenEXR/ImfMultiPartInputFile.h")

 # Try to figure out version number
 if (EXISTS "${OPENEXR_INCLUDE_PATH}/OpenEXR/ImfMultiPartInputFile.h")
-    message(WARNING "Yes, file exist")
+    # message(WARNING "Yes, file exist")

     # Must be at least 2.0
     file(STRINGS "${OPENEXR_INCLUDE_PATH}/OpenEXR/OpenEXRConfig.h" TMP REGEX "^#define OPENEXR_VERSION_STRING .*$")
@@ -69,7 +69,7 @@
     file(STRINGS "${OPENEXR_INCLUDE_PATH}/OpenEXR/OpenEXRConfig.h" TMP REGEX "^#define OPENEXR_VERSION_MINOR .*$")
     string (REGEX MATCHALL "[0-9]+" OPENEXR_VERSION_MINOR ${TMP})
 else ()
-    message(WARNING "No, default to 1.6.1")
+    message(STATUS  "File ${OPENEXR_INCLUDE_PATH}/OpenEXR/ImfMultiPartInputFile.h does not exist. Default to 1.6.1")
     # Assume an old one, predates 2.x that had versions
     set (OPENEXR_VERSION 1.6.1)
     set (OPENEXR_MAJOR 1)


Reverting r220517; it seems this broke check-asan.

git-svn-id: c199f293c43da69278bea8e88f92242bf3aa95f7@220869 91177308-0d34-0410-b5e6-96231b3b80d8

--- cmake/Modules/AddCompilerRT.cmake
+++ cmake/Modules/AddCompilerRT.cmake
@@ -52,12 +52,8 @@
     # Setup compile flags and definitions.
     set_target_compile_flags(${name}
       ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS})
-    if (NOT MSVC)
-      # We do not want any custom link flags set on MSVC; especially not the
-      # compiler flags, as with other compilers.
-      set_target_link_flags(${name}
-        ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS})
-    endif()
+    set_target_link_flags(${name}
+      ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS})
     set_property(TARGET ${name} APPEND PROPERTY
       COMPILE_DEFINITIONS ${LIB_DEFS})
     # Setup correct output directory in the build tree.


Added a shortcut macro for defining preprocessor options.

--- scripts/project.cmake
+++ scripts/project.cmake
@@ -466,4 +466,11 @@
     #    set("${CURRENT_TARGET}_external_libraries" "${${CURRENT_TARGET}_external_libraries};${library}")
     list(APPEND ${CURRENT_TARGET}_external_libraries ${library})
   endif ()
+endmacro()
+
+macro(define_option option)
+  if (${option})
+    message("Setting ${option} to ${${option}} in ${CURRENT_TARGET}")
+    add_definitions(-D${option}=${${option}})
+  endif ()
 endmacro()


Handle flex's non support of -o option.

Handle flex's non support of -o option.

    * build-aux/cmake/modules/Flex.cmake: Do that by copying lex.yy.c to the
    output file.

Signed-off-by: Nicolas Despres <abdeb541ca46f1651c9cc594d44e707056e73d5d@gostai.com>

--- build-aux/cmake/modules/Flex.cmake
+++ build-aux/cmake/modules/Flex.cmake
@@ -33,15 +33,22 @@
     get_filename_component(_in ${_current_FILE} ABSOLUTE)
     get_filename_component(_basename ${_current_FILE} NAME_WE)

+    set(intermediate lex.yy.c)
     set(_out ${CMAKE_CURRENT_BINARY_DIR}/flex_${_basename}.cpp)
     # Invoke flex.
     add_custom_command(
-      OUTPUT ${_out}
+      OUTPUT ${intermediate}
       COMMAND ${FLEX_EXECUTABLE}
       ARGS
-      -o${_out}
       ${_in}
       DEPENDS ${_in}
+      )
+    # Copy intermediate file to output file.
+    add_custom_command(
+      OUTPUT ${_out}
+      COMMAND ${CMAKE_COMMAND}
+      ARGS -E copy ${intermediate} ${_out}
+      DEPENDS ${intermediate}
       )
     # Add the generated source file to the source list.
     set(${_sources} ${${_sources}} ${_out} PARENT_SCOPE)


Fix geoip rm and xargs issue when there was nothing to delete.

--- build/cmake/libgeoip.cmake
+++ build/cmake/libgeoip.cmake
@@ -21,5 +21,5 @@
   INSTALL_COMMAND install -D -m 644 <SOURCE_DIR>/GeoLiteCityv6.dat ${STAGE_EMBEDDED_DIR}/var/db/geoip/city-v6.dat
     # Since we re-download every day as a separate project name, this cleans up
     # any old downloads in the work directory.
-    COMMAND find ${WORK_DIR}/src -maxdepth 1 -name geolitecity* -not -name geolitecity-${RELEASE_DATE}* -print | xargs rm -r
+    COMMAND find ${WORK_DIR}/src -maxdepth 1 -name geolitecity* -not -name geolitecity-${RELEASE_DATE}* -print -exec rm -rf {} $<SEMICOLON>
 )


Upgrade CPM

Upgrade CPM

Upgrade to 0.27.1

--- cmake/CPM.cmake
+++ cmake/CPM.cmake
@@ -1,9 +1,9 @@
-# TheLartians/CPM - A simple Git dependency manager
-# =================================================
-# See https://github.com/TheLartians/CPM for usage and update instructions.
+# CPM.cmake - CMake's missing package manager
+# ===========================================
+# See https://github.com/TheLartians/CPM.cmake for usage and update instructions.
 #
 # MIT License
-# -----------
+# -----------
 #[[
   Copyright (c) 2019 Lars Melchior

@@ -28,11 +28,11 @@

 cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

-set(CURRENT_CPM_VERSION 0.15.1)
+set(CURRENT_CPM_VERSION 0.27.1)

 if(CPM_DIRECTORY)
-  if(NOT ${CPM_DIRECTORY} MATCHES ${CMAKE_CURRENT_LIST_DIR})
-    if (${CPM_VERSION} VERSION_LESS ${CURRENT_CPM_VERSION})
+  if(NOT CPM_DIRECTORY STREQUAL CMAKE_CURRENT_LIST_DIR)
+    if (CPM_VERSION VERSION_LESS CURRENT_CPM_VERSION)
       message(AUTHOR_WARNING "${CPM_INDENT} \
 A dependency is using a more recent CPM version (${CURRENT_CPM_VERSION}) than the current project (${CPM_VERSION}). \
 It is recommended to upgrade CPM to the most recent version. \
@@ -41,14 +41,25 @@
     endif()
     return()
   endif()
+
+  get_property(CPM_INITIALIZED GLOBAL "" PROPERTY CPM_INITIALIZED SET)
+  if (CPM_INITIALIZED)
+    return()
+  endif()
 endif()
+
+set_property(GLOBAL PROPERTY CPM_INITIALIZED true)

 option(CPM_USE_LOCAL_PACKAGES "Always try to use `find_package` to get dependencies" $ENV{CPM_USE_LOCAL_PACKAGES})
 option(CPM_LOCAL_PACKAGES_ONLY "Only use `find_package` to get dependencies" $ENV{CPM_LOCAL_PACKAGES_ONLY})
 option(CPM_DOWNLOAD_ALL "Always download dependencies from source" $ENV{CPM_DOWNLOAD_ALL})
+option(CPM_DONT_UPDATE_MODULE_PATH "Don't update the module path to allow using find_package" $ENV{CPM_DONT_UPDATE_MODULE_PATH})
+option(CPM_DONT_CREATE_PACKAGE_LOCK "Don't create a package lock file in the binary path" $ENV{CPM_DONT_CREATE_PACKAGE_LOCK})
+option(CPM_INCLUDE_ALL_IN_PACKAGE_LOCK "Add all packages added through CPM.cmake to the package lock" $ENV{CPM_INCLUDE_ALL_IN_PACKAGE_LOCK})

 set(CPM_VERSION ${CURRENT_CPM_VERSION} CACHE INTERNAL "")
 set(CPM_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} CACHE INTERNAL "")
+set(CPM_FILE ${CMAKE_CURRENT_LIST_FILE} CACHE INTERNAL "")
 set(CPM_PACKAGES "" CACHE INTERNAL "")
 set(CPM_DRY_RUN OFF CACHE INTERNAL "Don't download or configure dependencies (for testing)")

@@ -60,6 +71,20 @@

 set(CPM_SOURCE_CACHE ${CPM_SOURCE_CACHE_DEFAULT} CACHE PATH "Directory to downlaod CPM dependencies")

+if (NOT CPM_DONT_UPDATE_MODULE_PATH)
+  set(CPM_MODULE_PATH "${CMAKE_BINARY_DIR}/CPM_modules" CACHE INTERNAL "")
+  # remove old modules
+  FILE(REMOVE_RECURSE ${CPM_MODULE_PATH})
+  file(MAKE_DIRECTORY ${CPM_MODULE_PATH})
+  # locally added CPM modules should override global packages
+  set(CMAKE_MODULE_PATH "${CPM_MODULE_PATH};${CMAKE_MODULE_PATH}")
+endif()
+
+if (NOT CPM_DONT_CREATE_PACKAGE_LOCK)
+  set(CPM_PACKAGE_LOCK_FILE "${CMAKE_BINARY_DIR}/cpm-package-lock.cmake" CACHE INTERNAL "")
+  file(WRITE ${CPM_PACKAGE_LOCK_FILE} "# CPM Package Lock\n# This file should be committed to version control\n\n")
+endif()
+
 include(FetchContent)
 include(CMakeParseArguments)

@@ -70,13 +95,22 @@

 function(cpm_find_package NAME VERSION)
   string(REPLACE " " ";" EXTRA_ARGS "${ARGN}")
-  find_package(${NAME} ${VERSION} ${EXTRA_ARGS})
+  find_package(${NAME} ${VERSION} ${EXTRA_ARGS} QUIET)
   if(${CPM_ARGS_NAME}_FOUND)
-    message(STATUS "${CPM_INDENT} using local package ${CPM_ARGS_NAME}@${${CPM_ARGS_NAME}_VERSION}")
-    CPMRegisterPackage(${CPM_ARGS_NAME} "${${CPM_ARGS_NAME}_VERSION}")
+    message(STATUS "${CPM_INDENT} using local package ${CPM_ARGS_NAME}@${VERSION}")
+    CPMRegisterPackage(${CPM_ARGS_NAME} "${VERSION}")
     set(CPM_PACKAGE_FOUND YES PARENT_SCOPE)
   else()
     set(CPM_PACKAGE_FOUND NO PARENT_SCOPE)
+  endif()
+endfunction()
+
+# Create a custom FindXXX.cmake module for a CPM package
+# This prevents `find_package(NAME)` from finding the system library
+function(CPMCreateModuleFile Name)
+  if (NOT CPM_DONT_UPDATE_MODULE_PATH)
+    # erase any previous modules
+    FILE(WRITE ${CPM_MODULE_PATH}/Find${Name}.cmake "include(${CPM_FILE})\n${ARGN}\nset(${Name}_FOUND TRUE)")
   endif()
 endfunction()

@@ -89,10 +123,22 @@
   )

   cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "" ${ARGN})
-
+
+  if (NOT DEFINED CPM_ARGS_VERSION)
+    if (DEFINED CPM_ARGS_GIT_TAG)
+      cpm_get_version_from_git_tag("${CPM_ARGS_GIT_TAG}" CPM_ARGS_VERSION)
+    endif()
+  endif()
+
   if (CPM_DOWNLOAD_ALL)
     CPMAddPackage(${ARGN})
-    cpm_export_variables()
+    cpm_export_variables(${CPM_ARGS_NAME})
+    return()
+  endif()
+
+  CPMCheckIfPackageAlreadyAdded(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" "${CPM_ARGS_OPTIONS}")
+  if (CPM_PACKAGE_ALREADY_ADDED)
+    cpm_export_variables(${CPM_ARGS_NAME})
     return()
   endif()

@@ -100,9 +146,33 @@

   if(NOT CPM_PACKAGE_FOUND)
     CPMAddPackage(${ARGN})
-    cpm_export_variables()
-  endif()
-
+    cpm_export_variables(${CPM_ARGS_NAME})
+  endif()
+
+endfunction()
+
+# checks if a package has been added before
+function(CPMCheckIfPackageAlreadyAdded CPM_ARGS_NAME CPM_ARGS_VERSION CPM_ARGS_OPTIONS)
+  if ("${CPM_ARGS_NAME}" IN_LIST CPM_PACKAGES)
+    CPMGetPackageVersion(${CPM_ARGS_NAME} CPM_PACKAGE_VERSION)
+    if("${CPM_PACKAGE_VERSION}" VERSION_LESS "${CPM_ARGS_VERSION}")
+      message(WARNING "${CPM_INDENT} requires a newer version of ${CPM_ARGS_NAME} (${CPM_ARGS_VERSION}) than currently included (${CPM_PACKAGE_VERSION}).")
+    endif()
+    if (CPM_ARGS_OPTIONS)
+      foreach(OPTION ${CPM_ARGS_OPTIONS})
+        cpm_parse_option(${OPTION})
+        if(NOT "${${OPTION_KEY}}" STREQUAL "${OPTION_VALUE}")
+          message(WARNING "${CPM_INDENT} ignoring package option for ${CPM_ARGS_NAME}: ${OPTION_KEY} = ${OPTION_VALUE} (${${OPTION_KEY}})")
+        endif()
+      endforeach()
+    endif()
+    cpm_get_fetch_properties(${CPM_ARGS_NAME})
+    SET(${CPM_ARGS_NAME}_ADDED NO)
+    SET(CPM_PACKAGE_ALREADY_ADDED YES PARENT_SCOPE)
+    cpm_export_variables(${CPM_ARGS_NAME})
+  else()
+    SET(CPM_PACKAGE_ALREADY_ADDED NO PARENT_SCOPE)
+  endif()
 endfunction()

 # Download and add a package from source
@@ -110,86 +180,108 @@

   set(oneValueArgs
     NAME
+    FORCE
     VERSION
     GIT_TAG
     DOWNLOAD_ONLY
     GITHUB_REPOSITORY
     GITLAB_REPOSITORY
+    GIT_REPOSITORY
     SOURCE_DIR
     DOWNLOAD_COMMAND
     FIND_PACKAGE_ARGUMENTS
+    NO_CACHE
+    GIT_SHALLOW
   )

   set(multiValueArgs
     OPTIONS
   )

-  cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+  cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}")
+
+  # Set default values for arguments
+
+  if (NOT DEFINED CPM_ARGS_VERSION)
+    if (DEFINED CPM_ARGS_GIT_TAG)
+      cpm_get_version_from_git_tag("${CPM_ARGS_GIT_TAG}" CPM_ARGS_VERSION)
+    endif()
+  endif()
+
+  if(CPM_ARGS_DOWNLOAD_ONLY)
+    set(DOWNLOAD_ONLY ${CPM_ARGS_DOWNLOAD_ONLY})
+  else()
+    set(DOWNLOAD_ONLY NO)
+  endif()
+
+  if (DEFINED CPM_ARGS_GITHUB_REPOSITORY)
+    set(CPM_ARGS_GIT_REPOSITORY "https://github.com/${CPM_ARGS_GITHUB_REPOSITORY}.git")
+  endif()
+
+  if (DEFINED CPM_ARGS_GITLAB_REPOSITORY)
+    list(CPM_ARGS_GIT_REPOSITORY "https://gitlab.com/${CPM_ARGS_GITLAB_REPOSITORY}.git")
+  endif()
+
+  if (DEFINED CPM_ARGS_GIT_REPOSITORY)
+    list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_REPOSITORY ${CPM_ARGS_GIT_REPOSITORY})
+    if (NOT DEFINED CPM_ARGS_GIT_TAG)
+      set(CPM_ARGS_GIT_TAG v${CPM_ARGS_VERSION})
+    endif()
+  endif()
+
+  if (DEFINED CPM_ARGS_GIT_TAG)
+    list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_TAG ${CPM_ARGS_GIT_TAG})
+    # If GIT_SHALLOW is explicitly specified, honor the value.
+    if (DEFINED CPM_ARGS_GIT_SHALLOW)
+      list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_SHALLOW ${CPM_ARGS_GIT_SHALLOW})
+    endif()
+  endif()
+
+  # Check if package has been added before
+  CPMCheckIfPackageAlreadyAdded(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" "${CPM_ARGS_OPTIONS}")
+  if (CPM_PACKAGE_ALREADY_ADDED)
+    cpm_export_variables(${CPM_ARGS_NAME})
+    return()
+  endif()
+
+  # Check for manual overrides
+  if (NOT CPM_ARGS_FORCE AND NOT "${CPM_${CPM_ARGS_NAME}_SOURCE}" STREQUAL "")
+    set(PACKAGE_SOURCE ${CPM_${CPM_ARGS_NAME}_SOURCE})
+    set(CPM_${CPM_ARGS_NAME}_SOURCE "")
+    CPMAddPackage(
+      NAME ${CPM_ARGS_NAME}
+      SOURCE_DIR ${PACKAGE_SOURCE}
+      FORCE True
+    )
+    cpm_export_variables(${CPM_ARGS_NAME})
+    return()
+  endif()
+
+  # Check for available declaration
+  if (NOT CPM_ARGS_FORCE AND NOT "${CPM_DECLARATION_${CPM_ARGS_NAME}}" STREQUAL "")
+    set(declaration ${CPM_DECLARATION_${CPM_ARGS_NAME}})
+    set(CPM_DECLARATION_${CPM_ARGS_NAME} "")
+    CPMAddPackage(${declaration})
+    cpm_export_variables(${CPM_ARGS_NAME})
+    # checking again to ensure version and option compatibility
+    CPMCheckIfPackageAlreadyAdded(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" "${CPM_ARGS_OPTIONS}")
+    return()
+  endif()

   if(CPM_USE_LOCAL_PACKAGES OR CPM_LOCAL_PACKAGES_ONLY)
     cpm_find_package(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" ${CPM_ARGS_FIND_PACKAGE_ARGUMENTS})

     if(CPM_PACKAGE_FOUND)
+      cpm_export_variables(${CPM_ARGS_NAME})
       return()
     endif()

-    if(CPM_LOCAL_PACKAGES_ONLY)
+    if(CPM_LOCAL_PACKAGES_ONLY)
       message(SEND_ERROR "CPM: ${CPM_ARGS_NAME} not found via find_package(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION})")
     endif()
   endif()

-  if (NOT DEFINED CPM_ARGS_VERSION)
-    if (DEFINED CPM_ARGS_GIT_TAG)
-      cpm_get_version_from_git_tag("${CPM_ARGS_GIT_TAG}" CPM_ARGS_VERSION)
-    endif()
-    if (NOT DEFINED CPM_ARGS_VERSION)
-      set(CPM_ARGS_VERSION 0)
-    endif()
-  endif()
-
-  if (NOT DEFINED CPM_ARGS_GIT_TAG)
-    set(CPM_ARGS_GIT_TAG v${CPM_ARGS_VERSION})
-  endif()
-
-  list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_TAG ${CPM_ARGS_GIT_TAG})
-
-  if(CPM_ARGS_DOWNLOAD_ONLY)
-    set(DOWNLOAD_ONLY ${CPM_ARGS_DOWNLOAD_ONLY})
-  else()
-    set(DOWNLOAD_ONLY NO)
-  endif()
-
-  if (CPM_ARGS_GITHUB_REPOSITORY)
-    list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_REPOSITORY "https://github.com/${CPM_ARGS_GITHUB_REPOSITORY}.git")
-  endif()
-
-  if (CPM_ARGS_GITLAB_REPOSITORY)
-    list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_REPOSITORY "https://gitlab.com/${CPM_ARGS_GITLAB_REPOSITORY}.git")
-  endif()
-
-  if (${CPM_ARGS_NAME} IN_LIST CPM_PACKAGES)
-    CPMGetPackageVersion(${CPM_ARGS_NAME} CPM_PACKAGE_VERSION)
-    if(${CPM_PACKAGE_VERSION} VERSION_LESS ${CPM_ARGS_VERSION})
-      message(WARNING "${CPM_INDENT} requires a newer version of ${CPM_ARGS_NAME} (${CPM_ARGS_VERSION}) than currently included (${CPM_PACKAGE_VERSION}).")
-    endif()
-    if (CPM_ARGS_OPTIONS)
-      foreach(OPTION ${CPM_ARGS_OPTIONS})
-        cpm_parse_option(${OPTION})
-        if(NOT "${${OPTION_KEY}}" STREQUAL ${OPTION_VALUE})
-          message(WARNING "${CPM_INDENT} ignoring package option for ${CPM_ARGS_NAME}: ${OPTION_KEY} = ${OPTION_VALUE} (${${OPTION_KEY}})")
-        endif()
-      endforeach()
-    endif()
-    cpm_fetch_package(${CPM_ARGS_NAME} ${DOWNLOAD_ONLY})
-    cpm_get_fetch_properties(${CPM_ARGS_NAME})
-    SET(${CPM_ARGS_NAME}_SOURCE_DIR "${${CPM_ARGS_NAME}_SOURCE_DIR}")
-    SET(${CPM_ARGS_NAME}_BINARY_DIR "${${CPM_ARGS_NAME}_BINARY_DIR}")
-    SET(${CPM_ARGS_NAME}_ADDED NO)
-    cpm_export_variables()
-    return()
-  endif()
-
-  CPMRegisterPackage(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION})
+  CPMRegisterPackage("${CPM_ARGS_NAME}" "${CPM_ARGS_VERSION}")

   if (CPM_ARGS_OPTIONS)
     foreach(OPTION ${CPM_ARGS_OPTIONS})
@@ -198,51 +290,121 @@
     endforeach()
   endif()

-  set(FETCH_CONTENT_DECLARE_EXTRA_OPTS "")
-
   if (DEFINED CPM_ARGS_GIT_TAG)
     set(PACKAGE_INFO "${CPM_ARGS_GIT_TAG}")
+  elseif (DEFINED CPM_ARGS_SOURCE_DIR)
+    set(PACKAGE_INFO "${CPM_ARGS_SOURCE_DIR}")
   else()
     set(PACKAGE_INFO "${CPM_ARGS_VERSION}")
   endif()

   if (DEFINED CPM_ARGS_DOWNLOAD_COMMAND)
-    set(FETCH_CONTENT_DECLARE_EXTRA_OPTS DOWNLOAD_COMMAND ${CPM_ARGS_DOWNLOAD_COMMAND})
-  else()
-    if (CPM_SOURCE_CACHE AND NOT DEFINED CPM_ARGS_SOURCE_DIR)
-      string(TOLOWER ${CPM_ARGS_NAME} lower_case_name)
-      set(origin_parameters ${CPM_ARGS_UNPARSED_ARGUMENTS})
-      list(SORT origin_parameters)
-      string(SHA1 origin_hash "${origin_parameters}")
-      set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${origin_hash})
-      list(APPEND FETCH_CONTENT_DECLARE_EXTRA_OPTS SOURCE_DIR ${download_directory})
-      if (EXISTS ${download_directory})
-        list(APPEND FETCH_CONTENT_DECLARE_EXTRA_OPTS DOWNLOAD_COMMAND ":")
-        set(PACKAGE_INFO "${download_directory}")
-      else()
-        # remove timestamps so CMake will re-download the dependency
-        file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/_deps/${lower_case_name}-subbuild)
-        set(PACKAGE_INFO "${PACKAGE_INFO} -> ${download_directory}")
+    list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS DOWNLOAD_COMMAND ${CPM_ARGS_DOWNLOAD_COMMAND})
+  elseif (DEFINED CPM_ARGS_SOURCE_DIR)
+    list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS SOURCE_DIR ${CPM_ARGS_SOURCE_DIR})
+  elseif (CPM_SOURCE_CACHE AND NOT CPM_ARGS_NO_CACHE)
+    string(TOLOWER ${CPM_ARGS_NAME} lower_case_name)
+    set(origin_parameters ${CPM_ARGS_UNPARSED_ARGUMENTS})
+    list(SORT origin_parameters)
+    string(SHA1 origin_hash "${origin_parameters}")
+    set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${origin_hash})
+    list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS SOURCE_DIR ${download_directory})
+    if (EXISTS ${download_directory})
+      # disable the download command to allow offline builds
+      list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS DOWNLOAD_COMMAND "${CMAKE_COMMAND}")
+      set(PACKAGE_INFO "${download_directory}")
+    else()
+      # Enable shallow clone when GIT_TAG is not a commit hash.
+      # Our guess may not be accurate, but it should guarantee no commit hash get mis-detected.
+      if (NOT DEFINED CPM_ARGS_GIT_SHALLOW)
+        cpm_is_git_tag_commit_hash("${CPM_ARGS_GIT_TAG}" IS_HASH)
+        if (NOT ${IS_HASH})
+          list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_SHALLOW TRUE)
+        endif()
       endif()
-    endif()
-  endif()
-
-  cpm_declare_fetch(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION} ${PACKAGE_INFO} "${CPM_ARGS_UNPARSED_ARGUMENTS}" ${FETCH_CONTENT_DECLARE_EXTRA_OPTS})
-  cpm_fetch_package(${CPM_ARGS_NAME} ${DOWNLOAD_ONLY})
-  cpm_get_fetch_properties(${CPM_ARGS_NAME})
+
+      # remove timestamps so CMake will re-download the dependency
+      file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/_deps/${lower_case_name}-subbuild)
+      set(PACKAGE_INFO "${PACKAGE_INFO} -> ${download_directory}")
+    endif()
+  endif()
+
+  CPMCreateModuleFile(${CPM_ARGS_NAME} "CPMAddPackage(${ARGN})")
+
+  if (CPM_PACKAGE_LOCK_ENABLED)
+    if ((CPM_ARGS_VERSION AND NOT CPM_ARGS_SOURCE_DIR) OR CPM_INCLUDE_ALL_IN_PACKAGE_LOCK)
+      cpm_add_to_package_lock(${CPM_ARGS_NAME} "${ARGN}")
+    elseif(CPM_ARGS_SOURCE_DIR)
+      cpm_add_comment_to_package_lock(${CPM_ARGS_NAME} "local directory")
+    else()
+      cpm_add_comment_to_package_lock(${CPM_ARGS_NAME} "${ARGN}")
+    endif()
+  endif()
+
+  cpm_declare_fetch("${CPM_ARGS_NAME}" "${CPM_ARGS_VERSION}" "${PACKAGE_INFO}" "${CPM_ARGS_UNPARSED_ARGUMENTS}")
+  cpm_fetch_package("${CPM_ARGS_NAME}" "${DOWNLOAD_ONLY}")
+  cpm_get_fetch_properties("${CPM_ARGS_NAME}")
+
   SET(${CPM_ARGS_NAME}_ADDED YES)
-  cpm_export_variables()
-endfunction()
+  cpm_export_variables("${CPM_ARGS_NAME}")
+endfunction()
+
+# Fetch a previously declared package
+macro(CPMGetPackage Name)
+  if (DEFINED "CPM_DECLARATION_${Name}")
+    CPMAddPackage(
+      NAME ${Name}
+    )
+  else()
+    message(SEND_ERROR "Cannot retrieve package ${Name}: no declaration available")
+  endif()
+endmacro()

 # export variables available to the caller to the parent scope
 # expects ${CPM_ARGS_NAME} to be set
-macro(cpm_export_variables)
-  SET(${CPM_ARGS_NAME}_SOURCE_DIR "${${CPM_ARGS_NAME}_SOURCE_DIR}" PARENT_SCOPE)
-  SET(${CPM_ARGS_NAME}_BINARY_DIR "${${CPM_ARGS_NAME}_BINARY_DIR}" PARENT_SCOPE)
-  SET(${CPM_ARGS_NAME}_ADDED "${${CPM_ARGS_NAME}_ADDED}" PARENT_SCOPE)
+macro(cpm_export_variables name)
+  SET(${name}_SOURCE_DIR "${${name}_SOURCE_DIR}" PARENT_SCOPE)
+  SET(${name}_BINARY_DIR "${${name}_BINARY_DIR}" PARENT_SCOPE)
+  SET(${name}_ADDED "${${name}_ADDED}" PARENT_SCOPE)
 endmacro()

-# declares that a package has been added to CPM
+# declares a package, so that any call to CPMAddPackage for the
+# package name will use these arguments instead.
+# Previous declarations will not be overriden.
+macro(CPMDeclarePackage Name)
+  if (NOT DEFINED "CPM_DECLARATION_${Name}")
+    set("CPM_DECLARATION_${Name}" "${ARGN}")
+  endif()
+endmacro()
+
+function(cpm_add_to_package_lock Name)
+  if (NOT CPM_DONT_CREATE_PACKAGE_LOCK)
+    file(APPEND ${CPM_PACKAGE_LOCK_FILE} "# ${Name}\nCPMDeclarePackage(${Name} \"${ARGN}\")\n")
+  endif()
+endfunction()
+
+function(cpm_add_comment_to_package_lock Name)
+  if (NOT CPM_DONT_CREATE_PACKAGE_LOCK)
+    file(APPEND ${CPM_PACKAGE_LOCK_FILE} "# ${Name} (unversioned)\n# CPMDeclarePackage(${Name} \"${ARGN}\")\n")
+  endif()
+endfunction()
+
+# includes the package lock file if it exists and creates a target
+# `cpm-write-package-lock` to update it
+macro(CPMUsePackageLock file)
+  if (NOT CPM_DONT_CREATE_PACKAGE_LOCK)
+    get_filename_component(CPM_ABSOLUTE_PACKAGE_LOCK_PATH ${file} ABSOLUTE)
+    if(EXISTS ${CPM_ABSOLUTE_PACKAGE_LOCK_PATH})
+      include(${CPM_ABSOLUTE_PACKAGE_LOCK_PATH})
+    endif()
+    if (NOT TARGET cpm-update-package-lock)
+      add_custom_target(cpm-update-package-lock COMMAND ${CMAKE_COMMAND} -E copy ${CPM_PACKAGE_LOCK_FILE} ${CPM_ABSOLUTE_PACKAGE_LOCK_PATH})
+    endif()
+    set(CPM_PACKAGE_LOCK_ENABLED true)
+  endif()
+endmacro()
+
+# registers a package that has been added to CPM
 function(CPMRegisterPackage PACKAGE VERSION)
   list(APPEND CPM_PACKAGES ${PACKAGE})
   set(CPM_PACKAGES ${CPM_PACKAGES} CACHE INTERNAL "")
@@ -254,24 +416,23 @@
   set(${OUTPUT} "${CPM_PACKAGE_${PACKAGE}_VERSION}" PARENT_SCOPE)
 endfunction()

-# declares a package in FetchContent_Declare
+# declares a package in FetchContent_Declare
 function (cpm_declare_fetch PACKAGE VERSION INFO)
   message(STATUS "${CPM_INDENT} adding package ${PACKAGE}@${VERSION} (${INFO})")

-  if (${CPM_DRY_RUN})
+  if (${CPM_DRY_RUN})
     message(STATUS "${CPM_INDENT} package not declared (dry run)")
     return()
   endif()

-  FetchContent_Declare(
-    ${PACKAGE}
+  FetchContent_Declare(${PACKAGE}
     ${ARGN}
   )
 endfunction()

 # returns properties for a package previously defined by cpm_declare_fetch
 function (cpm_get_fetch_properties PACKAGE)
-  if (${CPM_DRY_RUN})
+  if (${CPM_DRY_RUN})
     return()
   endif()
   FetchContent_GetProperties(${PACKAGE})
@@ -281,31 +442,37 @@
 endfunction()

 # downloads a previously declared package via FetchContent
-function (cpm_fetch_package PACKAGE DOWNLOAD_ONLY)
-
-  if (${CPM_DRY_RUN})
+function (cpm_fetch_package PACKAGE DOWNLOAD_ONLY)
+  if (${CPM_DRY_RUN})
     message(STATUS "${CPM_INDENT} package ${PACKAGE} not fetched (dry run)")
     return()
   endif()

-  set(CPM_OLD_INDENT "${CPM_INDENT}")
-  set(CPM_INDENT "${CPM_INDENT} ${PACKAGE}:")
-  if(${DOWNLOAD_ONLY})
-    if(NOT "${PACKAGE}_POPULATED")
+  if(DOWNLOAD_ONLY)
+    FetchContent_GetProperties(${PACKAGE})
+    if(NOT ${PACKAGE}_POPULATED)
       FetchContent_Populate(${PACKAGE})
     endif()
   else()
+    set(CPM_OLD_INDENT "${CPM_INDENT}")
+    set(CPM_INDENT "${CPM_INDENT} ${PACKAGE}:")
     FetchContent_MakeAvailable(${PACKAGE})
-  endif()
-  set(CPM_INDENT "${CPM_OLD_INDENT}")
+    set(CPM_INDENT "${CPM_OLD_INDENT}")
+  endif()
 endfunction()

 # splits a package option
 function(cpm_parse_option OPTION)
   string(REGEX MATCH "^[^ ]+" OPTION_KEY ${OPTION})
+  string(LENGTH ${OPTION} OPTION_LENGTH)
   string(LENGTH ${OPTION_KEY} OPTION_KEY_LENGTH)
-  math(EXPR OPTION_KEY_LENGTH "${OPTION_KEY_LENGTH}+1")
-  string(SUBSTRING ${OPTION} "${OPTION_KEY_LENGTH}" "-1" OPTION_VALUE)
+  if (OPTION_KEY_LENGTH STREQUAL OPTION_LENGTH)
+    # no value for key provided, assume user wants to set option to "ON"
+    set(OPTION_VALUE "ON")
+  else()
+    math(EXPR OPTION_KEY_LENGTH "${OPTION_KEY_LENGTH}+1")
+    string(SUBSTRING ${OPTION} "${OPTION_KEY_LENGTH}" "-1" OPTION_VALUE)
+  endif()
   set(OPTION_KEY "${OPTION_KEY}" PARENT_SCOPE)
   set(OPTION_VALUE "${OPTION_VALUE}" PARENT_SCOPE)
 endfunction()
@@ -313,7 +480,7 @@
 # guesses the package version from a git tag
 function(cpm_get_version_from_git_tag GIT_TAG RESULT)
   string(LENGTH ${GIT_TAG} length)
-  if (length EQUAL 40)
+  if (length EQUAL 40)
     # GIT_TAG is probably a git hash
     SET(${RESULT} 0 PARENT_SCOPE)
   else()
@@ -321,3 +488,18 @@
     SET(${RESULT} ${CMAKE_MATCH_1} PARENT_SCOPE)
   endif()
 endfunction()
+
+# guesses if the git tag is a commit hash or an actual tag or a branch nane.
+function(cpm_is_git_tag_commit_hash GIT_TAG RESULT)
+  string(LENGTH "${GIT_TAG}" length)
+  # full hash has 40 characters, and short hash has at least 7 characters.
+  if (length LESS 7 OR length GREATER 40)
+    SET(${RESULT} 0 PARENT_SCOPE)
+  else()
+    if (${GIT_TAG} MATCHES "^[a-fA-F0-9]+$")
+      SET(${RESULT} 1 PARENT_SCOPE)
+    else()
+      SET(${RESULT} 0 PARENT_SCOPE)
+    endif()
+  endif()
+endfunction()


Add more comments

Add more comments

--- cmake/mex.cmake
+++ cmake/mex.cmake
@@ -120,26 +120,33 @@
   set(MEX_EXT ${MEX_EXT} PARENT_SCOPE)
   set(simulink_FOUND ${simulink_FOUND} PARENT_SCOPE)

+  # Try to compile a file using MEX. The verbose output from mex -v includes the
+  # values of the compiler and linker flags that it uses to so.
   file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy_mex.c "")
-  execute_process(COMMAND ${mex} -largeArrayDims -v ${CMAKE_CURRENT_BINARY_DIR}/dummy_mex.c OUTPUT_VARIABLE mexv_output ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
-
+  execute_process(COMMAND ${mex} -largeArrayDims -v ${CMAKE_CURRENT_BINARY_DIR}/dummy_mex.c
+    OUTPUT_VARIABLE mexv_output ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+  # Parse the output from the try-compile (mexv_output) to obtain the compiler
+  # and linker flags. This creates variables MEX_* in parent scope that are used
+  # to set these flags in the add_mex() function.
   if ( WIN32 )
     get_mex_option(CC NAMES COMPILER REQUIRED)
-    get_mex_option(CXX NAMES COMPILER REQUIRED)
+    get_mex_option(CXX NAMES COMPILER REQUIRED)  # cl

     get_mex_option(CFLAGS NAMES COMPFLAGS)
-    get_mex_option(CXXFLAGS NAMES COMPFLAGS)
-    get_mex_option(DEFINES NAMES COMPDEFINES)
+    get_mex_option(CXXFLAGS NAMES COMPFLAGS)  # /MD /nologo ...
+    get_mex_option(DEFINES NAMES COMPDEFINES)  # /D_CRT_SECURE_NO_DEPRECATE ...
+    get_mex_option(MATLABMEX)  # /DMATLAB_MEX_FILE ...
     get_mex_option(COPTIMFLAGS NAMES OPTIMFLAGS)
-    get_mex_option(CXXOPTIMFLAGS NAMES OPTIMFLAGS)
+    get_mex_option(CXXOPTIMFLAGS NAMES OPTIMFLAGS)  # /O2 /DNDEBUG /Zp8 ...
     get_mex_option(CDEBUGFLAGS NAMES DEBUGFLAGS)
-    get_mex_option(CXXDEBUGFLAGS NAMES DEBUGFLAGS)
-
-    get_mex_option(LD NAMES LINKER)
-    get_mex_option(LDFLAGS NAMES LINKFLAGS)
-    get_mex_option(LINKLIBS)
+    get_mex_option(CXXDEBUGFLAGS NAMES DEBUGFLAGS)  # /Z7 ...
+
+    get_mex_option(LD NAMES LINKER)  # link
+    get_mex_option(LDFLAGS NAMES LINKFLAGS)  # /nologo ...
+    get_mex_option(LINKLIBS)  # /LIBPATH:$MATLAB_ROOT\extern\lib\$ARCH\microsoft libmx.lib libmex.lib libmat.lib ...
     get_mex_option(LINKEXPORT)
-    get_mex_option(LDDEBUGFLAGS NAMES LINKDEBUGFLAGS)
+    get_mex_option(LDDEBUGFLAGS NAMES LINKDEBUGFLAGS)  # /debug ...

     if (MSVC)
 #        string(REGEX REPLACE "^.*implib:\"(.*)templib.x\" .*$" "\\1" tempdir "${MEX_LDFLAGS}")
@@ -163,18 +170,18 @@
     get_mex_option(CC REQUIRED)

 #    get_mex_option(CFLAGS REQUIRED)
-    get_mex_option(CXXFLAGS NAMES CXXFLAGS CFLAGS REQUIRED)
-    get_mex_option(DEFINES)
-    get_mex_option(MATLABMEX)
-    get_mex_option(INCLUDE)
+    get_mex_option(CXXFLAGS NAMES CXXFLAGS CFLAGS REQUIRED)  # -fexceptions -fPIC ...
+    get_mex_option(DEFINES)  # -D_GNU_SOURCE ...
+    get_mex_option(MATLABMEX)  # -DMATLAB_MEX_FILE ...
+    get_mex_option(INCLUDE)  # -I$MATLAB_ROOT/extern/include -I$MATLAB_ROOT/simulink/include ...
     get_mex_option(CDEBUGFLAGS)
     get_mex_option(COPTIMFLAGS)
     get_mex_option(CLIBS)
     get_mex_arguments(CC)

-    get_mex_option(CXX NAMES CXX CC REQUIRED)
-    get_mex_option(CXXDEBUGFLAGS)
-    get_mex_option(CXXOPTIMFLAGS)
+    get_mex_option(CXX NAMES CXX CC REQUIRED)  # g++, xcrun -sdk $SDK_VERSION clang++ ...
+    get_mex_option(CXXDEBUGFLAGS)  # -g ...
+    get_mex_option(CXXOPTIMFLAGS)  # -O2 -DNDEBUG ...
     get_mex_option(CXXLIBS)
     get_mex_arguments(CXX)

@@ -186,11 +193,11 @@
 #  get_mex_option(FLIBS)
 #  get_mex_arguments(FC)

-    get_mex_option(LD REQUIRED)
+    get_mex_option(LD REQUIRED)  # ld
     get_mex_option(LDFLAGS REQUIRED)
-    get_mex_option(LINKLIBS)
-    get_mex_option(LDDEBUGFLAGS)
-    get_mex_option(LDOPTIMFLAGS)
+    get_mex_option(LINKLIBS)  # -L$MATLAB_ROOT/bin/$ARCH -lmx -lmex -lmat ...
+    get_mex_option(LDDEBUGFLAGS)  # -g ...
+    get_mex_option(LDOPTIMFLAGS)  # -O ...
     get_mex_option(LDEXTENSION NAMES LDEXTENSION LDEXT REQUIRED)
     get_mex_arguments(LD)

@@ -229,15 +236,20 @@
   set (MEX_COMPILE_FLAGS "${MEX_CXXFLAGS} ${MEX_DEFINES} ${MEX_CXX_ARGUMENTS}")

   # CMake will add the appropriate flags for the chosen build configuration
-  # instead of these flags
+  # instead of these flags that were parsed from the output of the try-compile.
   if(MSVC)
-    # Controlled by CMAKE_BUILD_TYPE
+    # Controlled by CMAKE_BUILD_TYPE. MEX always uses "/MD", but that would
+    # conflict with "/MDd" which is set by CMake during "Debug" builds.
     string(REPLACE "/MD " "" MEX_COMPILE_FLAGS "${MEX_COMPILE_FLAGS}")
-    # Controlled by CMAKE_VERBOSE_MAKEFILE
+    # Controlled by CMAKE_VERBOSE_MAKEFILE even for generators such as
+    # "Visual Studio 2015".
     string(REPLACE "/nologo " "" MEX_COMPILE_FLAGS "${MEX_COMPILE_FLAGS}")
     string(REPLACE "/nologo " "" MEXLIB_LDFLAGS "${MEXLIB_LDFLAGS}")
   else()
-    # Controlled by CMAKE_C_STANDARD and CMAKE_CXX_STANDARD
+    # Controlled by CMAKE_C_STANDARD and CMAKE_CXX_STANDARD. MEX always sets the
+    # C dialect to ANSI and the C++ dialect to either ANSI or C++11 depending on
+    # the version of MATLAB, but these conflict if CMAKE_C_STANDARD or
+    # CMAKE_CXX_STANDARD are set in order to enable C++14 or above.
     string(REPLACE "-ansi " "" MEX_COMPILE_FLAGS "${MEX_COMPILE_FLAGS}")
     string(REPLACE "-std=c++11 " "" MEX_COMPILE_FLAGS "${MEX_COMPILE_FLAGS}")
   endif()
@@ -304,6 +316,10 @@

   list(FIND ARGV SHARED isshared)
   list(FIND ARGV EXECUTABLE isexe)
+
+  # Set compiler and linker flags for MEX file compilation. Be careful not to
+  # overwrite these COMPILE_FLAGS when setting additional properties on MEX
+  # targets to suppress specific compiler warnings, etc.
   if (isexe GREATER -1)
     list(REMOVE_ITEM ARGV EXECUTABLE)
     add_executable(${target} ${ARGV})


fixes issue 1066

fixes issue 1066

Enhanced runsuite_ssh.cmake to transfer all files from
ext/drsyms/libelftc/ - otherwise rsync's -C option would
exclude pre-built static libraries located there.

Change-Id: I0bff2f64551837f37f32257ba4726fc2238b67ab

SVN-Revision: 2157

--- suite/runsuite_ssh.cmake
+++ suite/runsuite_ssh.cmake
@@ -126,14 +126,16 @@
 run_cmd("${cmd}")

 # copy the local source tree to the remote host using rsync
-# * using -C to avoid sending ~ files, but need explicit include of core/
+# * using -C to avoid sending ~ files, but need explicit include of core/,
+#   and also all files under ext/drsyms/libelftc/ in order to copy pre-built
+#   static libraries
 # * not using -u since last tree tested might have newer timestamps
 # * not paying cost of checksums (-c) since assuming that either
 #   time or size will be different
 # * if coming from a perforce checkout don't want to preserve read-only
 #   perms so should use "-rltgoD" instead of "-a" though should just
 #   get replaced next time so shouldn't matter
-set(cmd "${RSYNC}" "-avzC" "--include=core/" "--delete"
+set(cmd "${RSYNC}" "-avzC" "--include=core/" "--include=ext/drsyms/libelftc/**" "--delete"
   # exclude, in case people keep build/install dirs inside src dir
   "--exclude=/build*" "--exclude=/exports*"
   "${LOCAL_SRCDIR}/"


[CMake] Add support for populating LLVM_REPOSITORY from CMake.

Autoconf does this in the GetRepositoryPath script, CMake's VersionFromVCS does grab the SVN_REVISION, but doesn't populate the repository URL.

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

--- cmake/modules/VersionFromVCS.cmake
+++ cmake/modules/VersionFromVCS.cmake
@@ -15,6 +15,9 @@
       if( Project_WC_REVISION )
         set(SVN_REVISION ${Project_WC_REVISION} PARENT_SCOPE)
         set(result "${result}-r${Project_WC_REVISION}")
+      endif()
+      if( Project_WC_URL )
+        set(LLVM_REPOSITORY ${Project_WC_URL} PARENT_SCOPE)
       endif()
     endif()
   elseif( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git )
@@ -65,6 +68,19 @@
         else()
           set(result "${result}${git_svn_rev}")
         endif()
+
+        execute_process(COMMAND
+          ${git_executable} svn info
+          WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+          TIMEOUT 5
+          RESULT_VARIABLE git_result
+          OUTPUT_VARIABLE git_output)
+        if( git_result EQUAL 0)
+          string(REGEX MATCH "URL: ([^ \n]*)" svn_url ${git_output})
+          if(svn_url)
+            set(LLVM_REPOSITORY ${CMAKE_MATCH_1} PARENT_SCOPE)
+          endif()
+        endif()
       endif()
     endif()
   endif()


added cuda profiler line info flag to debug and relwithdebinfo build targets

--- cmake/oskar_compiler_options.cmake
+++ cmake/oskar_compiler_options.cmake
@@ -115,9 +115,9 @@
         set(CUDA_VERBOSE_BUILD OFF)

         # General NVCC compiler options.
-        set(CUDA_NVCC_FLAGS_RELEASE -O2)
-        set(CUDA_NVCC_FLAGS_DEBUG -O0;-g)
-        set(CUDA_NVCC_FLAGS_RELWIDTHDEBINFO "-02 -g")
+        set(CUDA_NVCC_FLAGS_RELEASE "-O2")
+        set(CUDA_NVCC_FLAGS_DEBUG "-O0 -g --generate-line-info")
+        set(CUDA_NVCC_FLAGS_RELWIDTHDEBINFO "-02 -g --generate-line-info")
         set(CUDA_NVCC_FLAGS_MINSIZEREL -01)

         # Options passed to the compiler NVCC encapsulates.


fixed hash of buffer

fixed hash of buffer

--- cmake/projects/Buffer/hunter.cmake
+++ cmake/projects/Buffer/hunter.cmake
@@ -11,7 +11,7 @@
     URL
     "https://github.com/designerror/buffer/archive/v0.1.0.tar.gz"
     SHA1
-    c54c5b35a5c22630912f28cec9d614a00c28e1cf
+    10f08bb239c1ae142b33491f0eeb6339332736c1
 )

 hunter_pick_scheme(DEFAULT url_sha1_cmake)


Update hunter.cmake

Update hunter.cmake

--- cmake/projects/buffer/hunter.cmake
+++ cmake/projects/buffer/hunter.cmake
@@ -8,7 +8,7 @@
     PACKAGE_NAME
     buffer
     VERSION
-    "0.1.6"
+    "0.1.7"
     URL
     "https://github.com/designerror/buffer/archive/v0.1.7.tar.gz"
     SHA1


Update hunter.cmake

Update hunter.cmake

--- cmake/projects/xfixes/hunter.cmake
+++ cmake/projects/xfixes/hunter.cmake
@@ -10,7 +10,7 @@
 include(hunter_download)
 include(hunter_pick_scheme)

-# http://www.x.org/releases/individual/proto/
+# https://www.x.org/releases/individual/lib/
 hunter_add_version(
     PACKAGE_NAME
     xfixes


Added "minor revision" number to LIB_VERSION variable so that our versioning number coincides with that of InstallAnywhere. Ordinarily I would frown on changing our code to satisfy some external tool, but can't see how adding one more place to our version number could hurt. In fact, it will likely prove useful in the future.

--- system_definitions.cmake
+++ system_definitions.cmake
@@ -154,7 +154,7 @@
 # This is only relevant for releases. 1.1.1 is chosen here
 # simply as a stub.
 #
-set(LIB_VERSION 1.1.1 CACHE STRING "Library version number for release purposes")
+set(LIB_VERSION 0.0.0.0 CACHE STRING "Library version number for release purposes")

 mark_as_advanced(LIB_VERSION)


[t:4814] fix symbol existence checking

[t:4814] fix symbol existence checking

git-svn-id: b5c078ec0b4d3a50497e9dd3081db18a5b4f16e5@43400 c7de825b-a66e-492c-adef-691d508d4ae1

--- cmake_modules/TokuFeatureDetection.cmake
+++ cmake_modules/TokuFeatureDetection.cmake
@@ -38,9 +38,9 @@
 include(CheckSymbolExists)

 ## check whether we can set the mmap threshold like we can in gnu libc's malloc
-check_symbol_exists(M_MMAP_THRESHOLD "malloc.h;sys/malloc.h" HAVE_M_MMAP_THRESHOLD)
+check_symbol_exists(M_MMAP_THRESHOLD "malloc.h" HAVE_M_MMAP_THRESHOLD)
 ## check whether we have CLOCK_REALTIME
-check_symbol_exists(CLOCK_REALTIME "time.h;sys/time.h" HAVE_CLOCK_REALTIME)
+check_symbol_exists(CLOCK_REALTIME "time.h" HAVE_CLOCK_REALTIME)

 include(CheckFunctionExists)


fix update command

fix update command

git-svn-id: 8b72b58fb31a931b6e9a2bd3bb08bc6614045fb1@3415 c330d7e9-fc0c-0410-a5b3-fd85c6f5aa8f

--- test/openVibeTests.cmake
+++ test/openVibeTests.cmake
@@ -74,7 +74,7 @@
 endif(NOT EXISTS "${CTEST_SOURCE_DIRECTORY}")

 ## -- Update Command
-set(CTEST_UPDATE_COMMAND               "${CTEST_SVN_COMMAND}")
+set(CTEST_UPDATE_COMMAND               "${CTEST_SVN_COMMAND} update")


Fedpkg: WORKING_DIRECTORY of fedpkg clone should be FEDPKG_DIR

--- Modules/ManageReleaseFedora.cmake
+++ Modules/ManageReleaseFedora.cmake
@@ -154,12 +154,13 @@
 	SET(FEDPKG_PRJ_DIR_GIT "${FEDPKG_PRJ_DIR}/.git/.cmake-fedora")

 	ADD_CUSTOM_COMMAND(OUTPUT ${FEDPKG_PRJ_DIR_GIT}
-	    COMMAND ${CMAKE_COMMAND} -E make_directory ${FEDPKG_DIR}
 	    COMMAND [ -d ${FEDPKG_PRJ_DIR} ] || ${FEDPKG_CMD} clone ${PROJECT_NAME}
 	    COMMAND ${CMAKE_COMMAND} -E touch ${FEDPKG_PRJ_DIR_GIT}
 	    COMMENT "Making FedPkg directory"
+	    WORKING_DIRECTORY ${FEDPKG_DIR}
 	    VERBATIM
 	    )
+
     ENDIF(NOT _manage_release_fedora_dependencies_missing)

     FUNCTION(RELEASE_ADD_KOJI_BUILD_SCRATCH)


BUG: fix manual definition of git tag for remote modules

Bug was introduced by d67ae98 due to an incomplete search and replace.

--- CMake/ITKModuleRemote.cmake
+++ CMake/ITKModuleRemote.cmake
@@ -216,8 +216,8 @@
     set(REMOTE_GIT_TAG "${_fetch_options_GIT_TAG}")

     if( DEFINED Module_${_name}_GIT_TAG AND NOT "${Module_${_name}_GIT_TAG}" STREQUAL "${_fetch_options_GIT_TAG}")
-      set(REMOTE_GIT_TAG "${REMOTE_GIT_TAG_${_name}}")
-      message(STATUS "NOTE: Using override 'REMOTE_GIT_TAG_${_name}=${REMOTE_GIT_TAG}'\n"
+      set(REMOTE_GIT_TAG "${Module_${_name}_GIT_TAG}")
+      message(STATUS "NOTE: Using override 'Module_${_name}_GIT_TAG=${REMOTE_GIT_TAG}'\n"
                      "      instead of value 'GIT_TAG=${_fetch_options_GIT_TAG}'\n"
                      "      specified in file ${ITK_SOURCE_DIR}/Modules/Remote/${_name}.remote.cmake'")
     endif()
@@ -238,8 +238,8 @@
     endif()
   else()
     # Hide remote module options if not building.
-    if(DEFINED REMOTE_GIT_TAG_${_name})
-      set_property(CACHE REMOTE_GIT_TAG_${_name} PROPERTY TYPE INTERNAL)
+    if(DEFINED Module_${_name}_GIT_TAG)
+      set_property(CACHE Module_${_name}_GIT_TAG PROPERTY TYPE INTERNAL)
     endif()
     if(DEFINED Module_${_name}_BUILD_EXAMPLES)
       set_property(CACHE Module_${_name}_BUILD_EXAMPLES PROPERTY TYPE INTERNAL)


Enable customization of find_package().

Enable customization of find_package().

`vtk_module_export_code_find_package` now supports passing arguments to
the exported `find_package` call e.g. to pick specific components to
load from the package.

--- CMake/vtkModuleMacros.cmake
+++ CMake/vtkModuleMacros.cmake
@@ -211,7 +211,14 @@
 # The VTK_INSTALL_FIND_PACKAGE_<name>_DIR variable may be set
 # to an alternative location for the install tree to reference,
 # or to a false value to remove any default location.
+#
+# Additional arguments for find_package() call added to the module config
+# can be provided as extra arguments to this macro e.g.
+#
+#     vtk_module_export_code_find_package(Qt5 COMPONENTS Widgets)
+#
 macro(vtk_module_export_code_find_package _name)
+  string(REPLACE ";" " " _argn "${ARGN}")
   if(${_name}_DIR)
     if(DEFINED VTK_INSTALL_FIND_PACKAGE_${_name}_DIR)
       set(_dir "${VTK_INSTALL_FIND_PACKAGE_${_name}_DIR}")
@@ -225,13 +232,13 @@
 endif()")
     endif()
     set(${vtk-module}_EXPORT_CODE_INSTALL "${${vtk-module}_EXPORT_CODE_INSTALL}
-find_package(${_name} REQUIRED QUIET)
+find_package(${_name} REQUIRED QUIET ${_argn})
 ")
     set(${vtk-module}_EXPORT_CODE_BUILD "${${vtk-module}_EXPORT_CODE_BUILD}
 if(NOT ${_name}_DIR)
   set(${_name}_DIR \"${${_name}_DIR}\")
 endif()
-find_package(${_name} REQUIRED QUIET)
+find_package(${_name} REQUIRED QUIET ${_argn})
 ")
   endif()
 endmacro()


BUG: build_subdirectory was not set to the correct location

--- ShapePopulationViewer.cmake
+++ ShapePopulationViewer.cmake
@@ -9,12 +9,12 @@
   set(MODULE_NAME ${LOCAL_PROJECT_NAME} )
   set(EXTENSION_HOMEPAGE "https://www.nitrc.org/projects/shapepopviewer/")
   set(EXTENSION_CATEGORY "Shape Analysis")
-  set(EXTENSION_CONTRIBUTORS "Alexis Girault (NIRAL, UNC)")
+  set(EXTENSION_CONTRIBUTORS "Alexis Girault (NIRAL, UNC), Francois Budin (NIRAL, UNC)")
   set(EXTENSION_DESCRIPTION "Visualize and interact with multiple surfaces at the same time to easily compare them")
   set(EXTENSION_ICONURL "https://www.nitrc.org/project/screenshot.php?group_id=759&screenshot_id=704")
   set(EXTENSION_SCREENSHOTURLS "http://wiki.na-mic.org/Wiki/images/8/81/Screenshot1.png http://wiki.na-mic.org/Wiki/images/1/13/SPVscreenshot2.png")
   set(EXTENSION_DEPENDS "NA") # Specified as a space separated list or 'NA' if any
-  set(EXTENSION_BUILD_SUBDIRECTORY ShapePopulationViewer-build)
+  set(EXTENSION_BUILD_SUBDIRECTORY .)
   unsetForSlicer( NAMES QT_QMAKE_EXECUTABLE SlicerExecutionModel_DIR ITK_DIR VTK_DIR CMAKE_C_COMPILER CMAKE_CXX_COMPILER CMAKE_CXX_FLAGS CMAKE_C_FLAGS ITK_LIBRARIES )
   find_package(Slicer REQUIRED)
   include(${Slicer_USE_FILE})


update NDK to r13b (#289)

update NDK to r13b (#289)

--- ci-build.cmake
+++ ci-build.cmake
@@ -54,7 +54,7 @@
 if(DEFINED ENV{ANDROID})
     set(CROSS
         -DANDROID_NATIVE_API_LEVEL=21
-        -DANDROID_NDK=${CMAKE_CURRENT_SOURCE_DIR}/android-ndk-r13
+        -DANDROID_NDK=${CMAKE_CURRENT_SOURCE_DIR}/android-ndk-r13b
         -DCMAKE_TOOLCHAIN_FILE=${CMAKE_CURRENT_SOURCE_DIR}/CMake/toolchain/android.toolchain.cmake
         "-DANDROID_ABI=armeabi-v7a with NEON")

@@ -71,10 +71,10 @@

     message(STATUS "Downloading Android NDK")
     file(DOWNLOAD
-        http://dl.google.com/android/repository/android-ndk-r13-linux-x86_64.zip
-        ./android-ndk-r13-linux-x86_64.zip)
+        http://dl.google.com/android/repository/android-ndk-r13b-linux-x86_64.zip
+        ./android-ndk-r13b-linux-x86_64.zip)
     message(STATUS "Extracting Android NDK")
-    execute_process(COMMAND unzip android-ndk-r13-linux-x86_64.zip OUTPUT_QUIET)
+    execute_process(COMMAND unzip android-ndk-r13b-linux-x86_64.zip OUTPUT_QUIET)
 endif()

 execute_process(COMMAND cmake


Update CBSE readme instructions on CMake dep install instructions

--- cmake/DaemonCBSE.cmake
+++ cmake/DaemonCBSE.cmake
@@ -52,7 +52,8 @@
         COMMAND ${PYTHON_EXECUTABLE} -c "import jinja2, yaml, collections, argparse, sys, os.path, re"
         RESULT_VARIABLE RET)
     if (NOT RET EQUAL 0)
-        message(FATAL_ERROR "Missing dependences for CBSE generation. Use pip -r install src/utils/cbse/requirements.txt to install")
+        message(FATAL_ERROR "Missing dependences for CBSE generation. Please ensure you have python ≥ 2, python-yaml, and python-jinja installed.
+                             Use pip -r install src/utils/cbse/requirements.txt to install")
     endif()
     set(GENERATED_CBSE ${output}/backend/CBSEBackend.cpp
                        ${output}/backend/CBSEBackend.h


Update FindCython.cmake from upstream (thewtex/cython-cmake-example)

--- cmake/FindCython.cmake
+++ cmake/FindCython.cmake
@@ -22,7 +22,21 @@
 # limitations under the License.
 #=============================================================================

-find_program( CYTHON_EXECUTABLE NAMES cython cython.bat )
+# Use the Cython executable that lives next to the Python executable
+# if it is a local installation.
+find_package( PythonInterp )
+if( PYTHONINTERP_FOUND )
+  get_filename_component( _python_path ${PYTHON_EXECUTABLE} PATH )
+  find_program( CYTHON_EXECUTABLE
+    NAMES cython cython.bat
+    HINTS ${_python_path}
+    )
+else()
+  find_program( CYTHON_EXECUTABLE
+    NAMES cython cython.bat
+    )
+endif()
+

 include( FindPackageHandleStandardArgs )
 FIND_PACKAGE_HANDLE_STANDARD_ARGS( Cython REQUIRED_VARS CYTHON_EXECUTABLE )


added missing slash: dsound is now correctly detected using the DX SDK

--- cmake/FindDSound.cmake
+++ cmake/FindDSound.cmake
@@ -31,7 +31,7 @@
              NO_DEFAULT_PATH
              PATHS
              "${DXSDK_DIR}/Lib/${DIRECTX_ARCH}"
-             "$ENV{DXSDK_DIR}Lib/${DIRECTX_ARCH}"
+             "$ENV{DXSDK_DIR}/Lib/${DIRECTX_ARCH}"
              "$ENV{PROGRAMFILES}/Microsoft DirectX SDK/Lib/${DIRECTX_ARCH}"
              "$ENV{PROGRAMFILES}/Microsoft DirectX SDK (August 2008)/Lib/${DIRECTX_ARCH}"
              "$ENV{PROGRAMFILES}/Microsoft DirectX SDK (June 2010)/Lib/${DIRECTX_ARCH}"


check version number using newer cmake functionality, instead of kde macro

--- cmake/FindEigen2.cmake
+++ cmake/FindEigen2.cmake
@@ -8,8 +8,6 @@
 # Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org>
 # Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr>
 # Redistribution and use is allowed according to the terms of the BSD license.
-
-include(MacroEnsureVersion)

 if(NOT EIGEN2_MIN_VERSION)
   if(NOT Eigen2_FIND_VERSION_MAJOR)
@@ -36,7 +34,11 @@
   set(EIGEN2_MINOR_VERSION "${CMAKE_MATCH_1}")

   set(EIGEN2_VERSION ${EIGEN2_WORLD_VERSION}.${EIGEN2_MAJOR_VERSION}.${EIGEN2_MINOR_VERSION})
-  MACRO_ENSURE_VERSION( ${EIGEN2_MIN_VERSION} ${EIGEN2_VERSION} EIGEN2_VERSION_OK)
+  if(${EIGEN2_VERSION} VERSION_LESS ${EIGEN2_MIN_VERSION})
+    set(EIGEN2_VERSION_OK FALSE)
+  else(${EIGEN2_VERSION} VERSION_LESS ${EIGEN2_MIN_VERSION})
+    set(EIGEN2_VERSION_OK TRUE)
+  endif(${EIGEN2_VERSION} VERSION_LESS ${EIGEN2_MIN_VERSION})

   if(NOT EIGEN2_VERSION_OK)


Fix for gflags with pthreads linking. Patch from Alex Stewart of Ceres

Change-Id: Iad78fa17d40be4483acdce22502bdc16e29d0e99

--- cmake/FindGflags.cmake
+++ cmake/FindGflags.cmake
@@ -130,6 +130,18 @@
 ENDIF (NOT GFLAGS_LIBRARY OR
        NOT EXISTS ${GFLAGS_LIBRARY})

+# gflags typically requires a threading library (which is OS dependent), note
+# that this defines the CMAKE_THREAD_LIBS_INIT variable.  If we are able to
+# detect threads, we assume that gflags requires it.
+FIND_PACKAGE(Threads QUIET)
+SET(GFLAGS_LINK_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
+# On Windows, the Shlwapi library is used by gflags if available.
+IF (MSVC)
+  CHECK_INCLUDE_FILE_CXX("shlwapi.h" HAVE_SHLWAPI)
+  IF (HAVE_SHLWAPI)
+    LIST(APPEND GFLAGS_LINK_LIBRARIES shlwapi.lib)
+  ENDIF(HAVE_SHLWAPI)
+ENDIF (MSVC)
 # Mark internally as found, then verify. GFLAGS_REPORT_NOT_FOUND() unsets
 # if called.
 SET(GFLAGS_FOUND TRUE)
@@ -140,7 +152,7 @@
   INCLUDE(CheckCXXSourceCompiles)
   # Setup include path & link library for gflags for CHECK_CXX_SOURCE_COMPILES
   SET(CMAKE_REQUIRED_INCLUDES ${GFLAGS_INCLUDE_DIR})
-  SET(CMAKE_REQUIRED_LIBRARIES ${GFLAGS_LIBRARY})
+  SET(CMAKE_REQUIRED_LIBRARIES ${GFLAGS_LIBRARY} ${GFLAGS_LINK_LIBRARIES})
   CHECK_CXX_SOURCE_COMPILES(
     "#include <gflags/gflags.h>
      int main(int argc, char * argv[]) {
@@ -155,7 +167,7 @@
     #
     # Setup include path & link library for gflags for CHECK_CXX_SOURCE_COMPILES
     SET(CMAKE_REQUIRED_INCLUDES ${GFLAGS_INCLUDE_DIR})
-    SET(CMAKE_REQUIRED_LIBRARIES ${GFLAGS_LIBRARY})
+    SET(CMAKE_REQUIRED_LIBRARIES ${GFLAGS_LIBRARY} ${GFLAGS_LINK_LIBRARIES})
     CHECK_CXX_SOURCE_COMPILES(
       "#include <gflags/gflags.h>
        int main(int argc, char * argv[]) {
@@ -202,7 +214,7 @@
 # Set standard CMake FindPackage variables if found.
 IF (GFLAGS_FOUND)
   SET(GFLAGS_INCLUDE_DIRS ${GFLAGS_INCLUDE_DIR})
-  SET(GFLAGS_LIBRARIES ${GFLAGS_LIBRARY})
+  SET(GFLAGS_LIBRARIES ${GFLAGS_LIBRARY} ${GFLAGS_LINK_LIBRARIES})
 ENDIF (GFLAGS_FOUND)

 # Handle REQUIRED / QUIET optional arguments.


cmake: look for either static or dynamic libraries

On some distro, static libraries are shipped in a separate package.
Look for either a static or dynamic libbpf, and only fail if neither is found.

--- cmake/FindLibBpf.cmake
+++ cmake/FindLibBpf.cmake
@@ -28,6 +28,20 @@
     /sw/include
     ENV CPATH)

+find_library (LIBBPF_LIBRARIES
+  NAMES
+    bpf
+  PATHS
+    /usr/lib
+    /usr/local/lib
+    /opt/local/lib
+    /sw/lib
+    ENV LIBRARY_PATH
+    ENV LD_LIBRARY_PATH)
+if(LIBBPF_LIBRARIES)
+list(APPEND PATHS LIBBPF_LIBRARIES)
+endif()
+
 find_library (LIBBPF_STATIC_LIBRARIES
   NAMES
     libbpf.a
@@ -38,24 +52,19 @@
     /sw/lib
     ENV LIBRARY_PATH
     ENV LD_LIBRARY_PATH)
+if(LIBBPF_STATIC_LIBRARIES)
+list(APPEND PATHS LIBBPF_STATIC_LIBRARIES)
+endif()

-find_library (LIBBPF_LIBRARIES
-  NAMES
-    bpf
-  PATHS
-    /usr/lib
-    /usr/local/lib
-    /opt/local/lib
-    /sw/lib
-    ENV LIBRARY_PATH
-    ENV LD_LIBRARY_PATH)
-
+if(LIBBPF_STATIC_LIBRARIES OR LIBBPF_LIBRARIES)
 include (FindPackageHandleStandardArgs)

 # handle the QUIETLY and REQUIRED arguments and set LIBBPF_FOUND to TRUE if all listed variables are TRUE
 FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibBpf "Please install the libbpf development package"
-  LIBBPF_LIBRARIES
-  LIBBPF_STATIC_LIBRARIES
+  ${PATHS}
   LIBBPF_INCLUDE_DIR)

-mark_as_advanced(LIBBPF_INCLUDE_DIR LIBBPF_STATIC_LIBRARIES LIBBPF_LIBRARIES)
+mark_as_advanced(LIBBPF_INCLUDE_DIR ${PATHS})
+else()
+message(Please install the libbpf development package)
+endif()


Prefer system utf8cpp if available

Prefer system utf8cpp if available

The current logic always uses the bundled utf8cpp.  This is contrary
to the stated intent of commit
1d7dd3e082be8a046f21d4a2d51026ac3c1f7c14 if UTFCPP_PATH is not set
explicitly.

--- cmake/FindUtfcpp.cmake
+++ cmake/FindUtfcpp.cmake
@@ -10,7 +10,8 @@

 find_path(UTFCPP_INCLUDE_DIR
     NAMES utf8.h
-    HINTS  "${UTFCPP_PATH}" "${PROJECT_SOURCE_DIR}/lib/utfcpp/v2_0/source"
+    HINTS "${UTFCPP_PATH}"
+    PATHS "${PROJECT_SOURCE_DIR}/lib/utfcpp/v2_0/source"
 )

 if (UTFCPP_INCLUDE_DIR)


switch to devleop branch for thunderegg external project

--- cmake/ThunderEgg.cmake
+++ cmake/ThunderEgg.cmake
@@ -21,7 +21,7 @@

 ExternalProject_Add(ThunderEgg
 GIT_REPOSITORY https://github.com/thunderegg/thunderegg
-GIT_TAG        develop-wip
+GIT_TAG        develop
 CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${THUNDEREGG_ROOT} -Dmpi:BOOL=${mpi} -Dopenmp:BOOL=${openmp} -Ddisable_petsc:BOOL=true -DP4EST_ROOT=${P4EST_ROOT}
 BUILD_BYPRODUCTS ${THUNDEREGG_LIBRARIES}
 DEPENDS P4EST-install


using system xml2

using system xml2

--- vtk.cmake
+++ vtk.cmake
@@ -48,6 +48,8 @@
         -DVTK_USE_QT:BOOL=ON
         -DVTK_USE_QVTK_QTOPENGL:BOOL=ON
 	-DVTK_USE_TK=OFF
+	# NETCDF caused weird errors in vtk's xml
+	-DVTK_USE_SYSTEM_LIBXML2
     BUILD_COMMAND       ${BUILDEM_ENV_STRING} make
     #TEST_COMMAND        ${BUILDEM_ENV_STRING} make check
     INSTALL_COMMAND     ${BUILDEM_ENV_STRING} make install


Fix FindAlure.cmake to find correct name "alure32" on windows.

--- audio/cmake/FindAlure.cmake
+++ audio/cmake/FindAlure.cmake
@@ -42,7 +42,7 @@

   find_library(ALURE_LIBRARY
     NAMES
-      alure alure 32
+      alure alure32
     PATHS
       /usr/lib
       /usr/local/lib


Fix findfilesystem for custom llvm on macos

--- cmake/FindFilesystem.cmake
+++ cmake/FindFilesystem.cmake
@@ -28,9 +28,9 @@
         find_library(
             FILESYSTEM_LIBRARY
             NAMES c++fs
-            PATH_SUFFIXES
+            HINTS
             # mac clang location
-            llvm/lib
+            /usr/local/opt/llvm/lib
             )
     endif()


SDL: Fixed issue finding SDL_image header.

--- cmake/FindSDL2_image.cmake
+++ cmake/FindSDL2_image.cmake
@@ -28,7 +28,7 @@
   )

   FIND_LIBRARY(SDL2_IMAGE_LIBRARY SDL2_image ${TRIAL_LIBRARY_PATHS})
-  FIND_PATH(SDL_IMAGE_INCLUDE_DIR SDL_image.h ${TRIAL_INCLUDE_PATHS})
+  FIND_PATH(SDL2_IMAGE_INCLUDE_DIR SDL_image.h ${TRIAL_INCLUDE_PATHS})

 ENDIF(SDL2_IMAGE_INCLUDE_DIRS)


Overhaul finding Windows SDKs.

Overhaul finding Windows SDKs.

--- cmake/FindWindowsSDK.cmake
+++ cmake/FindWindowsSDK.cmake
@@ -1,6 +1,10 @@
 # - Find the Windows SDK aka Platform SDK
 #
 # Relevant Wikipedia article: http://en.wikipedia.org/wiki/Microsoft_Windows_SDK
+#
+# Pass "COMPONENTS tools" to ignore Visual Studio version checks: in case
+# you just want the tool binaries to run, rather than the libraries and headers
+# for compiling.
 #
 # Variables:
 #  WINDOWSSDK_FOUND - if any version of the windows or platform SDK was found that is usable with the current version of visual studio
@@ -17,6 +21,9 @@
 #  windowssdk_name_lookup(<directory> <output variable>) - Find the name corresponding with the SDK directory you pass in, or
 #     NOTFOUND if not recognized. Your directory must be one of WINDOWSSDK_DIRS for this to work.
 #
+#  windowssdk_build_lookup(<directory> <output variable>) - Find the build version number corresponding with the SDK directory you pass in, or
+#     NOTFOUND if not recognized. Your directory must be one of WINDOWSSDK_DIRS for this to work.
+#
 #  get_windowssdk_from_component(<file or dir> <output variable>) - Given a library or include dir,
 #     find the Windows SDK root dir corresponding to it, or NOTFOUND if unrecognized.
 #
@@ -42,44 +49,160 @@
 set(_preferred_sdk_dirs) # pre-output
 set(_win_sdk_dirs) # pre-output
 set(_win_sdk_versanddirs) # pre-output
+set(_win_sdk_buildsanddirs) # pre-output
 set(_winsdk_vistaonly) # search parameters
 set(_winsdk_kits) # search parameters

-# Appends to the two main pre-output lists used only if the path exists
-macro(_winsdk_conditional_append _vername _path)
-	if(EXISTS "${_path}")
-		list(APPEND _win_sdk_dirs "${_path}")
-		list(APPEND
-			_win_sdk_versanddirs
-			"${_vername}"
-			"${_path}")
+
+set(_WINDOWSSDK_ANNOUNCE OFF)
+if(NOT WINDOWSSDK_FOUND AND (NOT WindowsSDK_FIND_QUIETLY))
+	set(_WINDOWSSDK_ANNOUNCE ON)
+endif()
+macro(_winsdk_announce)
+	if(_WINSDK_ANNOUNCE)
+		message(STATUS ${ARGN})
 	endif()
 endmacro()
-if(MSVC AND MSVC_VERSION GREATER 1310) # Newer than VS .NET/VS Toolkit 2003
-	# Environment variable for SDK dir
-	if(EXISTS "$ENV{WindowsSDKDir}" AND (NOT "$ENV{WindowsSDKDir}" STREQUAL ""))
-		message(STATUS "Got $ENV{WindowsSDKDir} - Windows/Platform SDK directories: ${_win_sdk_dirs}")
-		list(APPEND _preferred_sdk_dirs "$ENV{WindowsSDKDir}")
-	endif()
-
-	if(MSVC_VERSION LESS 1600)
-		# Per-user current Windows SDK for VS2005/2008
+
+set(_winsdk_win10vers 10.0.10056.0 10.0.10240.0)
+
+if(WindowsSDK_FIND_COMPONENTS MATCHES "tools")
+	set(_WINDOWSSDK_IGNOREMSVC ON)
+	_winsdk_announce("Checking for tools from Windows/Platform SDKs...")
+else()
+	set(_WINDOWSSDK_IGNOREMSVC OFF)
+	_winsdk_announce("Checking for Windows/Platform SDKs...")
+endif()
+
+# Appends to the three main pre-output lists used only if the path exists
+# and is not already in the list.
+function(_winsdk_conditional_append _vername _build _path)
+	if(("${_path}" MATCHES "registry") OR (NOT EXISTS "${_path}"))
+		# Path invalid - do not add
+		return()
+	endif()
+	list(FIND _win_sdk_dirs "${_path}" _win_sdk_idx)
+	if(_win_sdk_idx GREATER -1)
+		# Path already in list - do not add
+		return()
+	endif()
+	_winsdk_announce( " - ${_vername}, Build ${_build} @ ${_path}")
+	# Not yet in the list, so we'll add it
+	list(APPEND _win_sdk_dirs "${_path}")
+	set(_win_sdk_dirs "${_win_sdk_dirs}" CACHE INTERNAL "" FORCE)
+	list(APPEND
+		_win_sdk_versanddirs
+		"${_vername}"
+		"${_path}")
+	set(_win_sdk_versanddirs "${_win_sdk_versanddirs}" CACHE INTERNAL "" FORCE)
+	list(APPEND
+		_win_sdk_buildsanddirs
+		"${_build}"
+		"${_path}")
+	set(_win_sdk_buildsanddirs "${_win_sdk_buildsanddirs}" CACHE INTERNAL "" FORCE)
+endfunction()
+
+# Appends to the "preferred SDK" lists only if the path exists
+function(_winsdk_conditional_append_preferred _info _path)
+	if(("${_path}" MATCHES "registry") OR (NOT EXISTS "${_path}"))
+		# Path invalid - do not add
+		return()
+	endif()
+
+	get_filename_component(_path "${_path}" ABSOLUTE)
+
+	list(FIND _win_sdk_preferred_sdk_dirs "${_path}" _win_sdk_idx)
+	if(_win_sdk_idx GREATER -1)
+		# Path already in list - do not add
+		return()
+	endif()
+	_winsdk_announce( " - Found \"preferred\" SDK ${_info} @ ${_path}")
+	# Not yet in the list, so we'll add it
+	list(APPEND _win_sdk_preferred_sdk_dirs "${_path}")
+	set(_win_sdk_preferred_sdk_dirs "${_win_sdk_dirs}" CACHE INTERNAL "" FORCE)
+
+	# Just in case we somehow missed it:
+	_winsdk_conditional_append("${_info}" "" "${_path}")
+endfunction()
+
+# Given a version like v7.0A, looks for an SDK in the registry under "Microsoft SDKs".
+# If the given version might be in both HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows
+# and HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots aka "Windows Kits",
+# use this macro first, since these registry keys usually have more information.
+#
+# Pass a "default" build number as an extra argument in case we can't find it.
+function(_winsdk_check_microsoft_sdks_registry _winsdkver)
+	set(SDKKEY "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\${_winsdkver}")
+	get_filename_component(_sdkdir
+		"[${SDKKEY};InstallationFolder]"
+		ABSOLUTE)
+
+	set(_sdkname "Windows SDK ${_winsdkver}")
+
+	# Default build number passed as extra argument
+	set(_build ${ARGN})
+	# See if the registry holds a Microsoft-mutilated, err, designated, product name
+	# (just using get_filename_component to execute the registry lookup)
+	get_filename_component(_sdkproductname
+		"[${SDKKEY};ProductName]"
+		NAME)
+	if(NOT "${_sdkproductname}" MATCHES "registry")
+		# Got a product name
+		set(_sdkname "${_sdkname} (${_sdkproductname})")
+	endif()
+
+	# try for a version to augment our name
+	# (just using get_filename_component to execute the registry lookup)
+	get_filename_component(_sdkver
+		"[${SDKKEY};ProductVersion]"
+		NAME)
+	if(NOT "${_sdkver}" MATCHES "registry" AND NOT MATCHES)
+		# Got a version
+		if(NOT "${_sdkver}" MATCHES "\\.\\.")
+			# and it's not an invalid one with two dots in it:
+			# use to override the default build
+			set(_build ${_sdkver})
+			if(NOT "${_sdkname}" MATCHES "${_sdkver}")
+				# Got a version that's not already in the name, let's use it to improve our name.
+				set(_sdkname "${_sdkname} (${_sdkver})")
+			endif()
+		endif()
+	endif()
+	_winsdk_conditional_append("${_sdkname}" "${_build}" "${_sdkdir}")
+endfunction()
+
+# Given a name for identification purposes, the build number, and a key (technically a "value name")
+# corresponding to a Windows SDK packaged as a "Windows Kit", look for it
+# in HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots
+# Note that the key or "value name" tends to be something weird like KitsRoot81 -
+# no easy way to predict, just have to observe them in the wild.
+# Doesn't hurt to also try _winsdk_check_microsoft_sdks_registry for these:
+# sometimes you get keys in both parts of the registry (in the wow64 portion especially),
+# and the non-"Windows Kits" location is often more descriptive.
+function(_winsdk_check_windows_kits_registry _winkit_name _winkit_build _winkit_key)
+	get_filename_component(_sdkdir
+		"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;${_winkit_key}]"
+		ABSOLUTE)
+	_winsdk_conditional_append("${_winkit_name}" "${_winkit_build}" "${_sdkdir}")
+endfunction()
+
+# Given a name for indentification purposes, the build number, and the associated package GUID,
+# look in the registry under both HKLM and HKCU in \\SOFTWARE\\Microsoft\\MicrosoftSDK\\InstalledSDKs\\
+# for that guid and the SDK it points to.
+function(_winsdk_check_platformsdk_registry _platformsdkname _build _platformsdkguid)
+	foreach(_winsdk_hive HKEY_LOCAL_MACHINE HKEY_CURRENT_USER)
 		get_filename_component(_sdkdir
-			"[HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]"
+			"[${_winsdk_hive}\\SOFTWARE\\Microsoft\\MicrosoftSDK\\InstalledSDKs\\${_platformsdkguid};Install Dir]"
 			ABSOLUTE)
-		if(EXISTS "${_sdkdir}")
-			list(APPEND _preferred_sdk_dirs "${_sdkdir}")
-		endif()
-
-		# System-wide current Windows SDK for VS2005/2008
-		get_filename_component(_sdkdir
-			"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]"
-			ABSOLUTE)
-		if(EXISTS "${_sdkdir}")
-			list(APPEND _preferred_sdk_dirs "${_sdkdir}")
-		endif()
-	endif()
-
+		_winsdk_conditional_append("${_platformsdkname} (${_build})" "${_build}" "${_sdkdir}")
+	endforeach()
+endfunction()
+
+###
+# Detect toolchain information: to know whether it's OK to use Vista+ only SDKs
+###
+set(_winsdk_vistaonly_ok OFF)
+if(MSVC AND NOT _WINDOWSSDK_IGNOREMSVC)
 	# VC 10 and older has broad target support
 	if(MSVC_VERSION LESS 1700)
 		# VC 11 by default targets Vista and later only, so we can add a few more SDKs that (might?) only work on vista+
@@ -90,179 +213,236 @@
 	else()
 		# OK, we're VC11 or newer and not using a backlevel or XP-compatible toolset.
 		# These versions have no XP (and possibly Vista pre-SP1) support
-		if((NOT WINDOWSSDK_FOUND) AND (NOT WindowsSDK_FIND_QUIETLY))
+		set(_winsdk_vistaonly_ok ON)
+		if(_WINDOWSSDK_ANNOUNCE)
 			message(STATUS "FindWindowsSDK: Detected Visual Studio 2012 or newer, not using the _xp toolset variant: including SDK versions that drop XP support in search!")
 		endif()
-		if(NOT MSVC_VERSION LESS 1800)
-			# These require at least Visual Studio 2013 (VC12)
-			list(APPEND _winsdk_vistaonly
-				v10.0A
-
-				# Windows Software Development Kit (SDK) for Windows 10
-				v10.0
-
-				# Windows Software Development Kit (SDK) for Windows 8.1
-				# http://msdn.microsoft.com/en-gb/windows/desktop/bg162891
-				v8.1)
-			list(APPEND _winsdk_kits
-				"Windows Kits 10:KitsRoot10"
-				"Windows Kits 8.1:KitsRoot81")
-		endif()
-		list(APPEND _winsdk_kits
-			"Windows Kits 8.0:KitsRoot")
-		list(APPEND _winsdk_vistaonly
-
-			# Included in Visual Studio 2012
-			v8.0A
-
-			# Microsoft Windows SDK for Windows 8 and .NET Framework 4.5
-			# This is the first version to also include the DirectX SDK
-			# http://msdn.microsoft.com/en-US/windows/desktop/hh852363.aspx
-			v8.0
-
-			# Microsoft Windows SDK for Windows 7 and .NET Framework 4
-			# http://www.microsoft.com/downloads/en/details.aspx?FamilyID=6b6c21d2-2006-4afa-9702-529fa782d63b
-			v7.1
-			)
-	endif()
-	foreach(_winkit ${_winsdk_kits})
-		string(REGEX REPLACE "[^:]*:" "" _winkit_key "${_winkit}")
-		string(REGEX REPLACE ":[^:]*" "" _winkit_name "${_winkit}")
+	endif()
+endif()
+if(_WINDOWSSDK_IGNOREMSVC)
+	set(_winsdk_vistaonly_ok ON)
+endif()
+
+###
+# MSVC version checks - keeps messy conditionals in one place
+# (messy because of _WINDOWSSDK_IGNOREMSVC)
+###
+set(_winsdk_msvc_greater_1200 OFF)
+if(_WINDOWSSDK_IGNOREMSVC OR (MSVC AND (MSVC_VERSION GREATER 1200)))
+	set(_winsdk_msvc_greater_1200 ON)
+endif()
+# Newer than VS .NET/VS Toolkit 2003
+set(_winsdk_msvc_greater_1310 OFF)
+if(_WINDOWSSDK_IGNOREMSVC OR (MSVC AND (MSVC_VERSION GREATER 1310)))
+	set(_winsdk_msvc_greater_1310 ON)
+endif()
+
+# VS2005/2008
+set(_winsdk_msvc_less_1600 OFF)
+if(_WINDOWSSDK_IGNOREMSVC OR (MSVC AND (MSVC_VERSION LESS 1600)))
+	set(_winsdk_msvc_less_1600 ON)
+endif()
+
+# VS2013+
+set(_winsdk_msvc_not_less_1800 OFF)
+if(_WINDOWSSDK_IGNOREMSVC OR (MSVC AND (NOT MSVC_VERSION LESS 1800)))
+	set(_winsdk_msvc_not_less_1800 ON)
+endif()
+
+###
+# START body of find module
+###
+if(_winsdk_msvc_greater_1310) # Newer than VS .NET/VS Toolkit 2003
+	###
+	# Look for "preferred" SDKs
+	###
+
+	# Environment variable for SDK dir
+	if(EXISTS "$ENV{WindowsSDKDir}" AND (NOT "$ENV{WindowsSDKDir}" STREQUAL ""))
+		_winsdk_conditional_append_preferred("WindowsSDKDir environment variable" "$ENV{WindowsSDKDir}")
+	endif()
+
+	if(_winsdk_msvc_less_1600)
+		# Per-user current Windows SDK for VS2005/2008
 		get_filename_component(_sdkdir
-			"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;${_winkit_key}]"
+			"[HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]"
 			ABSOLUTE)
-		_winsdk_conditional_append("${_winkit_name}" "${_sdkdir}")
-	endforeach()
-	foreach(_winsdkver
-		${_winsdk_vistaonly}
-
-		# Included in Visual Studio 2013
-		# Includes the v120_xp toolset
-		v8.1A
-
-		# Included with VS 2012 Update 1 or later
-		# Introduces v110_xp toolset
-		v7.1A
-
-		# Included with VS 2010
-		v7.0A
-
-		# Windows SDK for Windows 7 and .NET Framework 3.5 SP1
-		# Works with VC9
-		#http://www.microsoft.com/en-us/download/details.aspx?id=18950
-		v7.0
-
-		# Two versions call themselves "v6.1":
-		# Older:
-		# Windows Vista Update & .NET 3.0 SDK
-		# http://www.microsoft.com/en-us/download/details.aspx?id=14477
-
-		# Newer:
-		# Windows Server 2008 & .NET 3.5 SDK
-		# may have broken VS9SP1? they recommend v7.0 instead, or a KB...
-		# http://www.microsoft.com/en-us/download/details.aspx?id=24826
-		v6.1
-
-		# Included in VS 2008
-		v6.0A
-
-		# Microsoft Windows Software Development Kit for Windows Vista and .NET Framework 3.0 Runtime Components
-		# http://blogs.msdn.com/b/stanley/archive/2006/11/08/microsoft-windows-software-development-kit-for-windows-vista-and-net-framework-3-0-runtime-components.aspx
-		v6.0)
-
+		_winsdk_conditional_append_preferred("Per-user current Windows SDK" "${_sdkdir}")
+
+		# System-wide current Windows SDK for VS2005/2008
 		get_filename_component(_sdkdir
-			"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\${_winsdkver};InstallationFolder]"
+			"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]"
 			ABSOLUTE)
-		_winsdk_conditional_append("Windows SDK ${_winsdkver}" "${_sdkdir}")
-	endforeach()
-endif()
-if(MSVC AND MSVC_VERSION GREATER 1200)
-	foreach(_platformsdkinfo
-		"D2FF9F89-8AA2-4373-8A31-C838BF4DBBE1_Microsoft Platform SDK for Windows Server 2003 R2"
-		"8F9E5EF3-A9A5-491B-A889-C58EFFECE8B3_Microsoft Platform SDK for Windows Server 2003 SP1")
-		string(SUBSTRING "${_platformsdkinfo}" 0 36 _platformsdkguid)
-		string(SUBSTRING "${_platformsdkinfo}" 37 -1 _platformsdkname)
-		foreach(HIVE HKEY_LOCAL_MACHINE HKEY_CURRENT_USER)
-			get_filename_component(_sdkdir
-				"[${HIVE}\\SOFTWARE\\Microsoft\\MicrosoftSDK\\InstalledSDKs\\${_platformsdkguid};Install Dir]"
-				ABSOLUTE)
-			_winsdk_conditional_append("${_platformsdkname}" "${_sdkdir}")
-		endforeach()
-	endforeach()
-endif()
-
-set(_win_sdk_versanddirs
-	"${_win_sdk_versanddirs}"
-	CACHE
-	INTERNAL
-	"mapping between windows sdk version locations and names"
-	FORCE)
+		_winsdk_conditional_append_preferred("System-wide current Windows SDK" "${_sdkdir}")
+	endif()
+
+	###
+	# Begin the massive list of SDK searching!
+	###
+	if(_winsdk_vistaonly_ok AND _winsdk_msvc_not_less_1800)
+		# These require at least Visual Studio 2013 (VC12)
+
+		_winsdk_check_microsoft_sdks_registry(v10.0A)
+
+		# Windows Software Development Kit (SDK) for Windows 10
+		_winsdk_check_microsoft_sdks_registry(v10.0 10.0.10240.0)
+		_winsdk_check_windows_kits_registry("Windows Kits 10" 10.0.10240.0 KitsRoot10)
+	endif() # vista-only and 2013+
+
+	# Included in Visual Studio 2013
+	# Includes the v120_xp toolset
+	_winsdk_check_microsoft_sdks_registry(v8.1A 8.1.51636)
+
+	if(_winsdk_vistaonly_ok AND _winsdk_msvc_not_less_1800)
+		# Windows Software Development Kit (SDK) for Windows 8.1
+		# http://msdn.microsoft.com/en-gb/windows/desktop/bg162891
+		_winsdk_check_microsoft_sdks_registry(v8.1 8.1.25984.0)
+		_winsdk_check_windows_kits_registry("Windows Kits 8.1" 8.1.25984.0 KitsRoot81)
+	endif() # vista-only and 2013+
+
+	if(_winsdk_vistaonly_ok)
+		# Included in Visual Studio 2012
+		_winsdk_check_microsoft_sdks_registry(v8.0A 8.0.50727)
+
+		# Microsoft Windows SDK for Windows 8 and .NET Framework 4.5
+		# This is the first version to also include the DirectX SDK
+		# http://msdn.microsoft.com/en-US/windows/desktop/hh852363.aspx
+		_winsdk_check_microsoft_sdks_registry(v8.0 6.2.9200.16384)
+		_winsdk_check_windows_kits_registry("Windows Kits 8.0" 6.2.9200.16384 KitsRoot)
+	endif() # vista-only
+
+	# Included with VS 2012 Update 1 or later
+	# Introduces v110_xp toolset
+	_winsdk_check_microsoft_sdks_registry(v7.1A 7.1.51106)
+	if(_winsdk_vistaonly_ok)
+		# Microsoft Windows SDK for Windows 7 and .NET Framework 4
+		# http://www.microsoft.com/downloads/en/details.aspx?FamilyID=6b6c21d2-2006-4afa-9702-529fa782d63b
+		_winsdk_check_microsoft_sdks_registry(v7.1 7.1.7600.0.30514)
+	endif() # vista-only
+
+	# Included with VS 2010
+	_winsdk_check_microsoft_sdks_registry(v7.0A 6.1.7600.16385)
+
+	# Windows SDK for Windows 7 and .NET Framework 3.5 SP1
+	# Works with VC9
+	# http://www.microsoft.com/en-us/download/details.aspx?id=18950
+	_winsdk_check_microsoft_sdks_registry(v7.0 6.1.7600.16385)
+
+	# Two versions call themselves "v6.1":
+	# Older:
+	# Windows Vista Update & .NET 3.0 SDK
+	# http://www.microsoft.com/en-us/download/details.aspx?id=14477
+
+	# Newer:
+	# Windows Server 2008 & .NET 3.5 SDK
+	# may have broken VS9SP1? they recommend v7.0 instead, or a KB...
+	# http://www.microsoft.com/en-us/download/details.aspx?id=24826
+	_winsdk_check_microsoft_sdks_registry(v6.1 6.1.6000.16384.10)
+
+	# Included in VS 2008
+	_winsdk_check_microsoft_sdks_registry(v6.0A 6.1.6723.1)
+
+	# Microsoft Windows Software Development Kit for Windows Vista and .NET Framework 3.0 Runtime Components
+	# http://blogs.msdn.com/b/stanley/archive/2006/11/08/microsoft-windows-software-development-kit-for-windows-vista-and-net-framework-3-0-runtime-components.aspx
+	_winsdk_check_microsoft_sdks_registry(v6.0 6.0.6000.16384)
+endif()
+
+# Let's not forget the Platform SDKs, which sometimes are useful!
+if(_winsdk_msvc_greater_1200)
+	_winsdk_check_platformsdk_registry("Microsoft Platform SDK for Windows Server 2003 R2" "5.2.3790.2075.51" "D2FF9F89-8AA2-4373-8A31-C838BF4DBBE1")
+	_winsdk_check_platformsdk_registry("Microsoft Platform SDK for Windows Server 2003 SP1" "5.2.3790.1830.15" "8F9E5EF3-A9A5-491B-A889-C58EFFECE8B3")
+endif()
+###
+# Finally, look for "preferred" SDKs
+###
+if(_winsdk_msvc_greater_1310) # Newer than VS .NET/VS Toolkit 2003
+
+
+	# Environment variable for SDK dir
+	if(EXISTS "$ENV{WindowsSDKDir}" AND (NOT "$ENV{WindowsSDKDir}" STREQUAL ""))
+		_winsdk_conditional_append_preferred("WindowsSDKDir environment variable" "$ENV{WindowsSDKDir}")
+	endif()
+
+	if(_winsdk_msvc_less_1600)
+		# Per-user current Windows SDK for VS2005/2008
+		get_filename_component(_sdkdir
+			"[HKEY_CURRENT_USER\\Software\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]"
+			ABSOLUTE)
+		_winsdk_conditional_append_preferred("Per-user current Windows SDK" "${_sdkdir}")
+
+		# System-wide current Windows SDK for VS2005/2008
+		get_filename_component(_sdkdir
+			"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]"
+			ABSOLUTE)
+		_winsdk_conditional_append_preferred("System-wide current Windows SDK" "${_sdkdir}")
+	endif()
+endif()
+

 function(windowssdk_name_lookup _dir _outvar)
 	list(FIND _win_sdk_versanddirs "${_dir}" _diridx)
-	math(EXPR _nameidx "${_diridx} - 1")
-	if(${_nameidx} GREATER -1)
-		list(GET _win_sdk_versanddirs ${_nameidx} _sdkname)
+	math(EXPR _idx "${_diridx} - 1")
+	if(${_idx} GREATER -1)
+		list(GET _win_sdk_versanddirs ${_idx} _ret)
 	else()
-		set(_sdkname "NOTFOUND")
-	endif()
-	set(${_outvar} "${_sdkname}" PARENT_SCOPE)
-endfunction()
-
+		set(_ret "NOTFOUND")
+	endif()
+	set(${_outvar} "${_ret}" PARENT_SCOPE)
+endfunction()
+
+function(windowssdk_build_lookup _dir _outvar)
+	list(FIND _win_sdk_buildsanddirs "${_dir}" _diridx)
+	math(EXPR _idx "${_diridx} - 1")
+	if(${_idx} GREATER -1)
+		list(GET _win_sdk_buildsanddirs ${_idx} _ret)
+	else()
+		set(_ret "NOTFOUND")
+	endif()
+	set(${_outvar} "${_ret}" PARENT_SCOPE)
+endfunction()
+
+# If we found something...
 if(_win_sdk_dirs)
-	# Remove duplicates
-	list(REMOVE_DUPLICATES _win_sdk_dirs)
 	list(GET _win_sdk_dirs 0 WINDOWSSDK_LATEST_DIR)
 	windowssdk_name_lookup("${WINDOWSSDK_LATEST_DIR}"
 		WINDOWSSDK_LATEST_NAME)
 	set(WINDOWSSDK_DIRS ${_win_sdk_dirs})
-endif()
-if(_preferred_sdk_dirs)
-	list(GET _preferred_sdk_dirs 0 WINDOWSSDK_PREFERRED_DIR)
-	windowssdk_name_lookup("${WINDOWSSDK_LATEST_DIR}"
-		WINDOWSSDK_PREFERRED_NAME)
-	set(WINDOWSSDK_PREFERRED_FIRST_DIRS
-		${_preferred_sdk_dirs}
-		${_win_sdk_dirs})
-	list(REMOVE_DUPLICATES WINDOWSSDK_PREFERRED_FIRST_DIRS)
-	set(WINDOWSSDK_FOUND_PREFERENCE ON)
-
-	# In case a preferred dir was found that isn't found otherwise
-	#set(WINDOWSSDK_DIRS ${WINDOWSSDK_DIRS} ${WINDOWSSDK_PREFERRED_FIRST_DIRS})
-	#list(REMOVE_DUPLICATES WINDOWSSDK_DIRS)
-else()
+
+	# Fallback, in case no preference found.
 	set(WINDOWSSDK_PREFERRED_DIR "${WINDOWSSDK_LATEST_DIR}")
 	set(WINDOWSSDK_PREFERRED_NAME "${WINDOWSSDK_LATEST_NAME}")
 	set(WINDOWSSDK_PREFERRED_FIRST_DIRS ${WINDOWSSDK_DIRS})
 	set(WINDOWSSDK_FOUND_PREFERENCE OFF)
 endif()

+# If we found indications of a user preference...
+if(_win_sdk_preferred_sdk_dirs)
+	list(GET _win_sdk_preferred_sdk_dirs 0 WINDOWSSDK_PREFERRED_DIR)
+	windowssdk_name_lookup("${WINDOWSSDK_PREFERRED_DIR}"
+		WINDOWSSDK_PREFERRED_NAME)
+	set(WINDOWSSDK_PREFERRED_FIRST_DIRS
+		${_win_sdk_preferred_sdk_dirs}
+		${_win_sdk_dirs})
+	list(REMOVE_DUPLICATES WINDOWSSDK_PREFERRED_FIRST_DIRS)
+	set(WINDOWSSDK_FOUND_PREFERENCE ON)
+endif()
+
 include(FindPackageHandleStandardArgs)
 find_package_handle_standard_args(WindowsSDK
 	"No compatible version of the Windows SDK or Platform SDK found."
 	WINDOWSSDK_DIRS)

 if(WINDOWSSDK_FOUND)
-	if(NOT _winsdk_remembered_dirs STREQUAL WINDOWSSDK_DIRS)
-		set(_winsdk_remembered_dirs
-			"${WINDOWSSDK_DIRS}"
-			CACHE
-			INTERNAL
-			""
-			FORCE)
-		if(NOT WindowsSDK_FIND_QUIETLY)
-			foreach(_sdkdir ${WINDOWSSDK_DIRS})
-				windowssdk_name_lookup("${_sdkdir}" _sdkname)
-				message(STATUS " - Found ${_sdkname} at ${_sdkdir}")
-			endforeach()
-		endif()
-	endif()
-
 	# Internal: Architecture-appropriate library directory names.
 	if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "ARM")
-		set(_winsdk_archbare /arm) # what the architecture used to be called in oldest SDKs
-		set(_winsdk_arch arm) # what the architecture used to be called
-		set(_winsdk_arch8 arm) # what the WDK for Win8+ calls this architecture
+		if(CMAKE_SIZEOF_VOID_P MATCHES "8")
+			# Only supported in Win10 SDK and up.
+			set(_winsdk_arch8 arm64) # what the WDK for Win8+ calls this architecture
+		else()
+			set(_winsdk_archbare /arm) # what the architecture used to be called in oldest SDKs
+			set(_winsdk_arch arm) # what the architecture used to be called
+			set(_winsdk_arch8 arm) # what the WDK for Win8+ calls this architecture
+		endif()
 	else()
 		if(CMAKE_SIZEOF_VOID_P MATCHES "8")
 			set(_winsdk_archbare /x64) # what the architecture used to be called in oldest SDKs
@@ -293,20 +473,46 @@
 	endfunction()
 	function(get_windowssdk_library_dirs _winsdk_dir _var)
 		set(_result)
-		foreach(_suffix
+		set(_suffixes
 			"lib${_winsdk_archbare}" # SDKs like 7.1A
+			"lib/${_winsdk_arch}" # just because some SDKs have x86 dir and root dir
 			"lib/w2k/${_winsdk_arch}" # Win2k min requirement
 			"lib/wxp/${_winsdk_arch}" # WinXP min requirement
 			"lib/wnet/${_winsdk_arch}" # Win Server 2003 min requirement
-			"lib/wlh/${_winsdk_arch}" # Win Vista ("Long Horn") min requirement
+			"lib/wlh/${_winsdk_arch}"
 			"lib/wlh/um/${_winsdk_arch8}" # Win Vista ("Long Horn") min requirement
-			"lib/win7/${_winsdk_arch}" # Win 7 min requirement
+			"lib/win7/${_winsdk_arch}"
 			"lib/win7/um/${_winsdk_arch8}" # Win 7 min requirement
-			"lib/win8/um/${_winsdk_arch8}" # Win 8 min requirement
-			"lib/win8/km/${_winsdk_arch8}" # Win 8 min requirement
-			"lib/winv6.3/km/${_winsdk_arch8}" # Win 8.1 min requirement
-			"lib/winv6.3/um/${_winsdk_arch8}" # Win 8.1 min requirement
 		)
+		foreach(_ver
+			wlh # Win Vista ("Long Horn") min requirement
+			win7 # Win 7 min requirement
+			win8 # Win 8 min requirement
+			winv6.3 # Win 8.1 min requirement
+		)
+
+			list(APPEND _suffixes
+				"lib/${_ver}/${_winsdk_arch}"
+				"lib/${_ver}/um/${_winsdk_arch8}"
+				"lib/${_ver}/km/${_winsdk_arch8}"
+			)
+		endforeach()
+
+		# Look for WDF libraries in Win10+ SDK
+		foreach(_mode umdf kmdf)
+			file(GLOB _wdfdirs RELATIVE "${_winsdk_dir}" "${_winsdk_dir}/lib/wdf/${_mode}/${_winsdk_arch8}/*")
+			if(_wdfdirs)
+				list(APPEND _suffixes ${_wdfdirs})
+			endif()
+		endforeach()
+
+		foreach(_win10ver ${_winsdk_win10vers})
+			foreach(_component um km ucrt mmos)
+				list(APPEND _suffixes "lib/${_win10ver}/${_component}/${_winsdk_arch8}")
+			endforeach()
+		endforeach()
+
+		foreach(_suffix ${_suffixes})
 			# Check to see if a library actually exists here.
 			file(GLOB _libs "${_winsdk_dir}/${_suffix}/*.lib")
 			if(_libs)
@@ -315,19 +521,28 @@
 		endforeach()
 		if(NOT _result)
 			set(_result NOTFOUND)
+		else()
+			list(REMOVE_DUPLICATES _result)
 		endif()
 		set(${_var} ${_result} PARENT_SCOPE)
 	endfunction()
 	function(get_windowssdk_include_dirs _winsdk_dir _var)
 		set(_result)
-		foreach(_suffix
-			"Include"
-			"Include/shared"
-			"Include/um"
-			"Include/winrt"
-			"Include/km"
-			"Include/wdf"
-		)
+
+		set(_subdirs shared um winrt km wdf mmos ucrt)
+		set(_suffixes Include)
+
+		foreach(_dir ${_subdirs})
+			list(APPEND _suffixes "Include/${_dir}")
+		endforeach()
+
+		foreach(_ver ${_winsdk_win10vers})
+			foreach(_dir ${_subdirs})
+				list(APPEND _suffixes "Include/${_ver}/${_dir}")
+			endforeach()
+		endforeach()
+
+		foreach(_suffix ${_suffixes})
 			# Check to see if a header file actually exists here.
 			file(GLOB _headers "${_winsdk_dir}/${_suffix}/*.h")
 			if(_headers)
@@ -336,6 +551,8 @@
 		endforeach()
 		if(NOT _result)
 			set(_result NOTFOUND)
+		else()
+			list(REMOVE_DUPLICATES _result)
 		endif()
 		set(${_var} ${_result} PARENT_SCOPE)
 	endfunction()


Updated InstallPackage.cmake script with changes from h5pp

Former-commit-id: d6db65af74146c152d0b9ddea2bd0c574e9eabe2

--- cmake/InstallPackage.cmake
+++ cmake/InstallPackage.cmake
@@ -50,10 +50,10 @@
     endif()

     # Further parsing / override defaults
-    set(pkg_build_dir ${PKG_BUILD_DIR}/${pkg_name})
-    set(pkg_install_dir   ${PKG_INSTALL_DIR})
+    set(pkg_build_dir   ${PKG_BUILD_DIR}/${pkg_name})
+    set(pkg_install_dir ${PKG_INSTALL_DIR})
     set(pkg_target_name ${pkg_name}::${pkg_name})
-    set(pkg_find_name ${pkg_name})
+    set(pkg_find_name   ${pkg_name})
     if(PKG_INSTALL_PREFIX_PKGNAME)
         set(pkg_install_dir ${pkg_install_dir}/${pkg_name})
     endif()
@@ -102,11 +102,11 @@
         message(FATAL_ERROR "Could not install ${pkg_name}: dependencies missing [${PKG_MISSING_TARGET}]")
     endif()

-    # We set variables here that allows us to find packages with CMAKE_PREFIX_PATH
-    set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};${pkg_install_dir}" CACHE INTERNAL "Paths for find_package lookup")
+    # Append to CMAKE_PREFIX_PATH so we can find the packages later
+    set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};${pkg_install_dir};${PKG_INSTALL_DIR}" CACHE INTERNAL "Paths for find_package lookup" FORCE)
     list(REMOVE_DUPLICATES CMAKE_PREFIX_PATH)

-    set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH}" CACHE STRING "" FORCE)
+    # Try finding config files before modules
     set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)

     if(PKG_LIBRARY_NAMES)
@@ -125,22 +125,26 @@
             find_package(${pkg_find_name} ${PKG_VERSION} ${COMPONENTS} ${PKG_COMPONENTS} ${QUIET})
         endif()
     elseif(PKG_MODULE)
-        find_package(${pkg_find_name} ${PKG_VERSION} ${COMPONENTS} ${PKG_COMPONENTS} ${QUIET})
-    else()
-        find_package(${pkg_find_name} ${PKG_VERSION}
-                HINTS ${PKG_HINTS}
-                PATHS ${PKG_PATHS}
-                PATH_SUFFIXES ${PKG_PATH_SUFFIXES}
-                ${COMPONENTS} ${PKG_COMPONENTS}
-                ${CONFIG} ${QUIET}
-                # These lets us ignore system packages
-                NO_SYSTEM_ENVIRONMENT_PATH #5
-                NO_CMAKE_PACKAGE_REGISTRY #6
-                NO_CMAKE_SYSTEM_PATH #7
-                NO_CMAKE_SYSTEM_PACKAGE_REGISTRY #8
-                )
-    endif()
-    # Check if the package was found
+        if(NOT ${pkg_find_name}_FOUND)
+            find_package(${pkg_find_name} ${PKG_VERSION} ${COMPONENTS} ${PKG_COMPONENTS} ${QUIET})
+        endif()
+    else()
+        if(NOT ${pkg_find_name}_FOUND)
+            find_package(${pkg_find_name} ${PKG_VERSION}
+                    HINTS ${PKG_HINTS}
+                    PATHS ${PKG_PATHS}
+                    PATH_SUFFIXES ${PKG_PATH_SUFFIXES}
+                    ${COMPONENTS} ${PKG_COMPONENTS}
+                    ${CONFIG} ${QUIET}
+                    # These lets us ignore system packages
+                    NO_SYSTEM_ENVIRONMENT_PATH #5
+                    NO_CMAKE_PACKAGE_REGISTRY #6
+                    NO_CMAKE_SYSTEM_PATH #7
+                    NO_CMAKE_SYSTEM_PACKAGE_REGISTRY #8
+                    )
+        endif()
+    endif()
+    # Set _FOUND variables for alternate names and components
     if(NOT ${pkg_name}_FOUND)
         if(${pkg_find_name}_FOUND)
             set(${pkg_name}_FOUND TRUE)
@@ -154,7 +158,7 @@
             endforeach()
         endif()
     endif()
-
+    # Check if the package was found
     if(${pkg_name}_FOUND)
         if(PKG_DEPENDS)
             target_link_libraries(${pkg_target_name} INTERFACE ${PKG_DEPENDS})


cmake,LinuxPackaging: only set exclusion list for RPMs if RPM cmd found

Minor optimization.

Signed-off-by: Alexandru Ardelean <685557f6b7c225d86b536740313ed51b24843a58@analog.com>

--- cmake/LinuxPackaging.cmake
+++ cmake/LinuxPackaging.cmake
@@ -7,19 +7,19 @@
 	set(CPACK_PACKAGE_RELOCATABLE OFF)
 	set(CPACK_GENERATOR ${CPACK_GENERATOR};RPM)
 	set(CPACK_RPM_PACKAGE_REQUIRES "libaio >= 0.3.107, avahi >= 0.6.25, libusb1 >= 1.0.9, libxml2 >= 2.7.6")
+
+	# Add these for CentOS 7
+	set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
+		/lib
+		/lib/udev
+		/lib/udev/rules.d
+		/usr/sbin
+		/usr/lib/python2.7
+		/usr/lib/python2.7/site-packages
+		/usr/lib/pkgconfig
+		/usr/lib64/pkgconfig
+	)
 endif()
-
-# Add these for CentOS 7
-set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
-	/lib
-	/lib/udev
-	/lib/udev/rules.d
-	/usr/sbin
-	/usr/lib/python2.7
-	/usr/lib/python2.7/site-packages
-	/usr/lib/pkgconfig
-	/usr/lib64/pkgconfig
-)

 set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
 set(CPACK_PACKAGE_VERSION_MAJOR ${LIBIIO_VERSION_MAJOR})


Revert silly changes

Revert silly changes

--- cmake/ThirdPartyFFTW.cmake
+++ cmake/ThirdPartyFFTW.cmake
@@ -24,8 +24,10 @@
         )
         SET(FFTW_LIB fftw3)
         MARK_AS_ADVANCED(FFTW_LIB)
-        MESSAGE(STATUS "Build FFTW: ${TPSRC}/dist/lib/lib${FFTW_LIB}.so")
+        INCLUDE_DIRECTORIES(${TPDIST}/include)
+        MESSAGE(STATUS "Build FFTW: ${TPDIST}/lib/lib${FFTW_LIB}.so")
     ELSE ()
         INCLUDE (FindFFTW)
+        INCLUDE_DIRECTORIES(${FFTW_INCLUDE_DIR})
     ENDIF()
 ENDIF( NEKTAR_USE_FFTW )


PC_REQUIRES_TAG always set locally so drop setting a default global value
for that variable/

Improve commentary concerning the NON_TRANSITIVE option.

Implement the FORCE_EXTERNAL_STATIC option for the (internal) static
library case (NOT BUILD_SHARED_LIBS) to force CMake to find and use
only external libraries with a *.a suffix (i.e., static libraries).
This suffix trick only works with UNIX so FORCE_EXTERNAL_STATIC is
ignored in all other cases. The option is experimental.  In fact, it
still does not completely work at this time because of pkg-config
complications. Therefore, its default value is OFF.

svn path=/trunk/; revision=12055

--- cmake/modules/plplot.cmake
+++ cmake/modules/plplot.cmake
@@ -22,12 +22,24 @@
 # libraries are all shared by default
 option(BUILD_SHARED_LIBS "Build shared libraries" ON)

-# OFF means libraries are transitively linked by default.
+if(NOT BUILD_SHARED_LIBS)
+  option(FORCE_EXTERNAL_STATIC "Force external UNIX libraries to be static" OFF)
+endif(NOT BUILD_SHARED_LIBS)
+
+# CYGWIN eliminated here because .a suffix is not sufficient to guarantee a
+# static library on that platform.
+if(UNIX AND NOT CYGWIN AND FORCE_EXTERNAL_STATIC)
+  # All find_library commands append this suffix to the searched name so
+  # this always forces find_library to find only the Unix static library
+  # if it exists or fail if it doesn't exist.
+  set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
+endif(UNIX AND NOT CYGWIN AND FORCE_EXTERNAL_STATIC)
+
+# OFF means shared libraries (but never static libraries) are
+# transitively linked by default by CMake and also by pkg-config (used
+# to generate compile and link flags for the traditional build and
+# test system of the installed examples).
 option(NON_TRANSITIVE "Experimental option to try non-transitive linking" OFF)
-# For now use this default which causes transitive linking of software built
-# with our pkg-config files (unless PC_REQUIRES_TAG specifically overridden
-# for particular language bindings with Requires.private).
-set(PC_REQUIRES_TAG "Requires")

 # Color maps (discrete and continuous) to use by default
 if(NOT DEFAULT_CMAP0_FILE)


The python stuff should be installed in an arch specific directory.  (Thanks
to Orion Poplawski for spotting this.)

svn path=/trunk/; revision=7373

--- cmake/modules/python.cmake
+++ cmake/modules/python.cmake
@@ -82,7 +82,7 @@
   set(
   PYTHON_ARG_STRING
   "-c \"from distutils import sysconfig\;"
-  "print sysconfig.get_python_lib(0,0,prefix='${CMAKE_INSTALL_EXEC_PREFIX}')\""
+  "print sysconfig.get_python_lib(1,0,prefix='${CMAKE_INSTALL_EXEC_PREFIX}')\""
   )
   exec_program(
   ${PYTHON_EXECUTABLE}


Adapt test flow for more complicated test case

--- test/module_test.cmake
+++ test/module_test.cmake
@@ -8,6 +8,14 @@
 set (OUTPUT_FILE_GPU ${CMAKE_CURRENT_SOURCE_DIR}/transformed_code_gpu.f90)
 set (REFERENCE_FILE_CPU ${CMAKE_CURRENT_SOURCE_DIR}/reference_cpu.f90)
 set (REFERENCE_FILE_GPU ${CMAKE_CURRENT_SOURCE_DIR}/reference_gpu.f90)
+
+if(HAS_EXTRA_MOD)
+  set (ORIGINAL_FILE_EXTRA ${CMAKE_CURRENT_SOURCE_DIR}/mo_column_extra.f90)
+  set (OUTPUT_FILE_EXTRA_CPU ${CMAKE_CURRENT_SOURCE_DIR}/transformed_code_extra_cpu.f90)
+  set (OUTPUT_FILE_EXTRA_GPU ${CMAKE_CURRENT_SOURCE_DIR}/transformed_code_extra_gpu.f90)
+  set (REFERENCE_FILE_EXTRA_CPU ${CMAKE_CURRENT_SOURCE_DIR}/reference_extra_cpu.f90)
+  set (REFERENCE_FILE_EXTRA_GPU ${CMAKE_CURRENT_SOURCE_DIR}/reference_extra_gpu.f90)
+endif()

 # Define executable file name
 set (EXECUTABLE_ORIGINAL original_code_${TEST_NAME})
@@ -31,7 +39,7 @@
 # Execute the CLAW compiler for CPU target
 add_custom_command(
   OUTPUT  ${OUTPUT_FILE_CPU}
-  COMMAND touch ${ORIGINAL_FILE}
+  COMMAND touch ${ORIGINAL_FILE} # to force new compilation
   COMMAND ${CLAWFC} ${OPTIONAL_FLAGS} --target=cpu ${DIRECTIVE_CPU} ${DEBUG_FLAG} -J ${XMOD_DIR} -o ${OUTPUT_FILE_CPU} ${ORIGINAL_FILE}
   WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
   DEPENDS ${ORIGINAL_FILE}
@@ -41,18 +49,55 @@
 # Execute the CLAW compiler for GPU target
 add_custom_command(
   OUTPUT  ${OUTPUT_FILE_GPU}
-  COMMAND touch ${ORIGINAL_FILE}
+  COMMAND touch ${ORIGINAL_FILE} # to force new compilation
   COMMAND ${CLAWFC} ${OPTIONAL_FLAGS} --target=gpu ${DIRECTIVE_GPU} ${DEBUG_FLAG} -J ${XMOD_DIR} -o ${OUTPUT_FILE_GPU} ${ORIGINAL_FILE}
   WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
   DEPENDS ${ORIGINAL_FILE}
   COMMENT "Translating CLAW directive with ${CLAWFC} for GPU target"
 )

-# Target for the transformation
-add_custom_target(
-  transform-${TEST_NAME}
-  DEPENDS ${MAIN_CPU} ${OUTPUT_FILE_CPU} ${MAIN_GPU} ${OUTPUT_FILE_GPU} ${EXECUTABLE_ORIGINAL} ${EXECUTABLE_TRANSFORMED_CPU} ${EXECUTABLE_TRANSFORMED_GPU}
-)
+if(HAS_EXTRA_MOD)
+  # Execute the CLAW compiler for CPU target
+  add_custom_command(
+    OUTPUT  ${OUTPUT_FILE_EXTRA_CPU}
+    COMMAND touch ${ORIGINAL_FILE_EXTRA} # to force new compilation
+    COMMAND ${CLAWFC} ${OPTIONAL_FLAGS} --target=cpu ${DIRECTIVE_CPU} ${DEBUG_FLAG} -J ${XMOD_DIR} -o ${OUTPUT_FILE_EXTRA_CPU} ${ORIGINAL_FILE_EXTRA}
+    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+    DEPENDS ${ORIGINAL_FILE_EXTRA}
+    COMMENT "Translating CLAW directive with ${CLAWFC} for CPU target"
+  )
+
+  # Execute the CLAW compiler for GPU target
+  add_custom_command(
+    OUTPUT  ${OUTPUT_FILE_EXTRA_GPU}
+    COMMAND touch ${ORIGINAL_FILE_EXTRA} # to force new compilation
+    COMMAND ${CLAWFC} ${OPTIONAL_FLAGS} --target=gpu ${DIRECTIVE_GPU} ${DEBUG_FLAG} -J ${XMOD_DIR} -o ${OUTPUT_FILE_EXTRA_GPU} ${ORIGINAL_FILE_EXTRA}
+    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+    DEPENDS ${ORIGINAL_FILE_EXTRA}
+    COMMENT "Translating CLAW directive with ${CLAWFC} for GPU target"
+  )
+
+  # Target for the transformation
+  add_custom_target(
+    transform-${TEST_NAME}
+    DEPENDS
+    ${MAIN_CPU} ${OUTPUT_FILE_CPU} ${OUTPUT_FILE_EXTRA_CPU} ${MAIN_GPU}
+    ${OUTPUT_FILE_GPU} ${OUTPUT_FILE_EXTRA_GPU} ${EXECUTABLE_ORIGINAL}
+    ${EXECUTABLE_TRANSFORMED_CPU} ${EXECUTABLE_TRANSFORMED_GPU}
+  )
+
+else()
+
+  # Target for the transformation
+  add_custom_target(
+    transform-${TEST_NAME}
+    DEPENDS
+    ${MAIN_CPU} ${OUTPUT_FILE_CPU} ${MAIN_GPU} ${OUTPUT_FILE_GPU}
+    ${EXECUTABLE_ORIGINAL} ${EXECUTABLE_TRANSFORMED_CPU}
+    ${EXECUTABLE_TRANSFORMED_GPU}
+  )
+
+endif()

 # Target to clean the generated file (Output of clawfc)
 add_custom_target(
@@ -67,12 +112,26 @@
 # Define additional compilation flags
 set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${CLAW_TEST_FFP_FLAGS}")

-# Build the original code and the transformed code
-add_executable (${EXECUTABLE_ORIGINAL} EXCLUDE_FROM_ALL "${ORIGINAL_FILE}" "${MAIN_F90}")
-add_executable (${EXECUTABLE_TRANSFORMED_CPU} EXCLUDE_FROM_ALL "${OUTPUT_FILE_CPU}" "${MAIN_F90}")
-target_compile_definitions(${EXECUTABLE_TRANSFORMED_CPU} PRIVATE -D_CLAW)
-add_executable (${EXECUTABLE_TRANSFORMED_GPU} EXCLUDE_FROM_ALL "${OUTPUT_FILE_GPU}" "${MAIN_F90}")
-target_compile_definitions(${EXECUTABLE_TRANSFORMED_GPU} PRIVATE -D_CLAW)
+
+if(HAS_EXTRA_MOD)
+
+  # Build the original code and the transformed code
+  add_executable (${EXECUTABLE_ORIGINAL} EXCLUDE_FROM_ALL "${ORIGINAL_FILE}" "${ORIGINAL_FILE_EXTRA}" "${MAIN_F90}")
+  add_executable (${EXECUTABLE_TRANSFORMED_CPU} EXCLUDE_FROM_ALL "${OUTPUT_FILE_CPU}" "${OUTPUT_FILE_EXTRA_CPU}" "${MAIN_F90}")
+  target_compile_definitions(${EXECUTABLE_TRANSFORMED_CPU} PRIVATE -D_CLAW)
+  add_executable (${EXECUTABLE_TRANSFORMED_GPU} EXCLUDE_FROM_ALL "${OUTPUT_FILE_GPU}" "${OUTPUT_FILE_EXTRA_GPU}" "${MAIN_F90}")
+  target_compile_definitions(${EXECUTABLE_TRANSFORMED_GPU} PRIVATE -D_CLAW)
+
+else()
+
+  # Build the original code and the transformed code
+  add_executable (${EXECUTABLE_ORIGINAL} EXCLUDE_FROM_ALL "${ORIGINAL_FILE}" "${MAIN_F90}")
+  add_executable (${EXECUTABLE_TRANSFORMED_CPU} EXCLUDE_FROM_ALL "${OUTPUT_FILE_CPU}" "${MAIN_F90}")
+  target_compile_definitions(${EXECUTABLE_TRANSFORMED_CPU} PRIVATE -D_CLAW)
+  add_executable (${EXECUTABLE_TRANSFORMED_GPU} EXCLUDE_FROM_ALL "${OUTPUT_FILE_GPU}" "${MAIN_F90}")
+  target_compile_definitions(${EXECUTABLE_TRANSFORMED_GPU} PRIVATE -D_CLAW)
+
+endif()

 # Set target specific compilation options
 if(OPENACC_ENABLE)
@@ -91,6 +150,13 @@
   set_tests_properties(ast-compare-cpu-${TEST_NAME} PROPERTIES DEPENDS ast-transform-${TEST_NAME})
   set_tests_properties(ast-compare-gpu-${TEST_NAME} PROPERTIES DEPENDS ast-transform-${TEST_NAME})

+  if(HAS_EXTRA_MOD)
+    add_test(NAME ast-compare-cpu-extra-${TEST_NAME} COMMAND diff ${OUTPUT_FILE_EXTRA_CPU} ${REFERENCE_FILE_EXTRA_CPU})
+    add_test(NAME ast-compare-gpu-extra-${TEST_NAME} COMMAND diff ${OUTPUT_FILE_EXTRA_GPU} ${REFERENCE_FILE_EXTRA_GPU})
+    set_tests_properties(ast-compare-cpu-extra-${TEST_NAME} PROPERTIES DEPENDS ast-transform-${TEST_NAME})
+    set_tests_properties(ast-compare-gpu-extra-${TEST_NAME} PROPERTIES DEPENDS ast-transform-${TEST_NAME})
+  endif()
+
   # Compare the output of both executable
   if(OUTPUT_TEST)
     set (TEST_PARAMETERS_CPU "<(./${EXECUTABLE_ORIGINAL}) <(./${EXECUTABLE_TRANSFORMED_CPU})")


BUG: Explicitly trust elastix SVN certificate

Superbuild is broken because of an expired SSL certificate
on the elastix SVN repository host machine. This commit tries
to disable the check for a valid certificate. Might not work
on all platforms.

--- SuperBuild/External_Elastix.cmake
+++ SuperBuild/External_Elastix.cmake
@@ -7,6 +7,9 @@
 ExternalProject_Add( ${proj}
   SVN_REPOSITORY ${ELASTIX_REPOSITORY}
   SVN_REVISION -r ${ELASTIX_REVISION}
+  SVN_USERNAME "elastixguest"
+  SVN_PASSWORD "elastixguest"
+  SVN_TRUST_CERT 1
   UPDATE_COMMAND ""
   SOURCE_DIR ${proj}
   BINARY_DIR ${proj}-build


ENH: Update elastix to revision 5211

ENH: Update elastix to revision 5211

--- SuperBuild/External_Elastix.cmake
+++ SuperBuild/External_Elastix.cmake
@@ -2,7 +2,7 @@

 file( WRITE "${CMAKE_CURRENT_BINARY_DIR}/${proj}-build/CMakeCacheInit.txt" "${ep_common_cache}" )
 set( ELASTIX_REPOSITORY https://svn.bigr.nl/elastix/trunkpublic/ )
-set( ELASTIX_REVISION 5210 )
+set( ELASTIX_REVISION 5211 )

 ExternalProject_Add( ${proj}
   SVN_REPOSITORY ${ELASTIX_REPOSITORY}


Further fixing the source filtering.  Writing out logic in CMake is sooo brittle.

--- generators/android/android-generator.cmake
+++ generators/android/android-generator.cmake
@@ -34,9 +34,9 @@

   foreach (inc ${${target}_sources})
     get_filename_component(extension ${inc} EXT)
-      message("${inc}  ---  ${extension}")
+#      message("${inc}  ---  ${extension}")
     if ("${extension}" STREQUAL ".c" OR "${extension}" STREQUAL ".cpp")
-      set(target_sources "$target_sources} ${inc}")
+      set(target_sources "${target_sources} ${inc}")
     endif ()
   endforeach ()


Remove remote_service_admin_dfi from deployment for now


Fix Win32 build

Fix Win32 build

[ ] May break build
[ ] May break existing applications (see CHANGES.txt)
[x] Bugfix
[ ] New Feature
[ ] Cleanup
[ ] Optimization
[ ] Documentation

--- configure.cmake
+++ configure.cmake
@@ -26,7 +26,7 @@
   if(OSG_LIBRARY MATCHES "OSG_LIBRARY-NOTFOUND")
     set(OSG_FOUND 0)
   endif()
-  if(${OPENSCENEGRAPH_VERSION} VERSION_LESS "2.9.8")
+  if("${OPENSCENEGRAPH_VERSION}" VERSION_LESS "2.9.8")
     set(OSG_FOUND 0)
   endif()
 endif()


Check for clock_gettime in librt

Check for clock_gettime in librt

--- configure.cmake
+++ configure.cmake
@@ -279,6 +279,9 @@
   MY_SEARCH_LIBS(setsockopt socket LIBSOCKET)
   MY_SEARCH_LIBS(dlopen dl LIBDL)
   MY_SEARCH_LIBS(sched_yield rt LIBRT)
+  IF(NOT LIBRT)
+    MY_SEARCH_LIBS(clock_gettime rt LIBRT)
+  ENDIF()
   FIND_PACKAGE(Threads)

   SET(CMAKE_REQUIRED_LIBRARIES