Full Code of bilke/cmake-modules for AI

master 5b988b5beb64 cached
35 files
293.7 KB
80.0k tokens
1 symbols
1 requests
Download .txt
Showing preview only (306K chars total). Download the full file or copy to clipboard to get everything.
Repository: bilke/cmake-modules
Branch: master
Commit: 5b988b5beb64
Files: 35
Total size: 293.7 KB

Directory structure:
gitextract_lh4i7t6e/

├── CleanDirectoryList.cmake
├── CodeCoverage.cmake
├── CppcheckTargets.cmake
├── EnableProfiling.cmake
├── FindCVODE.cmake
├── FindFFTW.cmake
├── FindGDB.cmake
├── FindGSL.cmake
├── FindGitHub.cmake
├── FindITAPS.cmake
├── FindLAPACKLibs.cmake
├── FindLIS.cmake
├── FindMKL.cmake
├── FindMsysGit.cmake
├── FindNetCDF.cmake
├── FindOpenSG.cmake
├── FindOpenSGSupportlibs.cmake
├── FindShapelib.cmake
├── FindVRPN.cmake
├── Findcppcheck.cmake
├── Findcppcheck.cpp
├── Findquatlib.cmake
├── GetCPUDetails.cmake
├── GetGitRevisionDescription.cmake
├── GetGitRevisionDescription.cmake.in
├── LICENSE_1_0.txt
├── ListAllCMakeVariableValues.cmake
├── OptionRequires.cmake
├── PrintVariables.cmake
├── ProcessorCount.cmake
├── README.md
├── ResetConfigurations.cmake
├── SetDefaultBuildType.cmake
├── cotire-license
└── cotire.cmake

================================================
FILE CONTENTS
================================================

================================================
FILE: CleanDirectoryList.cmake
================================================
# - Removes duplicate entries and non-directories from a provided list
#
#  clean_directory_list(<listvar> [<additional list items>...])
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

if(__clean_directory_list)
    return()
endif()
set(__clean_directory_list YES)

function(clean_directory_list _var)
    # combine variable's current value with additional list items
    set(_in ${${_var}} ${ARGN})

    if(_in)
        # Initial list cleaning
        list(REMOVE_DUPLICATES _in)

        # Grab the absolute path of each actual directory
        set(_out)
        foreach(_dir ${_in})
            if(IS_DIRECTORY "${_dir}")
                get_filename_component(_dir "${_dir}" ABSOLUTE)
                file(TO_CMAKE_PATH "${_dir}" _dir)
                list(APPEND _out "${_dir}")
            endif()
        endforeach()

        if(_out)
            # Clean up the output list now
            list(REMOVE_DUPLICATES _out)
        endif()

        # return _out
        set(${_var} "${_out}" PARENT_SCOPE)
    endif()
endfunction()


================================================
FILE: CodeCoverage.cmake
================================================
# Copyright (c) 2012 - 2017, Lars Bilke
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
#    list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
#    this list of conditions and the following disclaimer in the documentation
#    and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
#    may be used to endorse or promote products derived from this software without
#    specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# CHANGES:
#
# 2012-01-31, Lars Bilke
# - Enable Code Coverage
#
# 2013-09-17, Joakim Söderberg
# - Added support for Clang.
# - Some additional usage instructions.
#
# 2016-02-03, Lars Bilke
# - Refactored functions to use named parameters
#
# 2017-06-02, Lars Bilke
# - Merged with modified version from github.com/ufz/ogs
#
# 2019-05-06, Anatolii Kurotych
# - Remove unnecessary --coverage flag
#
# 2019-12-13, FeRD (Frank Dana)
# - Deprecate COVERAGE_LCOVR_EXCLUDES and COVERAGE_GCOVR_EXCLUDES lists in favor
#   of tool-agnostic COVERAGE_EXCLUDES variable, or EXCLUDE setup arguments.
# - CMake 3.4+: All excludes can be specified relative to BASE_DIRECTORY
# - All setup functions: accept BASE_DIRECTORY, EXCLUDE list
# - Set lcov basedir with -b argument
# - Add automatic --demangle-cpp in lcovr, if 'c++filt' is available (can be
#   overridden with NO_DEMANGLE option in setup_target_for_coverage_lcovr().)
# - Delete output dir, .info file on 'make clean'
# - Remove Python detection, since version mismatches will break gcovr
# - Minor cleanup (lowercase function names, update examples...)
#
# 2019-12-19, FeRD (Frank Dana)
# - Rename Lcov outputs, make filtered file canonical, fix cleanup for targets
#
# 2020-01-19, Bob Apthorpe
# - Added gfortran support
#
# 2020-02-17, FeRD (Frank Dana)
# - Make all add_custom_target()s VERBATIM to auto-escape wildcard characters
#   in EXCLUDEs, and remove manual escaping from gcovr targets
#
# 2021-01-19, Robin Mueller
# - Add CODE_COVERAGE_VERBOSE option which will allow to print out commands which are run
# - Added the option for users to set the GCOVR_ADDITIONAL_ARGS variable to supply additional
#   flags to the gcovr command
#
# 2020-05-04, Mihchael Davis
#     - Add -fprofile-abs-path to make gcno files contain absolute paths
#     - Fix BASE_DIRECTORY not working when defined
#     - Change BYPRODUCT from folder to index.html to stop ninja from complaining about double defines
#
# 2021-05-10, Martin Stump
#     - Check if the generator is multi-config before warning about non-Debug builds
#
# 2022-02-22, Marko Wehle
#     - Change gcovr output from -o <filename> for --xml <filename> and --html <filename> output respectively.
#       This will allow for Multiple Output Formats at the same time by making use of GCOVR_ADDITIONAL_ARGS, e.g. GCOVR_ADDITIONAL_ARGS "--txt".
#
# 2022-09-28, Sebastian Mueller
#     - fix append_coverage_compiler_flags_to_target to correctly add flags
#     - replace "-fprofile-arcs -ftest-coverage" with "--coverage" (equivalent)
#
# 2026-01-20, Michał Sawicz
#     - add `-fprofile-update=atomic` flag, if supported, for concurrent test runs
#
# USAGE:
#
# 1. Copy this file into your cmake modules path.
#
# 2. Add the following line to your CMakeLists.txt (best inside an if-condition
#    using a CMake option() to enable it just optionally):
#      include(CodeCoverage)
#
# 3. Append necessary compiler flags for all supported source files:
#      append_coverage_compiler_flags()
#    Or for specific target:
#      append_coverage_compiler_flags_to_target(YOUR_TARGET_NAME)
#
# 3.a (OPTIONAL) Set appropriate optimization flags, e.g. -O0, -O1 or -Og
#
# 4. If you need to exclude additional directories from the report, specify them
#    using full paths in the COVERAGE_EXCLUDES variable before calling
#    setup_target_for_coverage_*().
#    Example:
#      set(COVERAGE_EXCLUDES
#          '${PROJECT_SOURCE_DIR}/src/dir1/*'
#          '/path/to/my/src/dir2/*')
#    Or, use the EXCLUDE argument to setup_target_for_coverage_*().
#    Example:
#      setup_target_for_coverage_lcov(
#          NAME coverage
#          EXECUTABLE testrunner
#          EXCLUDE "${PROJECT_SOURCE_DIR}/src/dir1/*" "/path/to/my/src/dir2/*")
#
# 4.a NOTE: With CMake 3.4+, COVERAGE_EXCLUDES or EXCLUDE can also be set
#     relative to the BASE_DIRECTORY (default: PROJECT_SOURCE_DIR)
#     Example:
#       set(COVERAGE_EXCLUDES "dir1/*")
#       setup_target_for_coverage_gcovr_html(
#           NAME coverage
#           EXECUTABLE testrunner
#           BASE_DIRECTORY "${PROJECT_SOURCE_DIR}/src"
#           EXCLUDE "dir2/*")
#
# 5. Use the functions described below to create a custom make target which
#    runs your test executable and produces a code coverage report.
#
# 6. Build a Debug build:
#      cmake -DCMAKE_BUILD_TYPE=Debug ..
#      make
#      make my_coverage_target
#

include(CMakeParseArguments)

option(CODE_COVERAGE_VERBOSE "Verbose information" FALSE)

# Check prereqs
find_program( GCOV_PATH NAMES gcov )
find_program( LCOV_PATH NAMES lcov lcov.bat lcov.exe lcov.perl )
find_program( FASTCOV_PATH NAMES fastcov fastcov.py )
find_program( GENHTML_PATH NAMES genhtml genhtml.perl genhtml.bat )
find_program( GCOVR_PATH NAMES gcovr )
find_program( CPPFILT_PATH NAMES c++filt )

if(NOT GCOV_PATH)
    message(FATAL_ERROR "gcov not found! Aborting...")
endif() # NOT GCOV_PATH

if(LCOV_PATH)
    set(lcov_message "Found Lcov: ${LCOV_PATH}")
    execute_process(COMMAND ${LCOV_PATH} "--version" OUTPUT_VARIABLE LCOV_VERSION_OUTPUT)
    if("${LCOV_VERSION_OUTPUT}" MATCHES "lcov: LCOV version ([0-9]+\\.[0-9]+(\\.[0-9]+)?)(-[0-9])?\n")
        set(LCOV_VERSION "${CMAKE_MATCH_1}")
        string(APPEND lcov_message " (found version ${LCOV_VERSION})")
    endif()
    message(STATUS "${lcov_message}")
endif()

# Check supported compiler (Clang, GNU and Flang)
get_property(LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
list(REMOVE_ITEM LANGUAGES NONE)
foreach(LANG ${LANGUAGES})
  if("${CMAKE_${LANG}_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
    if("${CMAKE_${LANG}_COMPILER_VERSION}" VERSION_LESS 3)
      message(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...")
    endif()
  elseif(NOT "${CMAKE_${LANG}_COMPILER_ID}" MATCHES "GNU"
         AND NOT "${CMAKE_${LANG}_COMPILER_ID}" MATCHES "(LLVM)?[Ff]lang")
    message(FATAL_ERROR "Compiler is not GNU or Flang! Aborting...")
  endif()
endforeach()

set(COVERAGE_COMPILER_FLAGS "-g --coverage"
    CACHE INTERNAL "")

# This is necessary because older versions of ccache don't yet have these:
# https://github.com/ccache/ccache/commit/2737d79e282de72d1b29128f437173e4892ced5e
# https://github.com/ccache/ccache/pull/1408
function(_coverage_atomic_update_flag out_var lang)
    set(_atomic_update_flag "-fprofile-update=atomic")
    set(_coverage_uses_ccache OFF)
    foreach(_launcher IN LISTS CMAKE_${lang}_COMPILER_LAUNCHER)
        if(_launcher MATCHES "ccache(\\.exe)?$")
            # Check that ccache version is less than 4.10.
            execute_process(COMMAND ${_launcher} --version OUTPUT_VARIABLE CACHE_VERSION_OUTPUT)
            if("${CACHE_VERSION_OUTPUT}" MATCHES "ccache version ([0-9]+\\.[0-9]+\\.[0-9]+)")
                if("${CMAKE_MATCH_1}" VERSION_LESS "4.10.0")
                    set(_coverage_uses_ccache ON)
                    break()
                endif()
            endif()
        endif()
    endforeach()
    if(_coverage_uses_ccache)
        set(_atomic_update_flag "--ccache-skip -fprofile-update=atomic")
    endif()
    set(${out_var} "${_atomic_update_flag}" PARENT_SCOPE)
endfunction()

set(COVERAGE_CXX_COMPILER_FLAGS ${COVERAGE_COMPILER_FLAGS})
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
    include(CheckCXXCompilerFlag)
    check_cxx_compiler_flag(-fprofile-abs-path HAVE_cxx_fprofile_abs_path)
    if(HAVE_cxx_fprofile_abs_path)
        set(COVERAGE_CXX_COMPILER_FLAGS "${COVERAGE_CXX_COMPILER_FLAGS} -fprofile-abs-path")
    endif()
    check_cxx_compiler_flag(-fprofile-update=atomic HAVE_cxx_fprofile_update_atomic)
    if(HAVE_cxx_fprofile_update_atomic)
        _coverage_atomic_update_flag(COVERAGE_ATOMIC_UPDATE_FLAG CXX)
        set(COVERAGE_CXX_COMPILER_FLAGS "${COVERAGE_CXX_COMPILER_FLAGS} ${COVERAGE_ATOMIC_UPDATE_FLAG}")
    endif()
endif()

set(COVERAGE_C_COMPILER_FLAGS ${COVERAGE_COMPILER_FLAGS})
if(CMAKE_C_COMPILER_ID MATCHES "(GNU|Clang)")
    include(CheckCCompilerFlag)
    check_c_compiler_flag(-fprofile-abs-path HAVE_c_fprofile_abs_path)
    if(HAVE_c_fprofile_abs_path)
        set(COVERAGE_C_COMPILER_FLAGS "${COVERAGE_C_COMPILER_FLAGS} -fprofile-abs-path")
    endif()
    check_c_compiler_flag(-fprofile-update=atomic HAVE_c_fprofile_update_atomic)
    if(HAVE_c_fprofile_update_atomic)
        _coverage_atomic_update_flag(COVERAGE_ATOMIC_UPDATE_FLAG C)
        set(COVERAGE_C_COMPILER_FLAGS "${COVERAGE_C_COMPILER_FLAGS} ${COVERAGE_ATOMIC_UPDATE_FLAG}")
    endif()
endif()

set(COVERAGE_Fortran_COMPILER_FLAGS ${COVERAGE_COMPILER_FLAGS})
if(CMAKE_Fortran_COMPILER_ID MATCHES "(GNU|Clang)")
    include(CheckFortranCompilerFlag)
    check_fortran_compiler_flag(-fprofile-abs-path HAVE_fortran_fprofile_abs_path)
    if(HAVE_fortran_fprofile_abs_path)
        set(COVERAGE_Fortran_COMPILER_FLAGS "${COVERAGE_Fortran_COMPILER_FLAGS} -fprofile-abs-path")
    endif()
    check_fortran_compiler_flag(-fprofile-update=atomic HAVE_fortran_fprofile_update_atomic)
    if(HAVE_fortran_fprofile_update_atomic)
        _coverage_atomic_update_flag(COVERAGE_ATOMIC_UPDATE_FLAG Fortran)
        set(COVERAGE_Fortran_COMPILER_FLAGS "${COVERAGE_Fortran_COMPILER_FLAGS} ${COVERAGE_ATOMIC_UPDATE_FLAG}")
    endif()
endif()

set(CMAKE_Fortran_FLAGS_COVERAGE
    ${COVERAGE_Fortran_COMPILER_FLAGS}
    CACHE STRING "Flags used by the Fortran compiler during coverage builds."
    FORCE )
set(CMAKE_CXX_FLAGS_COVERAGE
    ${COVERAGE_CXX_COMPILER_FLAGS}
    CACHE STRING "Flags used by the C++ compiler during coverage builds."
    FORCE )
set(CMAKE_C_FLAGS_COVERAGE
    ${COVERAGE_C_COMPILER_FLAGS}
    CACHE STRING "Flags used by the C compiler during coverage builds."
    FORCE )
set(CMAKE_EXE_LINKER_FLAGS_COVERAGE
    ""
    CACHE STRING "Flags used for linking binaries during coverage builds."
    FORCE )
set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
    ""
    CACHE STRING "Flags used by the shared libraries linker during coverage builds."
    FORCE )
mark_as_advanced(
    CMAKE_Fortran_FLAGS_COVERAGE
    CMAKE_CXX_FLAGS_COVERAGE
    CMAKE_C_FLAGS_COVERAGE
    CMAKE_EXE_LINKER_FLAGS_COVERAGE
    CMAKE_SHARED_LINKER_FLAGS_COVERAGE )

get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR GENERATOR_IS_MULTI_CONFIG))
    message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading")
endif() # NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR GENERATOR_IS_MULTI_CONFIG)

# Defines a target for running and collection code coverage information
# Builds dependencies, runs the given executable and outputs reports.
# NOTE! The executable should always have a ZERO as exit code otherwise
# the coverage generation will not complete.
#
# setup_target_for_coverage_lcov(
#     NAME testrunner_coverage                    # New target name
#     EXECUTABLE testrunner -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
#     DEPENDENCIES testrunner                     # Dependencies to build first
#     BASE_DIRECTORY "../"                        # Base directory for report
#                                                 #  (defaults to PROJECT_SOURCE_DIR)
#     DATA_DIRECTORY "./"                         # Data directory
#                                                 #  (defaults to PROJECT_BINARY_DIR)
#     EXCLUDE "src/dir1/*" "src/dir2/*"           # Patterns to exclude (can be relative
#                                                 #  to BASE_DIRECTORY, with CMake 3.4+)
#     NO_DEMANGLE                                 # Don't demangle C++ symbols
#                                                 #  even if c++filt is found
# )
function(setup_target_for_coverage_lcov)

    set(options NO_DEMANGLE SONARQUBE)
    set(oneValueArgs BASE_DIRECTORY DATA_DIRECTORY NAME)
    set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES LCOV_ARGS GENHTML_ARGS)
    cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

    if(NOT LCOV_PATH)
        message(FATAL_ERROR "lcov not found! Aborting...")
    endif() # NOT LCOV_PATH

    if(NOT GENHTML_PATH)
        message(FATAL_ERROR "genhtml not found! Aborting...")
    endif() # NOT GENHTML_PATH

    # Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR
    if(DEFINED Coverage_BASE_DIRECTORY)
        get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE)
    else()
        set(BASEDIR ${PROJECT_SOURCE_DIR})
    endif()

    # Collect excludes (CMake 3.4+: Also compute absolute paths)
    set(LCOV_EXCLUDES "")
    foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} ${COVERAGE_LCOV_EXCLUDES})
        if(CMAKE_VERSION VERSION_GREATER 3.4)
            get_filename_component(EXCLUDE ${EXCLUDE} ABSOLUTE BASE_DIR ${BASEDIR})
        endif()
        list(APPEND LCOV_EXCLUDES "${EXCLUDE}")
    endforeach()
    list(REMOVE_DUPLICATES LCOV_EXCLUDES)

    # Conditional arguments
    if(CPPFILT_PATH AND NOT ${Coverage_NO_DEMANGLE})
        set(GENHTML_EXTRA_ARGS "--demangle-cpp")
    endif()

    if(DEFINED Coverage_DATA_DIRECTORY)
        set(LCOV_DATA_DIRECTORY ${Coverage_DATA_DIRECTORY})
    else()
        set(LCOV_DATA_DIRECTORY ${PROJECT_BINARY_DIR})
    endif()

    # Setting up commands which will be run to generate coverage data.
    # Cleanup lcov
    set(LCOV_CLEAN_CMD
        ${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} --directory ${LCOV_DATA_DIRECTORY}
        -b ${BASEDIR} --zerocounters
    )
    # Create baseline to make sure untouched files show up in the report
    set(LCOV_BASELINE_CMD
        ${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} -c -i -d ${LCOV_DATA_DIRECTORY} -b
        ${BASEDIR} -o ${Coverage_NAME}.base
    )
    # Run tests
    set(LCOV_EXEC_TESTS_CMD
        ${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS}
    )
    # Capturing lcov counters and generating report
    set(LCOV_CAPTURE_CMD
        ${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} --directory ${LCOV_DATA_DIRECTORY} -b
        ${BASEDIR} --capture --output-file ${Coverage_NAME}.capture
    )
    # add baseline counters
    set(LCOV_BASELINE_COUNT_CMD
        ${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} -a ${Coverage_NAME}.base
        -a ${Coverage_NAME}.capture --output-file ${Coverage_NAME}.total
    )
    # filter collected data to final coverage report
    set(LCOV_FILTER_CMD
        ${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} --remove
        ${Coverage_NAME}.total ${LCOV_EXCLUDES} --output-file ${Coverage_NAME}.info
    )
    # Generate HTML output
    set(LCOV_GEN_HTML_CMD
        ${GENHTML_PATH} ${GENHTML_EXTRA_ARGS} ${Coverage_GENHTML_ARGS} -o
        ${Coverage_NAME} ${Coverage_NAME}.info
    )
    if(${Coverage_SONARQUBE})
        # Generate SonarQube output
        set(GCOVR_XML_CMD
            ${GCOVR_PATH} --sonarqube ${Coverage_NAME}_sonarqube.xml -r ${BASEDIR} ${GCOVR_ADDITIONAL_ARGS}
            ${GCOVR_EXCLUDE_ARGS} --object-directory=${PROJECT_BINARY_DIR}
        )
        set(GCOVR_XML_CMD_COMMAND
            COMMAND ${GCOVR_XML_CMD}
        )
        set(GCOVR_XML_CMD_BYPRODUCTS ${Coverage_NAME}_sonarqube.xml)
        set(GCOVR_XML_CMD_COMMENT COMMENT "SonarQube code coverage info report saved in ${Coverage_NAME}_sonarqube.xml.")
    endif()


    if(CODE_COVERAGE_VERBOSE)
        message(STATUS "Executed command report")
        message(STATUS "Command to clean up lcov: ")
        string(REPLACE ";" " " LCOV_CLEAN_CMD_SPACED "${LCOV_CLEAN_CMD}")
        message(STATUS "${LCOV_CLEAN_CMD_SPACED}")

        message(STATUS "Command to create baseline: ")
        string(REPLACE ";" " " LCOV_BASELINE_CMD_SPACED "${LCOV_BASELINE_CMD}")
        message(STATUS "${LCOV_BASELINE_CMD_SPACED}")

        message(STATUS "Command to run the tests: ")
        string(REPLACE ";" " " LCOV_EXEC_TESTS_CMD_SPACED "${LCOV_EXEC_TESTS_CMD}")
        message(STATUS "${LCOV_EXEC_TESTS_CMD_SPACED}")

        message(STATUS "Command to capture counters and generate report: ")
        string(REPLACE ";" " " LCOV_CAPTURE_CMD_SPACED "${LCOV_CAPTURE_CMD}")
        message(STATUS "${LCOV_CAPTURE_CMD_SPACED}")

        message(STATUS "Command to add baseline counters: ")
        string(REPLACE ";" " " LCOV_BASELINE_COUNT_CMD_SPACED "${LCOV_BASELINE_COUNT_CMD}")
        message(STATUS "${LCOV_BASELINE_COUNT_CMD_SPACED}")

        message(STATUS "Command to filter collected data: ")
        string(REPLACE ";" " " LCOV_FILTER_CMD_SPACED "${LCOV_FILTER_CMD}")
        message(STATUS "${LCOV_FILTER_CMD_SPACED}")

        message(STATUS "Command to generate lcov HTML output: ")
        string(REPLACE ";" " " LCOV_GEN_HTML_CMD_SPACED "${LCOV_GEN_HTML_CMD}")
        message(STATUS "${LCOV_GEN_HTML_CMD_SPACED}")

        if(${Coverage_SONARQUBE})
            message(STATUS "Command to generate SonarQube XML output: ")
            string(REPLACE ";" " " GCOVR_XML_CMD_SPACED "${GCOVR_XML_CMD}")
            message(STATUS "${GCOVR_XML_CMD_SPACED}")
        endif()
    endif()

    # Setup target
    add_custom_target(${Coverage_NAME}
        COMMAND ${LCOV_CLEAN_CMD}
        COMMAND ${LCOV_BASELINE_CMD}
        COMMAND ${LCOV_EXEC_TESTS_CMD}
        COMMAND ${LCOV_CAPTURE_CMD}
        COMMAND ${LCOV_BASELINE_COUNT_CMD}
        COMMAND ${LCOV_FILTER_CMD}
        COMMAND ${LCOV_GEN_HTML_CMD}
        ${GCOVR_XML_CMD_COMMAND}

        # Set output files as GENERATED (will be removed on 'make clean')
        BYPRODUCTS
            ${Coverage_NAME}.base
            ${Coverage_NAME}.capture
            ${Coverage_NAME}.total
            ${Coverage_NAME}.info
            ${GCOVR_XML_CMD_BYPRODUCTS}
            ${Coverage_NAME}/index.html
        WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
        DEPENDS ${Coverage_DEPENDENCIES}
        VERBATIM # Protect arguments to commands
        COMMENT "Resetting code coverage counters to zero. Processing code coverage counters and generating report."
    )

    # Show where to find the lcov info report
    add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
        COMMAND true
        COMMENT "Lcov code coverage info report saved in ${Coverage_NAME}.info."
        ${GCOVR_XML_CMD_COMMENT}
    )

    # Show info where to find the report
    add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
        COMMAND true
        COMMENT "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report."
    )

endfunction() # setup_target_for_coverage_lcov

# Defines a target for running and collection code coverage information
# Builds dependencies, runs the given executable and outputs reports.
# NOTE! The executable should always have a ZERO as exit code otherwise
# the coverage generation will not complete.
#
# setup_target_for_coverage_gcovr_xml(
#     NAME ctest_coverage                    # New target name
#     EXECUTABLE ctest -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
#     DEPENDENCIES executable_target         # Dependencies to build first
#     BASE_DIRECTORY "../"                   # Base directory for report
#                                            #  (defaults to PROJECT_SOURCE_DIR)
#     EXCLUDE "src/dir1/*" "src/dir2/*"      # Patterns to exclude (can be relative
#                                            #  to BASE_DIRECTORY, with CMake 3.4+)
# )
# The user can set the variable GCOVR_ADDITIONAL_ARGS to supply additional flags to the
# GCVOR command.
function(setup_target_for_coverage_gcovr_xml)

    set(options NONE)
    set(oneValueArgs BASE_DIRECTORY NAME)
    set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES)
    cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

    if(NOT GCOVR_PATH)
        message(FATAL_ERROR "gcovr not found! Aborting...")
    endif() # NOT GCOVR_PATH

    # Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR
    if(DEFINED Coverage_BASE_DIRECTORY)
        get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE)
    else()
        set(BASEDIR ${PROJECT_SOURCE_DIR})
    endif()

    # Collect excludes (CMake 3.4+: Also compute absolute paths)
    set(GCOVR_EXCLUDES "")
    foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} ${COVERAGE_GCOVR_EXCLUDES})
        if(CMAKE_VERSION VERSION_GREATER 3.4)
            get_filename_component(EXCLUDE ${EXCLUDE} ABSOLUTE BASE_DIR ${BASEDIR})
        endif()
        list(APPEND GCOVR_EXCLUDES "${EXCLUDE}")
    endforeach()
    list(REMOVE_DUPLICATES GCOVR_EXCLUDES)

    # Combine excludes to several -e arguments
    set(GCOVR_EXCLUDE_ARGS "")
    foreach(EXCLUDE ${GCOVR_EXCLUDES})
        list(APPEND GCOVR_EXCLUDE_ARGS "-e")
        list(APPEND GCOVR_EXCLUDE_ARGS "${EXCLUDE}")
    endforeach()

    # Set up commands which will be run to generate coverage data
    # Run tests
    set(GCOVR_XML_EXEC_TESTS_CMD
        ${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS}
    )
    # Running gcovr
    set(GCOVR_XML_CMD
        ${GCOVR_PATH} --xml ${Coverage_NAME}.xml -r ${BASEDIR} ${GCOVR_ADDITIONAL_ARGS}
        ${GCOVR_EXCLUDE_ARGS} --object-directory=${PROJECT_BINARY_DIR}
    )

    if(CODE_COVERAGE_VERBOSE)
        message(STATUS "Executed command report")

        message(STATUS "Command to run tests: ")
        string(REPLACE ";" " " GCOVR_XML_EXEC_TESTS_CMD_SPACED "${GCOVR_XML_EXEC_TESTS_CMD}")
        message(STATUS "${GCOVR_XML_EXEC_TESTS_CMD_SPACED}")

        message(STATUS "Command to generate gcovr XML coverage data: ")
        string(REPLACE ";" " " GCOVR_XML_CMD_SPACED "${GCOVR_XML_CMD}")
        message(STATUS "${GCOVR_XML_CMD_SPACED}")
    endif()

    add_custom_target(${Coverage_NAME}
        COMMAND ${GCOVR_XML_EXEC_TESTS_CMD}
        COMMAND ${GCOVR_XML_CMD}

        BYPRODUCTS ${Coverage_NAME}.xml
        WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
        DEPENDS ${Coverage_DEPENDENCIES}
        VERBATIM # Protect arguments to commands
        COMMENT "Running gcovr to produce Cobertura code coverage report."
    )

    # Show info where to find the report
    add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
        COMMAND true
        COMMENT "Cobertura code coverage report saved in ${Coverage_NAME}.xml."
    )
endfunction() # setup_target_for_coverage_gcovr_xml

# Defines a target for running and collection code coverage information
# Builds dependencies, runs the given executable and outputs reports.
# NOTE! The executable should always have a ZERO as exit code otherwise
# the coverage generation will not complete.
#
# setup_target_for_coverage_gcovr_html(
#     NAME ctest_coverage                    # New target name
#     EXECUTABLE ctest -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
#     DEPENDENCIES executable_target         # Dependencies to build first
#     BASE_DIRECTORY "../"                   # Base directory for report
#                                            #  (defaults to PROJECT_SOURCE_DIR)
#     EXCLUDE "src/dir1/*" "src/dir2/*"      # Patterns to exclude (can be relative
#                                            #  to BASE_DIRECTORY, with CMake 3.4+)
# )
# The user can set the variable GCOVR_ADDITIONAL_ARGS to supply additional flags to the
# GCVOR command.
function(setup_target_for_coverage_gcovr_html)

    set(options NONE)
    set(oneValueArgs BASE_DIRECTORY NAME)
    set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES)
    cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

    if(NOT GCOVR_PATH)
        message(FATAL_ERROR "gcovr not found! Aborting...")
    endif() # NOT GCOVR_PATH

    # Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR
    if(DEFINED Coverage_BASE_DIRECTORY)
        get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE)
    else()
        set(BASEDIR ${PROJECT_SOURCE_DIR})
    endif()

    # Collect excludes (CMake 3.4+: Also compute absolute paths)
    set(GCOVR_EXCLUDES "")
    foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} ${COVERAGE_GCOVR_EXCLUDES})
        if(CMAKE_VERSION VERSION_GREATER 3.4)
            get_filename_component(EXCLUDE ${EXCLUDE} ABSOLUTE BASE_DIR ${BASEDIR})
        endif()
        list(APPEND GCOVR_EXCLUDES "${EXCLUDE}")
    endforeach()
    list(REMOVE_DUPLICATES GCOVR_EXCLUDES)

    # Combine excludes to several -e arguments
    set(GCOVR_EXCLUDE_ARGS "")
    foreach(EXCLUDE ${GCOVR_EXCLUDES})
        list(APPEND GCOVR_EXCLUDE_ARGS "-e")
        list(APPEND GCOVR_EXCLUDE_ARGS "${EXCLUDE}")
    endforeach()

    # Set up commands which will be run to generate coverage data
    # Run tests
    set(GCOVR_HTML_EXEC_TESTS_CMD
        ${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS}
    )
    # Create folder
    set(GCOVR_HTML_FOLDER_CMD
        ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/${Coverage_NAME}
    )
    # Running gcovr
    set(GCOVR_HTML_CMD
        ${GCOVR_PATH} --html ${Coverage_NAME}/index.html --html-details -r ${BASEDIR} ${GCOVR_ADDITIONAL_ARGS}
        ${GCOVR_EXCLUDE_ARGS} --object-directory=${PROJECT_BINARY_DIR}
    )

    if(CODE_COVERAGE_VERBOSE)
        message(STATUS "Executed command report")

        message(STATUS "Command to run tests: ")
        string(REPLACE ";" " " GCOVR_HTML_EXEC_TESTS_CMD_SPACED "${GCOVR_HTML_EXEC_TESTS_CMD}")
        message(STATUS "${GCOVR_HTML_EXEC_TESTS_CMD_SPACED}")

        message(STATUS "Command to create a folder: ")
        string(REPLACE ";" " " GCOVR_HTML_FOLDER_CMD_SPACED "${GCOVR_HTML_FOLDER_CMD}")
        message(STATUS "${GCOVR_HTML_FOLDER_CMD_SPACED}")

        message(STATUS "Command to generate gcovr HTML coverage data: ")
        string(REPLACE ";" " " GCOVR_HTML_CMD_SPACED "${GCOVR_HTML_CMD}")
        message(STATUS "${GCOVR_HTML_CMD_SPACED}")
    endif()

    add_custom_target(${Coverage_NAME}
        COMMAND ${GCOVR_HTML_EXEC_TESTS_CMD}
        COMMAND ${GCOVR_HTML_FOLDER_CMD}
        COMMAND ${GCOVR_HTML_CMD}

        BYPRODUCTS ${PROJECT_BINARY_DIR}/${Coverage_NAME}/index.html  # report directory
        WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
        DEPENDS ${Coverage_DEPENDENCIES}
        VERBATIM # Protect arguments to commands
        COMMENT "Running gcovr to produce HTML code coverage report."
    )

    # Show info where to find the report
    add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
        COMMAND true
        COMMENT "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report."
    )

endfunction() # setup_target_for_coverage_gcovr_html

# Defines a target for running and collection code coverage information
# Builds dependencies, runs the given executable and outputs reports.
# NOTE! The executable should always have a ZERO as exit code otherwise
# the coverage generation will not complete.
#
# setup_target_for_coverage_fastcov(
#     NAME testrunner_coverage                    # New target name
#     EXECUTABLE testrunner -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
#     DEPENDENCIES testrunner                     # Dependencies to build first
#     BASE_DIRECTORY "../"                        # Base directory for report
#                                                 #  (defaults to PROJECT_SOURCE_DIR)
#     EXCLUDE "src/dir1/" "src/dir2/"             # Patterns to exclude.
#     NO_DEMANGLE                                 # Don't demangle C++ symbols
#                                                 #  even if c++filt is found
#     SKIP_HTML                                   # Don't create html report
#     POST_CMD perl -i -pe s!${PROJECT_SOURCE_DIR}/!!g ctest_coverage.json  # E.g. for stripping source dir from file paths
# )
function(setup_target_for_coverage_fastcov)

    set(options NO_DEMANGLE SKIP_HTML)
    set(oneValueArgs BASE_DIRECTORY NAME)
    set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES FASTCOV_ARGS GENHTML_ARGS POST_CMD)
    cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

    if(NOT FASTCOV_PATH)
        message(FATAL_ERROR "fastcov not found! Aborting...")
    endif()

    if(NOT Coverage_SKIP_HTML AND NOT GENHTML_PATH)
        message(FATAL_ERROR "genhtml not found! Aborting...")
    endif()

    # Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR
    if(Coverage_BASE_DIRECTORY)
        get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE)
    else()
        set(BASEDIR ${PROJECT_SOURCE_DIR})
    endif()

    # Collect excludes (Patterns, not paths, for fastcov)
    set(FASTCOV_EXCLUDES "")
    foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} ${COVERAGE_FASTCOV_EXCLUDES})
        list(APPEND FASTCOV_EXCLUDES "${EXCLUDE}")
    endforeach()
    list(REMOVE_DUPLICATES FASTCOV_EXCLUDES)

    # Conditional arguments
    if(CPPFILT_PATH AND NOT ${Coverage_NO_DEMANGLE})
        set(GENHTML_EXTRA_ARGS "--demangle-cpp")
    endif()

    # Set up commands which will be run to generate coverage data
    set(FASTCOV_EXEC_TESTS_CMD ${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS})

    set(FASTCOV_CAPTURE_CMD ${FASTCOV_PATH} ${Coverage_FASTCOV_ARGS} --gcov ${GCOV_PATH}
        --search-directory ${BASEDIR}
        --process-gcno
        --output ${Coverage_NAME}.json
        --exclude ${FASTCOV_EXCLUDES}
    )

    set(FASTCOV_CONVERT_CMD ${FASTCOV_PATH}
        -C ${Coverage_NAME}.json --lcov --output ${Coverage_NAME}.info
    )

    if(Coverage_SKIP_HTML)
        set(FASTCOV_HTML_CMD ";")
    else()
        set(FASTCOV_HTML_CMD ${GENHTML_PATH} ${GENHTML_EXTRA_ARGS} ${Coverage_GENHTML_ARGS}
            -o ${Coverage_NAME} ${Coverage_NAME}.info
        )
    endif()

    set(FASTCOV_POST_CMD ";")
    if(Coverage_POST_CMD)
        set(FASTCOV_POST_CMD ${Coverage_POST_CMD})
    endif()

    if(CODE_COVERAGE_VERBOSE)
        message(STATUS "Code coverage commands for target ${Coverage_NAME} (fastcov):")

        message("   Running tests:")
        string(REPLACE ";" " " FASTCOV_EXEC_TESTS_CMD_SPACED "${FASTCOV_EXEC_TESTS_CMD}")
        message("     ${FASTCOV_EXEC_TESTS_CMD_SPACED}")

        message("   Capturing fastcov counters and generating report:")
        string(REPLACE ";" " " FASTCOV_CAPTURE_CMD_SPACED "${FASTCOV_CAPTURE_CMD}")
        message("     ${FASTCOV_CAPTURE_CMD_SPACED}")

        message("   Converting fastcov .json to lcov .info:")
        string(REPLACE ";" " " FASTCOV_CONVERT_CMD_SPACED "${FASTCOV_CONVERT_CMD}")
        message("     ${FASTCOV_CONVERT_CMD_SPACED}")

        if(NOT Coverage_SKIP_HTML)
            message("   Generating HTML report: ")
            string(REPLACE ";" " " FASTCOV_HTML_CMD_SPACED "${FASTCOV_HTML_CMD}")
            message("     ${FASTCOV_HTML_CMD_SPACED}")
        endif()
        if(Coverage_POST_CMD)
            message("   Running post command: ")
            string(REPLACE ";" " " FASTCOV_POST_CMD_SPACED "${FASTCOV_POST_CMD}")
            message("     ${FASTCOV_POST_CMD_SPACED}")
        endif()
    endif()

    # Setup target
    add_custom_target(${Coverage_NAME}

        # Cleanup fastcov
        COMMAND ${FASTCOV_PATH} ${Coverage_FASTCOV_ARGS} --gcov ${GCOV_PATH}
            --search-directory ${BASEDIR}
            --zerocounters

        COMMAND ${FASTCOV_EXEC_TESTS_CMD}
        COMMAND ${FASTCOV_CAPTURE_CMD}
        COMMAND ${FASTCOV_CONVERT_CMD}
        COMMAND ${FASTCOV_HTML_CMD}
        COMMAND ${FASTCOV_POST_CMD}

        # Set output files as GENERATED (will be removed on 'make clean')
        BYPRODUCTS
             ${Coverage_NAME}.info
             ${Coverage_NAME}.json
             ${Coverage_NAME}/index.html  # report directory

        WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
        DEPENDS ${Coverage_DEPENDENCIES}
        VERBATIM # Protect arguments to commands
        COMMENT "Resetting code coverage counters to zero. Processing code coverage counters and generating report."
    )

    set(INFO_MSG "fastcov code coverage info report saved in ${Coverage_NAME}.info and ${Coverage_NAME}.json.")
    if(NOT Coverage_SKIP_HTML)
        string(APPEND INFO_MSG " Open ${PROJECT_BINARY_DIR}/${Coverage_NAME}/index.html in your browser to view the coverage report.")
    endif()
    # Show where to find the fastcov info report
    add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E echo ${INFO_MSG}
    )

endfunction() # setup_target_for_coverage_fastcov

function(append_coverage_compiler_flags)
    foreach(LANG ${LANGUAGES})
        set(CMAKE_${LANG}_FLAGS "${CMAKE_${LANG}_FLAGS} ${CMAKE_${LANG}_FLAGS_COVERAGE}" PARENT_SCOPE)
        message(STATUS "Appending code coverage compiler flags for ${LANG}: ${CMAKE_${LANG}_FLAGS_COVERAGE}")
    endforeach()
    if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
        link_libraries(gcov)
    endif()
endfunction() # append_coverage_compiler_flags

# Setup coverage for specific library
function(append_coverage_compiler_flags_to_target name)
    foreach(LANG ${LANGUAGES})
        separate_arguments(_flag_list NATIVE_COMMAND "${CMAKE_${LANG}_FLAGS_COVERAGE}")
        target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:${LANG}>:${_flag_list}>)
    endforeach()
    if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
        target_link_libraries(${name} PRIVATE gcov)
    endif()
endfunction()


================================================
FILE: CppcheckTargets.cmake
================================================
# - Run cppcheck on c++ source files as a custom target and a test
#
#  include(CppcheckTargets)
#  add_cppcheck(<target-name> [UNUSED_FUNCTIONS] [STYLE] [POSSIBLE_ERROR] [FAIL_ON_WARNINGS]) -
#    Create a target to check a target's sources with cppcheck and the indicated options
#  add_cppcheck_sources(<target-name> [UNUSED_FUNCTIONS] [STYLE] [POSSIBLE_ERROR] [FAIL_ON_WARNINGS]) -
#    Create a target to check standalone sources with cppcheck and the indicated options
#
# Requires these CMake modules:
#  Findcppcheck
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

if(__add_cppcheck)
    return()
endif()
set(__add_cppcheck YES)

if(NOT CPPCHECK_FOUND)
    find_package(cppcheck QUIET)
endif()

if(CPPCHECK_FOUND)
    if(NOT TARGET all_cppcheck)
        add_custom_target(all_cppcheck)
        set_target_properties(all_cppcheck PROPERTIES EXCLUDE_FROM_ALL TRUE)
    endif()
endif()

function(add_cppcheck_sources _targetname)
    if(CPPCHECK_FOUND)
        set(_cppcheck_args)
        set(_input ${ARGN})
        list(FIND _input UNUSED_FUNCTIONS _unused_func)
        if("${_unused_func}" GREATER "-1")
            list(APPEND _cppcheck_args ${CPPCHECK_UNUSEDFUNC_ARG})
            list(REMOVE_AT _input ${_unused_func})
        endif()

        list(FIND _input STYLE _style)
        if("${_style}" GREATER "-1")
            list(APPEND _cppcheck_args ${CPPCHECK_STYLE_ARG})
            list(REMOVE_AT _input ${_style})
        endif()

        list(FIND _input POSSIBLE_ERROR _poss_err)
        if("${_poss_err}" GREATER "-1")
            list(APPEND _cppcheck_args ${CPPCHECK_POSSIBLEERROR_ARG})
            list(REMOVE_AT _input ${_poss_err})
        endif()

        list(FIND _input FAIL_ON_WARNINGS _fail_on_warn)
        if("${_fail_on_warn}" GREATER "-1")
            list(APPEND
                CPPCHECK_FAIL_REGULAR_EXPRESSION
                ${CPPCHECK_WARN_REGULAR_EXPRESSION})
            list(REMOVE_AT _input ${_fail_on_warn})
        endif()

        set(_files)
        foreach(_source ${_input})
            get_source_file_property(_cppcheck_loc "${_source}" LOCATION)
            if(_cppcheck_loc)
                # This file has a source file property, carry on.
                get_source_file_property(_cppcheck_lang "${_source}" LANGUAGE)
                if("${_cppcheck_lang}" MATCHES "CXX")
                    list(APPEND _files "${_cppcheck_loc}")
                endif()
            else()
                # This file doesn't have source file properties - figure it out.
                get_filename_component(_cppcheck_loc "${_source}" ABSOLUTE)
                if(EXISTS "${_cppcheck_loc}")
                    list(APPEND _files "${_cppcheck_loc}")
                else()
                    message(FATAL_ERROR
                        "Adding CPPCHECK for file target ${_targetname}: "
                        "File ${_source} does not exist or needs a corrected path location "
                        "since we think its absolute path is ${_cppcheck_loc}")
                endif()
            endif()
        endforeach()

        if("1.${CMAKE_VERSION}" VERSION_LESS "1.2.8.0")
            # Older than CMake 2.8.0
            add_test(${_targetname}_cppcheck_test
                "${CPPCHECK_EXECUTABLE}"
                ${CPPCHECK_TEMPLATE_ARG}
                ${_cppcheck_args}
                ${_files})
        else()
            # CMake 2.8.0 and newer
            add_test(NAME
                ${_targetname}_cppcheck_test
                COMMAND
                "${CPPCHECK_EXECUTABLE}"
                ${CPPCHECK_TEMPLATE_ARG}
                ${_cppcheck_args}
                ${_files})
        endif()

        set_tests_properties(${_targetname}_cppcheck_test
            PROPERTIES
            FAIL_REGULAR_EXPRESSION
            "${CPPCHECK_FAIL_REGULAR_EXPRESSION}")

        add_custom_command(TARGET
            all_cppcheck
            PRE_BUILD
            COMMAND
            ${CPPCHECK_EXECUTABLE}
            ${CPPCHECK_QUIET_ARG}
            ${CPPCHECK_TEMPLATE_ARG}
            ${_cppcheck_args}
            ${_files}
            WORKING_DIRECTORY
            "${CMAKE_CURRENT_SOURCE_DIR}"
            COMMENT
            "${_targetname}_cppcheck: Running cppcheck on target ${_targetname}..."
            VERBATIM)
    endif()
endfunction()

function(add_cppcheck _name)
    if(NOT TARGET ${_name})
        message(FATAL_ERROR
            "add_cppcheck given a target name that does not exist: '${_name}' !")
    endif()
    if(CPPCHECK_FOUND)
        set(_cppcheck_args)

        list(FIND ARGN UNUSED_FUNCTIONS _unused_func)
        if("${_unused_func}" GREATER "-1")
            list(APPEND _cppcheck_args ${CPPCHECK_UNUSEDFUNC_ARG})
        endif()

        list(FIND ARGN STYLE _style)
        if("${_style}" GREATER "-1")
            list(APPEND _cppcheck_args ${CPPCHECK_STYLE_ARG})
        endif()

        list(FIND ARGN POSSIBLE_ERROR _poss_err)
        if("${_poss_err}" GREATER "-1")
            list(APPEND _cppcheck_args ${CPPCHECK_POSSIBLEERROR_ARG})
        endif()

        list(FIND _input FAIL_ON_WARNINGS _fail_on_warn)
        if("${_fail_on_warn}" GREATER "-1")
            list(APPEND
                CPPCHECK_FAIL_REGULAR_EXPRESSION
                ${CPPCHECK_WARN_REGULAR_EXPRESSION})
            list(REMOVE_AT _input ${_unused_func})
        endif()

        get_target_property(_cppcheck_sources "${_name}" SOURCES)
        set(_files)
        foreach(_source ${_cppcheck_sources})
            get_source_file_property(_cppcheck_lang "${_source}" LANGUAGE)
            get_source_file_property(_cppcheck_loc "${_source}" LOCATION)
            if("${_cppcheck_lang}" MATCHES "CXX")
                list(APPEND _files "${_cppcheck_loc}")
            endif()
        endforeach()

        if("1.${CMAKE_VERSION}" VERSION_LESS "1.2.8.0")
            # Older than CMake 2.8.0
            add_test(${_name}_cppcheck_test
                "${CPPCHECK_EXECUTABLE}"
                ${CPPCHECK_TEMPLATE_ARG}
                ${_cppcheck_args}
                ${_files})
        else()
            # CMake 2.8.0 and newer
            add_test(NAME
                ${_name}_cppcheck_test
                COMMAND
                "${CPPCHECK_EXECUTABLE}"
                ${CPPCHECK_TEMPLATE_ARG}
                ${_cppcheck_args}
                ${_files})
        endif()

        set_tests_properties(${_name}_cppcheck_test
            PROPERTIES
            FAIL_REGULAR_EXPRESSION
            "${CPPCHECK_FAIL_REGULAR_EXPRESSION}")

        add_custom_command(TARGET
            all_cppcheck
            PRE_BUILD
            COMMAND
            ${CPPCHECK_EXECUTABLE}
            ${CPPCHECK_QUIET_ARG}
            ${CPPCHECK_TEMPLATE_ARG}
            ${_cppcheck_args}
            ${_files}
            WORKING_DIRECTORY
            "${CMAKE_CURRENT_SOURCE_DIR}"
            COMMENT
            "${_name}_cppcheck: Running cppcheck on target ${_name}..."
            VERBATIM)
    endif()

endfunction()


================================================
FILE: EnableProfiling.cmake
================================================
# - Add flags to compile with profiling support - currently only for GCC
#
#  enable_profiling(<targetname>)
#  globally_enable_profiling() - to modify CMAKE_CXX_FLAGS, etc
#    to change for all targets declared after the command, instead of per-command
#
#
# Original Author:
# 2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

if(__enable_profiling)
    return()
endif()
set(__enable_profiling YES)

macro(_enable_profiling_flags)
    set(_flags)
    if(MSVC)
        # TODO: what kind of flags are needed to profile on MSVC?
        #set(_flags /W4)
    elseif(CMAKE_COMPILER_IS_GNUCXX)
        set(_flags "-p")
    endif()
endmacro()

function(enable_profiling _target)
    _enable_profiling_flags()
    get_target_property(_origflags ${_target} COMPILE_FLAGS)
    if(_origflags)
        set_property(TARGET
            ${_target}
            PROPERTY
            COMPILE_FLAGS
            "${_flags} ${_origflags}")
    else()
        set_property(TARGET
            ${_target}
            PROPERTY
            COMPILE_FLAGS
            "${_flags}")
    endif()

endfunction()

function(globally_enable_profiling)
    _enable_profiling_flags()
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_flags}" PARENT_SCOPE)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flags}" PARENT_SCOPE)
endfunction()


================================================
FILE: FindCVODE.cmake
================================================
# Tries to find Sundials CVODE.
#
# This module will define the following variables:
#  CVODE_INCLUDE_DIRS - Location of the CVODE includes
#  CVODE_FOUND - true if CVODE was found on the system
#  CVODE_LIBRARIES - Required libraries for all requested components
#
# This module accepts the following environment or CMake vars
#  CVODE_ROOT - Install location to search for

include(FindPackageHandleStandardArgs)

if(NOT "$ENV{CVODE_ROOT}" STREQUAL "" OR NOT "${CVODE_ROOT}" STREQUAL "")
    list(APPEND CMAKE_INCLUDE_PATH "$ENV{CVODE_ROOT}" "${CVODE_ROOT}")
    list(APPEND CMAKE_LIBRARY_PATH "$ENV{CVODE_ROOT}" "${CVODE_ROOT}")
endif()

find_path(CVODE_INCLUDE_DIRS sundials/sundials_types.h
    ENV CVODE_ROOT
    PATH_SUFFIXES include
)

find_library(CVODE_LIBRARY
    NAMES sundials_cvode
    ENV CVODE_ROOT
    PATH_SUFFIXES lib Lib
)

find_library(CVODE_NVECSERIAL
    NAMES sundials_nvecserial
    ENV CVODE_ROOT
    PATH_SUFFIXES lib Lib
)

find_library(CVODE_KLU klu)

find_package_handle_standard_args(CVODE DEFAULT_MSG
    CVODE_LIBRARY
    CVODE_NVECSERIAL
    CVODE_INCLUDE_DIRS
)

if(CVODE_FOUND)
    set(CVODE_LIBRARIES ${CVODE_LIBRARY} ${CVODE_NVECSERIAL} CACHE INTERNAL "")
    if(CVODE_KLU)
        set(CVODE_LIBRARIES ${CVODE_LIBRARIES} ${CVODE_KLU} CACHE INTERNAL "")
    endif()
endif()

mark_as_advanced(CVODE_INCLUDE_DIRS CVODE_LIBRARY CVODE_NVECSERIAL)


================================================
FILE: FindFFTW.cmake
================================================
# - Find FFTW
# Find the native FFTW includes and library
#
#  FFTW_INCLUDES    - where to find fftw3.h
#  FFTW_LIBRARIES   - List of libraries when using FFTW.
#  FFTW_FOUND       - True if FFTW found.

if (FFTW_INCLUDES)
  # Already in cache, be silent
  set (FFTW_FIND_QUIETLY TRUE)
endif (FFTW_INCLUDES)

find_path (FFTW_INCLUDES fftw3.h)

find_library (FFTW_LIBRARIES NAMES fftw3)

# handle the QUIETLY and REQUIRED arguments and set FFTW_FOUND to TRUE if
# all listed variables are TRUE
include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (FFTW DEFAULT_MSG FFTW_LIBRARIES FFTW_INCLUDES)

mark_as_advanced (FFTW_LIBRARIES FFTW_INCLUDES)


================================================
FILE: FindGDB.cmake
================================================
# - Try to find GDB
#
# Once done, this will define:
#  GDB_FOUND - system has GDB
#  GDB_COMMAND - the command to run
#  GDB_VERSION - version
#  GDB_HAS_RETURN_CHILD_RESULT - if the --return-child-result flag is supported
#
# Useful configuration variables you might want to add to your cache:
#  GDB_ROOT_DIR - A directory prefix to search
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)


set(GDB_ROOT_DIR
    "${GDB_ROOT_DIR}"
    CACHE
    PATH
    "Directory to start our search in")

find_program(GDB_COMMAND
    NAMES
    gdb
    HINTS
    "${GDB_ROOT_DIR}"
    PATH_SUFFIXES
    bin
    libexec)

if(GDB_COMMAND)
    execute_process(COMMAND gdb --version
        COMMAND head -n 1
        OUTPUT_VARIABLE GDB_VERSION
        OUTPUT_STRIP_TRAILING_WHITESPACE)
    string(REGEX REPLACE "[^0-9]*([0-9]+[0-9.]*).*" "\\1" GDB_VERSION "${GDB_VERSION}")
endif()

# handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GDB DEFAULT_MSG GDB_COMMAND GDB_VERSION)

if(GDB_FOUND)
    mark_as_advanced(GDB_ROOT_DIR)
    if(GDB_VERSION VERSION_LESS 6.4)
        set(GDB_HAS_RETURN_CHILD_RESULT FALSE)
    else()
        set(GDB_HAS_RETURN_CHILD_RESULT TRUE)
    endif()
endif()

mark_as_advanced(GDB_COMMAND)


================================================
FILE: FindGSL.cmake
================================================
# - Find GSL
# Find the native GSL includes and library
#
#  GSL_INCLUDES    - where to find gsl/gsl_*.h, etc.
#  GSL_LIBRARIES   - List of libraries when using GSL.
#  GSL_FOUND       - True if GSL found.


if (GSL_INCLUDES)
  # Already in cache, be silent
  set (GSL_FIND_QUIETLY TRUE)
endif (GSL_INCLUDES)

find_path (GSL_INCLUDES gsl/gsl_math.h)

find_library (GSL_LIB NAMES gsl)

set (GSL_CBLAS_LIB "" CACHE FILEPATH "If your program fails to link
(usually because GSL is not automatically linking a CBLAS and no other
component of your project provides a CBLAS) then you may need to point
this variable to a valid CBLAS.  Usually GSL is distributed with
libgslcblas.{a,so} (next to GSL_LIB) which you may use if an optimized
CBLAS is unavailable.")

set (GSL_LIBRARIES "${GSL_LIB}" "${GSL_CBLAS_LIB}")

# handle the QUIETLY and REQUIRED arguments and set GSL_FOUND to TRUE if
# all listed variables are TRUE
include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (GSL DEFAULT_MSG GSL_LIBRARIES GSL_INCLUDES)

mark_as_advanced (GSL_LIB GSL_CBLAS_LIB GSL_INCLUDES)


================================================
FILE: FindGitHub.cmake
================================================
# - Find GitHub for Windows
#
#   GITHUB_FOUND    - Was GitHub for Windows found
#   GITHUB_BIN_DIR  - Path to the bin-directory where useful bash tools can be found
#
# Example usage:
#   find_package(GitHub)
#   find_program(BASH_TOOL_PATH bash HINTS ${GITHUB_BIN_DIR} DOC "The bash executable")

if(WIN32 AND NOT GITHUB_FOUND)

    # Check install Path
    find_path(
        GITHUB_DIR
        shell.ps1
        PATHS $ENV{LOCALAPPDATA}/GitHub $ENV{GitHub_DIR}
        NO_DEFAULT_PATH
    )

    if(GITHUB_DIR)

        execute_process (
            COMMAND cmd /c "cd ${GITHUB_DIR}/PortableGit*/bin & cd"
            OUTPUT_VARIABLE PORTABLE_GIT_WIN_DIR
        )

        if(PORTABLE_GIT_WIN_DIR)
            string(STRIP ${PORTABLE_GIT_WIN_DIR} PORTABLE_GIT_WIN_DIR)
            file(TO_CMAKE_PATH ${PORTABLE_GIT_WIN_DIR} PORTABLE_GIT_WIN_DIR)
            set(GITHUB_FOUND ON CACHE BOOL "Was GitHub for Windows found?")
            set(GITHUB_BIN_DIR ${PORTABLE_GIT_WIN_DIR} CACHE PATH "The path to the GitHub for Windows binaries." FORCE)
            message(STATUS "GitHub for Windows found.")
        endif()

    endif()
endif()


================================================
FILE: FindITAPS.cmake
================================================
# - Try to find ITAPS
#
# This will define
#
#  ITAPS_FOUND          - Requested components were found
#  ITAPS_INCLUDES       - Includes for all available components
#  ITAPS_LIBRARIES      - Libraries for all available components
#
#  ITAPS_MESH_FOUND     - System has iMesh
#  ITAPS_MESH_INCLUDES  - The iMesh include directory
#  ITAPS_MESH_LIBRARIES - Link these to use iMesh
#
#  ITAPS_GEOM_FOUND     - System has iGeom
#  ITAPS_GEOM_INCLUDES  - The iGeom include directory
#  ITAPS_GEOM_LIBRARIES - Link these to use iGeom
#
#  ITAPS_REL_FOUND      - System has iRel
#  ITAPS_REL_INCLUDES   - The iRel include directory
#  ITAPS_REL_LIBRARIES  - Link these to use iRel
#
# Setting this changes the behavior of the search
#  ITAPS_MESH_DEFS_FILE - path to iMesh-Defs.inc
#  ITAPS_GEOM_DEFS_FILE - path to iGeom-Defs.inc
#  ITAPS_REL_DEFS_FILE  - path to iRel-Defs.inc
#
# If any of these variables are in your environment, they will be used as hints
#  IMESH_DIR - directory in which iMesh resides
#  IGEOM_DIR - directory in which iGeom resides
#  IREL_DIR  - directory in which iRel resides
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#

include (FindPackageMultipass)
include (ResolveCompilerPaths)
include (CheckCSourceRuns)
include (FindPackageHandleStandardArgs)

find_program (MAKE_EXECUTABLE NAMES make gmake)

macro (ITAPS_PREPARE_COMPONENT component name)
  find_file (ITAPS_${component}_DEFS_FILE ${name}-Defs.inc
    HINTS ENV I${component}_DIR
    PATH_SUFFIXES lib64 lib)
  # If ITAPS_XXX_DEFS_FILE has changed, the library will be found again
  find_package_multipass (ITAPS_${component} itaps_${component}_config_current
    STATES DEFS_FILE
    DEPENDENTS INCLUDES LIBRARIES EXECUTABLE_RUNS)
endmacro ()

macro (ITAPS_GET_VARIABLE makefile name var)
  set (${var} "NOTFOUND" CACHE INTERNAL "Cleared" FORCE)
  execute_process (COMMAND ${MAKE_EXECUTABLE} -f ${${makefile}} show VARIABLE=${name}
    OUTPUT_VARIABLE ${var}
    RESULT_VARIABLE itaps_return)
endmacro (ITAPS_GET_VARIABLE)

macro (ITAPS_TEST_RUNS component name includes libraries program runs)
  # message (STATUS "Starting run test: ${includes} ${libraries} ${runs}")
  multipass_c_source_runs ("${includes}" "${libraries}" "${program}" ${runs})
  if (NOT ITAPS_${component}_EXECUTABLE_RUNS)
    set (ITAPS_${component}_EXECUTABLE_RUNS "${${runs}}" CACHE BOOL
      "Can the system successfully run an ${name} executable?  This variable can be manually set to \"YES\" to force CMake to accept a given configuration, but this will almost always result in a broken build." FORCE)
  endif ()
endmacro (ITAPS_TEST_RUNS)

macro (ITAPS_REQUIRED_LIBS component name includes libraries_all program libraries_required)
  # message (STATUS "trying program: ${program}")
  resolve_libraries (_all_libraries "${libraries_all}")
  list (GET _all_libraries 0 _first_library)
  itaps_test_runs (${component} ${name} "${includes}" "${_first_library};${itaps_rel_libs}" "${program}" ${name}_works_minimal)
  if (${name}_works_minimal)
    set (${libraries_required} "${_first_library}")
    message (STATUS "${name} executable works when only linking to the interface lib, this probably means you have shared libs.")
  else ()
    itaps_test_runs (${component} ${name} "${includes}" "${_all_libraries};${itaps_rel_libs}" "${itaps_mesh_program}" ${name}_works_extra)
    if (${name}_works_extra)
      set (${libraries_required} "${_all_libraries}")
      message (STATUS "${name} executable requires linking to extra libs, this probably means it's statically linked.")
    else ()
      message (STATUS "${name} could not be used, maybe the install is broken.")
    endif ()
  endif ()
endmacro ()

macro (ITAPS_HANDLE_COMPONENT component name program)
  itaps_prepare_component ("${component}" "${name}")
  if (ITAPS_${component}_DEFS_FILE AND NOT itaps_${component}_config_current)
    # A temporary makefile to probe this ITAPS components's configuration
    set (itaps_config_makefile "${PROJECT_BINARY_DIR}/Makefile.${name}")
    file (WRITE ${itaps_config_makefile}
      "## This file was autogenerated by FindITAPS.cmake
include ${ITAPS_${component}_DEFS_FILE}
show :
\t-@echo -n \${\${VARIABLE}}")
    itaps_get_variable (itaps_config_makefile I${component}_INCLUDEDIR   itaps_includedir)
    itaps_get_variable (itaps_config_makefile I${component}_LIBS         itaps_libs)
    file (REMOVE ${itaps_config_makefile})
    find_path (itaps_include_tmp ${name}.h HINTS ${itaps_includedir} NO_DEFAULT_PATH)
    set (ITAPS_${component}_INCLUDES "${itaps_include_tmp}" CACHE STRING "Include directories for ${name}")
    set (itaps_include_tmp "NOTFOUND" CACHE INTERNAL "Cleared" FORCE)
    itaps_required_libs ("${component}" "${name}" "${ITAPS_${component}_INCLUDES}" "${itaps_libs}" "${program}" itaps_${component}_required_libraries)
    set (ITAPS_${component}_LIBRARIES "${itaps_${component}_required_libraries}" CACHE STRING "Libraries for ${name}")
    mark_as_advanced (ITAPS_${component}_EXECUTABLE_RUNS ITAPS_${component}_LIBRARIES)
  endif()
  set (ITAPS_${component}_FOUND "${ITAPS_${component}_EXECUTABLE_RUNS}")
endmacro()

itaps_handle_component (MESH iMesh "
/* iMesh test program */
#include <iMesh.h>
#define CHK(err) if (err) return 1
int main(int argc,char *argv[]) {
  int err;
  iMesh_Instance m;
  iMesh_newMesh(\"\",&m,&err,0);CHK(err);
  iMesh_dtor(m,&err);CHK(err);
  return 0;
}
")
find_path (imesh_include_tmp iMeshP.h HINTS ${ITAPS_MESH_INCLUDES} NO_DEFAULT_PATH)
if (imesh_include_tmp)
  set (ITAPS_MESH_HAS_PARALLEL "YES")
else ()
  set (ITAPS_MESH_HAS_PARALLEL "NO")
endif ()
set (imesh_include_tmp "NOTFOUND" CACHE INTERNAL "Cleared" FORCE)

set (itaps_rel_libs)       # Extra libraries which should only be set when linking with iRel

itaps_handle_component (GEOM iGeom "
/* iGeom test program */
#include <iGeom.h>
#define CHK(err) if (err) return 1
int main() {
  int ierr;
  iGeom_Instance g;
  iGeom_newGeom(\"\",&g,&ierr,0);CHK(ierr);
  iGeom_dtor(g,&ierr);CHK(ierr);
  return 0;
}
")

if (ITAPS_MESH_FOUND AND ITAPS_GEOM_FOUND) # iRel only makes sense if iMesh and iGeom are found
  set (itaps_rel_libs "${ITAPS_MESH_LIBRARIES}" "${ITAPS_GEOM_LIBRARIES}")
  itaps_handle_component (REL iRel "
/* iRel test program */
#include <iRel.h>
#define CHK(err) if (err) return 1
int main() {
  int ierr;
  iRel_Instance rel;
  iRel_create(\"\",&rel,&ierr,0);CHK(ierr);
  iRel_destroy(rel,&ierr);CHK(ierr);
  return 0;
}
")
endif ()

set (ITAPS_INCLUDES)
set (ITAPS_LIBRARIES)
foreach (component REL GEOM MESH)
  if (ITAPS_${component}_INCLUDES)
    list (APPEND ITAPS_INCLUDES "${ITAPS_${component}_INCLUDES}")
  endif ()
  if (ITAPS_${component}_LIBRARIES)
    list (APPEND ITAPS_LIBRARIES "${ITAPS_${component}_LIBRARIES}")
  endif ()
  message (STATUS "ITAPS_${component}: ${ITAPS_${component}_INCLUDES} ${ITAPS_${component}_LIBRARIES}")
endforeach()
list (REMOVE_DUPLICATES ITAPS_INCLUDES)
list (REMOVE_DUPLICATES ITAPS_LIBRARIES)

set (ITAPS_FOUND_REQUIRED_COMPONENTS YES)
if (ITAPS_FIND_REQUIRED)
  foreach (component ${ITAPS_FIND_COMPONENTS})
    if (NOT ITAPS_${component}_FOUND)
      set (ITAPS_FOUND_REQUIRED_COMPONENTS NOTFOUND)
    endif()
  endforeach()
endif()

message (STATUS "ITAPS: ${ITAPS_INCLUDES}  ${ITAPS_LIBRARIES}")

find_package_handle_standard_args (ITAPS "ITAPS not found, check environment variables I{MESH,GEOM,REL}_DIR"
  ITAPS_INCLUDES ITAPS_LIBRARIES ITAPS_FOUND_REQUIRED_COMPONENTS)


================================================
FILE: FindLAPACKLibs.cmake
================================================
# - Try to find LAPACK and BLAS libraries
# Once done, this will define
#  LAPACKLIBS_LIBRARIES, all libraries to link against
#  LAPACKLIBS_FOUND, If false, do not try to use LAPACK library features.
#
# Users may wish to set:
#  LAPACKLIBS_ROOT_DIR, location to start searching for LAPACK libraries
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

set(_check)

set(LAPACKLIBS_ROOT_DIR
	"${LAPACKLIBS_ROOT_DIR}"
	CACHE
	PATH
	"Directory to search for LAPACK libraries")

if(APPLE)
	find_library(LAPACKLIBS_VECLIB_FRAMEWORK veclib)
	find_library(LAPACKLIBS_ACCELERATE_FRAMEWORK accelerate)
	mark_as_advanced(LAPACKLIBS_VECLIB_FRAMEWORK
		LAPACKLIBS_ACCELERATE_FRAMEWORK)

	set(LAPACKLIBS_LIBRARIES
		"${LAPACKLIBS_VECLIB_FRAMEWORK}"
		"${LAPACKLIBS_ACCELERATE_FRAMEWORK}")
	list(APPEND
		_check
		LAPACKLIBS_VECLIB_FRAMEWORK
		LAPACKLIBS_ACCELERATE_FRAMEWORK)
elseif(WIN32)
	# Tested to work with the files from http://www.fi.muni.cz/~xsvobod2/misc/lapack/
	# You might also see http://icl.cs.utk.edu/lapack-for-windows/clapack/index.html for
	# the libraries and headers.

	# Good luck!

	find_library(LAPACKLIBS_LAPACK_LIBRARY
		NAMES
		lapack_win32_MT
		lapack
		lapackd
		HINTS
		${LAPACKLIBS_ROOT_DIR}
		PATH_SUFFIXES
		lapack-MT-release
		lapack-MT-debug
		lib)
	find_library(LAPACKLIBS_BLAS_LIBRARY
		NAMES
		blas_win32_MT
		blas
		blasd
		HINTS
		${LAPACKLIBS_ROOT_DIR}
		PATH_SUFFIXES
		lapack-MT-release
		lapack-MT-debug
		lib)
	set(LAPACKLIBS_LIBRARIES
		"${LAPACKLIBS_LAPACK_LIBRARY}"
		"${LAPACKLIBS_BLAS_LIBRARY}")
	list(APPEND _check LAPACKLIBS_LAPACK_LIBRARY LAPACKLIBS_BLAS_LIBRARY)
elseif(UNIX)
	# All other Linux/Unix should have lapack without a fuss
	list(APPEND _check LAPACKLIBS_LAPACK_LIBRARY)
	find_library(LAPACKLIBS_LAPACK_LIBRARY lapack)
	set(LAPACKLIBS_LIBRARIES "${LAPACKLIBS_LAPACK_LIBRARY}")
endif()

# handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LAPACKLibs
	DEFAULT_MSG
	${_check})

if(LAPACKLIBS_FOUND)
	mark_as_advanced(LAPACKLIBS_ROOT_DIR
		LAPACKLIBS_LAPACK_LIBRARY
		LAPACKLIBS_BLAS_LIBRARY)
endif()


================================================
FILE: FindLIS.cmake
================================================
# - Try to find LIS
# Once done, this will define
#
#  LIS_FOUND
#  LIS_INCLUDE_DIRS
#  LIS_LIBRARIES
#
#  Environment variable LIS_ROOT_DIR can be set to give hints

find_path( LIS_INCLUDE_DIR lis.h
    PATHS ENV LIS_ROOT_DIR
    PATH_SUFFIXES include
)

find_library(LIS_LIBRARY lis
    PATHS ENV LIS_ROOT_DIR
    PATH_SUFFIXES lib
)

set(LIS_LIBRARIES ${LIS_LIBRARY})

include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIS DEFAULT_MSG LIS_LIBRARY LIS_INCLUDE_DIR)



================================================
FILE: FindMKL.cmake
================================================
# Find Intel Math Karnel Library (MKL)
#
# Options
# - MKL_DIR      MKL root directory
# - MKL_OPENMP   use OpenMP threading
#
# Results
# - MKL_INCLUDE_DIR
# - MKL_LIBRARIES
#
# Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org)
# Distributed under a Modified BSD License.
# See accompanying file LICENSE.txt or
# http://www.opengeosys.org/project/license

# Lookg for MKL root dir
if (NOT MKL_DIR)
    find_path(MKL_DIR
        include/mkl.h
        PATHS
        $ENV{MKL_DIR}
        /opt/intel/mkl/
        )
endif()
if(MKL_DIR)
    message(STATUS "MKL_DIR : ${MKL_DIR}")
endif()

# Find MKL include dir
find_path(MKL_INCLUDE_DIR NAMES mkl.h
    PATHS
        ${MKL_DIR}/include
    PATH_SUFFIXES
        mkl
)

# Set the directory path storing MKL libraries
if (NOT MKL_LIB_DIR)
    if(APPLE)
        set(MKL_LIB_DIR ${MKL_DIR}/lib)
    else()
        if (${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "x86_64")
            set(MKL_LIB_DIR ${MKL_DIR}/lib/intel64)
        else()
            set(MKL_LIB_DIR ${MKL_DIR}/lib/ia32)
        endif()
    endif()
endif()

# Find MKL libs
find_library(MKL_LIB_CORE mkl_core PATHS ${MKL_LIB_DIR})

if (${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "x86_64")
    set(MKL_INTEL_LIB_NAME mkl_intel_lp64)
else()
    set(MKL_INTEL_LIB_NAME mkl_intel)
endif()

find_library(MKL_LIB_INTEL ${MKL_INTEL_LIB_NAME} PATHS ${MKL_LIB_DIR})

if(OPENMP_FOUND)
    set(MKL_THREAD_LIB_NAME "mkl_gnu_thread")
else()
    set(MKL_THREAD_LIB_NAME "mkl_sequential")
endif()
find_library(MKL_LIB_THREAD ${MKL_THREAD_LIB_NAME} PATHS ${MKL_LIB_DIR})


set(MKL_LIBRARIES "${MKL_LIB_INTEL}" "${MKL_LIB_THREAD}" "${MKL_LIB_CORE}")

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MKL DEFAULT_MSG MKL_INCLUDE_DIR MKL_LIBRARIES)
mark_as_advanced(MKL_INCLUDE_DIR MKL_LIBRARIES)


================================================
FILE: FindMsysGit.cmake
================================================
# The module defines the following variables:
#   MSYSGIT_BIN_DIR - path to the tool binaries
#   MSYSGIT_FOUND - true if the command line client was found
# Example usage:
#   find_package(MsysGit)
#   if(MSYSGIT_FOUND)
#     message("msysGit tools found in: ${MSYSGIT_BIN_DIR}")
#   endif()

if(GIT_EXECUTABLE)
    execute_process(COMMAND ${GIT_EXECUTABLE} --version
                                    OUTPUT_VARIABLE git_version
                                    ERROR_QUIET
                                    OUTPUT_STRIP_TRAILING_WHITESPACE)
    if (git_version MATCHES "^git version [0-9]")
        string(REPLACE "git version " "" GIT_VERSION_STRING "${git_version}")
        if (git_version MATCHES "msysgit")
            set(GIT_IS_MSYSGIT TRUE)
        else()
            set(GIT_IS_MSYSGIT FALSE)
        endif()
    endif()
    unset(git_version)
endif()

if(GIT_IS_MSYSGIT)
    get_filename_component(MSYS_DIR ${GIT_EXECUTABLE} PATH)
    find_path(MSYSGIT_BIN_DIR
    NAMES date.exe grep.exe unzip.exe git.exe PATHS ${MSYS_DIR}/../bin NO_DEFAULT_PATH)
else()
    find_path(MSYSGIT_BIN_DIR
    NAMES date.exe grep.exe unzip.exe git.exe PATH_SUFFIXES Git/bin)
endif()

# Handle the QUIETLY and REQUIRED arguments and set MSYSGIT_FOUND to TRUE if
# all listed variables are TRUE

include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(MsysGit
                                                                    REQUIRED_VARS MSYSGIT_BIN_DIR)


================================================
FILE: FindNetCDF.cmake
================================================
# - Find NetCDF
# Find the native NetCDF includes and library

# TODO:
#       - Check for system netcdf
#       - Make CXX a component

# C
find_path(NETCDF_INCLUDES_C NAMES netcdf.h
    HINTS ${NETCDF_ROOT} PATH_SUFFIXES include)
find_library(NETCDF_LIBRARIES_C NAMES netcdf
    HINTS ${NETCDF_ROOT} PATH_SUFFIXES lib)

# CXX
find_path(NETCDF_INCLUDES_CXX NAMES netcdf
    HINTS ${NETCDF_CXX_ROOT} PATH_SUFFIXES include)
find_library(NETCDF_LIBRARIES_CXX NAMES netcdf_c++4 netcdf-cxx4
    HINTS ${NETCDF_CXX_ROOT} PATH_SUFFIXES lib)

include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (NetCDF DEFAULT_MSG
    NETCDF_LIBRARIES_C
    NETCDF_LIBRARIES_CXX
    NETCDF_INCLUDES_C
    NETCDF_INCLUDES_CXX
)



================================================
FILE: FindOpenSG.cmake
================================================
# Copyright (c) 2012 - 2015, Lars Bilke
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
#    list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
#    this list of conditions and the following disclaimer in the documentation
#    and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
#    may be used to endorse or promote products derived from this software without
#    specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
#
# - Find OpenSG 1.8 libraries
# Find the specified OpenSG 1.8 libraries and header files. Slightly modified
# from the version for 2.0, see # 1.8 - comments
#
# Since OpenSG consists of a number of libraries you need to specify which
# of those you want to use. To do so, pass a list of their names after
# the COMPONENTS argument to FIND_PACKAGE. A typical call looks like this:
# FIND_PACKAGE(OpenSG REQUIRED COMPONENTS OSGBase OSGSystem OSGDrawable)
#
# This module specifies the following variables:
#  OpenSG_INCLUDE_DIRS
#  OpenSG_LIBRARIES
#  OpenSG_LIBRARY_DIRS
#
#  For each component COMP the capitalized name (e.g. OSGBASE, OSGSYSTEM):
#  OpenSG_${COMP}_LIBRARY
#  OpenSG_${COMP}_LIBRARY_RELEASE
#  OpenSG_${COMP}_LIBRARY_DEBUG
#
#  You can control where this module attempts to locate libraries and headers:
#  you can use the following input variables:
#  OPENSG_ROOT          root of an installed OpenSG with include/OpenSG and lib below it
#  OPENSG_INCLUDE_DIR   header directory
#  OPENSG_LIBRARY_DIR   library directory
#  OR
#  OPENSG_INCLUDE_SEARCH_DIR
#  OPENSG_LIBRARY_SEARCH_DIR

# This macro sets the include path and libraries to link to.
# On Windows this also sets some preprocessor definitions and disables some warnings.
MACRO(USE_OPENSG targetName)
	IF (MSVC)
		ADD_DEFINITIONS(
			-DOSG_BUILD_DLL
			-DOSG_HAVE_CONFIGURED_H_
			-DOSG_WITH_GIF
			-DOSG_WITH_TIF
			-DOSG_WITH_JPG
		)
		SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4231 /wd4275")
	ENDIF (MSVC)
	IF(OpenSG_OSGWINDOWGLUT_LIBRARY)
		ADD_DEFINITIONS(-DOSG_WITH_GLUT)
	ENDIF()
	TARGET_LINK_LIBRARIES( ${targetName} ${OpenSG_LIBRARIES} )
	INCLUDE_DIRECTORIES( ${OpenSG_INCLUDE_DIRS} )
ENDMACRO()

SET(__OpenSG_IN_CACHE TRUE)
IF(OpenSG_INCLUDE_DIR)
    FOREACH(COMPONENT ${OpenSG_FIND_COMPONENTS})
        STRING(TOUPPER ${COMPONENT} COMPONENT)
        IF(NOT OpenSG_${COMPONENT}_FOUND)
            SET(__OpenSG_IN_CACHE FALSE)
        ENDIF(NOT OpenSG_${COMPONENT}_FOUND)
    ENDFOREACH(COMPONENT)
ELSE(OpenSG_INCLUDE_DIR)
    SET(__OpenSG_IN_CACHE FALSE)
ENDIF(OpenSG_INCLUDE_DIR)


# The reason that we failed to find OpenSG. This will be set to a
# user-friendly message when we fail to find some necessary piece of
# OpenSG.
set(OpenSG_ERROR_REASON)

############################################
#
# Check the existence of the libraries.
#
############################################
# This macro is directly taken from FindBoost.cmake that comes with the cmake
# distribution. It is NOT my work, only minor modifications have been made to
# remove references to boost.
#########################################################################

MACRO(__OpenSG_ADJUST_LIB_VARS basename)
    IF(OpenSG_INCLUDE_DIR)
        IF(OpenSG_${basename}_LIBRARY_DEBUG AND OpenSG_${basename}_LIBRARY_RELEASE)
        # if the generator supports configuration types then set
        # optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a value
            IF (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
                SET(OpenSG_${basename}_LIBRARY optimized ${OpenSG_${basename}_LIBRARY_RELEASE} debug ${OpenSG_${basename}_LIBRARY_DEBUG})
            ELSE(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
                # if there are no configuration types and CMAKE_BUILD_TYPE has no value
                # then just use the release libraries
                SET(OpenSG_${basename}_LIBRARY ${OpenSG_${basename}_LIBRARY_RELEASE} )
            ENDIF(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)

            SET(OpenSG_${basename}_LIBRARIES optimized ${OpenSG_${basename}_LIBRARY_RELEASE} debug ${OpenSG_${basename}_LIBRARY_DEBUG})
        ENDIF(OpenSG_${basename}_LIBRARY_DEBUG AND OpenSG_${basename}_LIBRARY_RELEASE)

        # if only the release version was found, set the debug variable also to the release version
        IF(OpenSG_${basename}_LIBRARY_RELEASE AND NOT OpenSG_${basename}_LIBRARY_DEBUG)
            SET(OpenSG_${basename}_LIBRARY_DEBUG ${OpenSG_${basename}_LIBRARY_RELEASE})
            SET(OpenSG_${basename}_LIBRARY       ${OpenSG_${basename}_LIBRARY_RELEASE})
            SET(OpenSG_${basename}_LIBRARIES     ${OpenSG_${basename}_LIBRARY_RELEASE})
        ENDIF(OpenSG_${basename}_LIBRARY_RELEASE AND NOT OpenSG_${basename}_LIBRARY_DEBUG)

        # if only the debug version was found, set the release variable also to the debug version
        IF(OpenSG_${basename}_LIBRARY_DEBUG AND NOT OpenSG_${basename}_LIBRARY_RELEASE)
            SET(OpenSG_${basename}_LIBRARY_RELEASE ${OpenSG_${basename}_LIBRARY_DEBUG})
            SET(OpenSG_${basename}_LIBRARY         ${OpenSG_${basename}_LIBRARY_DEBUG})
            SET(OpenSG_${basename}_LIBRARIES       ${OpenSG_${basename}_LIBRARY_DEBUG})
        ENDIF(OpenSG_${basename}_LIBRARY_DEBUG AND NOT OpenSG_${basename}_LIBRARY_RELEASE)

        IF(OpenSG_${basename}_LIBRARY)
            SET(OpenSG_${basename}_LIBRARY ${OpenSG_${basename}_LIBRARY} CACHE FILEPATH "The OpenSG ${basename} library")
            GET_FILENAME_COMPONENT(OpenSG_LIBRARY_DIRS "${OpenSG_${basename}_LIBRARY}" PATH)
            SET(OpenSG_LIBRARY_DIRS ${OpenSG_LIBRARY_DIRS} CACHE FILEPATH "OpenSG library directory")
            SET(OpenSG_${basename}_FOUND ON CACHE INTERNAL "Whether the OpenSG ${basename} library found")
        ENDIF(OpenSG_${basename}_LIBRARY)

    ENDIF(OpenSG_INCLUDE_DIR)

    # Make variables changeble to the advanced user
    MARK_AS_ADVANCED(
        OpenSG_${basename}_LIBRARY
        OpenSG_${basename}_LIBRARY_RELEASE
        OpenSG_${basename}_LIBRARY_DEBUG
    )
ENDMACRO(__OpenSG_ADJUST_LIB_VARS)

#-------------------------------------------------------------------------------


IF(__OpenSG_IN_CACHE)
    # values are already in the cache

    SET(OpenSG_FOUND TRUE)
    FOREACH(COMPONENT ${OpenSG_FIND_COMPONENTS})
        STRING(TOUPPER ${COMPONENT} COMPONENT)
        __OpenSG_ADJUST_LIB_VARS(${COMPONENT})
        SET(OpenSG_LIBRARIES ${OpenSG_LIBRARIES} ${OpenSG_${COMPONENT}_LIBRARY})
    ENDFOREACH(COMPONENT)

    SET(OpenSG_INCLUDE_DIRS "${OpenSG_INCLUDE_DIR}" "${OpenSG_INCLUDE_DIR}/OpenSG")

ELSE(__OpenSG_IN_CACHE)
    # need to search for libs

	# Visual Studio x32
	if (VS32)
	  # Visual Studio x32
	  SET( __OpenSG_INCLUDE_SEARCH_DIRS
	    $ENV{OPENSG_ROOT}/include
	    ${OPENSG_ROOT}/include
	    ${LIBRARIES_DIR}/opensg/include
	    ${CMAKE_SOURCE_DIR}/../OpenSG/include )
	  SET( __OpenSG_LIBRARIES_SEARCH_DIRS
	    $ENV{OPENSG_ROOT}/lib
	    ${OPENSG_ROOT}/lib
	    ${LIBRARIES_DIR}/opensg/lib
	    ${CMAKE_SOURCE_DIR}/../opensg/lib )
	else (VS32)
	  if (VS64)
	    # Visual Studio x64
		SET( __OpenSG_INCLUDE_SEARCH_DIRS
		$ENV{OPENSG_ROOT}/include
		${OPENSG_ROOT}/include
	      ${LIBRARIES_DIR}/opensg_x64/include
	      ${CMAKE_SOURCE_DIR}/../opensg_x64/include )
		SET( __OpenSG_LIBRARIES_SEARCH_DIRS
		$ENV{OPENSG_ROOT}/lib
		${OPENSG_ROOT}/lib
	      ${LIBRARIES_DIR}/opensg_x64/lib
	      ${CMAKE_SOURCE_DIR}/../opensg_x64/lib )
	  else (VS64)
	    # Linux or Mac
		SET( __OpenSG_INCLUDE_SEARCH_DIRS
          "/usr/local"
	      "/usr/local/include" )
		SET( __OpenSG_LIBRARIES_SEARCH_DIRS
	      "/usr/local"
	      "/usr/local/lib" )
	  endif(VS64)
	endif (VS32)


    # handle input variable OPENSG_INCLUDE_DIR
    IF(OPENSG_INCLUDE_DIR)
        FILE(TO_CMAKE_PATH ${OPENSG_INCLUDE_DIR} OPENSG_INCLUDE_DIR)
        SET(__OpenSG_INCLUDE_SEARCH_DIRS
            ${OPENSG_INCLUDE_DIR} ${__OpenSG_INCLUDE_SEARCH_DIRS})
    ENDIF(OPENSG_INCLUDE_DIR)

    # handle input variable OPENSG_LIBRARY_DIR
    IF(OPENSG_LIBRARY_DIR)
        FILE(TO_CMAKE_PATH ${OPENSG_LIBRARY_DIR} OPENSG_LIBRARY_DIR)
        SET(__OpenSG_LIBRARIES_SEARCH_DIRS
            ${OPENSG_LIBRARY_DIR} ${__OpenSG_LIBRARIES_SEARCH_DIRS})
    ENDIF(OPENSG_LIBRARY_DIR)

    # handle input variable OPENSG_INCLUDE_SEARCH_DIR
    IF(OPENSG_INCLUDE_SEARCH_DIR)
        FILE(TO_CMAKE_PATH ${OPENSG_INCLUDE_SEARCH_DIR} OPENSG_INCLUDE_SEARCH_DIR)
        SET(__OpenSG_INCLUDE_SEARCH_DIRS
            ${OPENSG_INCLUDE_SEARCH_DIR} ${__OpenSG_INCLUDE_SEARCH_DIRS})
    ENDIF(OPENSG_INCLUDE_SEARCH_DIR)

    # handle input variable OPENSG_LIBRARY_SEARCH_DIR
    IF(OPENSG_LIBRARY_SEARCH_DIR)
        FILE(TO_CMAKE_PATH ${OPENSG_LIBRARY_SEARCH_DIR} OPENSG_LIBRARY_SEARCH_DIR)
        SET(__OpenSG_LIBRARIES_SEARCH_DIRS
            ${OPENSG_LIBRARY_SEARCH_DIR} ${__OpenSG_LIBRARIES_SEARCH_DIRS})
    ENDIF(OPENSG_LIBRARY_SEARCH_DIR)

    IF(NOT OpenSG_INCLUDE_DIR)
        # try to find include dirrectory by searching for OSGConfigured.h
        FIND_PATH(OpenSG_INCLUDE_DIR
            NAMES         OpenSG/OSGConfigured.h
            HINTS         ${__OpenSG_INCLUDE_SEARCH_DIRS})
    ENDIF(NOT OpenSG_INCLUDE_DIR)
	#message(STATUS "OpenSG_INCLUDE_DIR: " ${OpenSG_INCLUDE_DIR})
    # ------------------------------------------------------------------------
    #  Begin finding OpenSG libraries
    # ------------------------------------------------------------------------
    FOREACH(COMPONENT ${OpenSG_FIND_COMPONENTS})
        STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
        SET(OpenSG_${UPPERCOMPONENT}_LIBRARY "OpenSG_${UPPERCOMPONENT}_LIBRARY-NOTFOUND" )
        SET(OpenSG_${UPPERCOMPONENT}_LIBRARY_RELEASE "OpenSG_${UPPERCOMPONENT}_LIBRARY_RELEASE-NOTFOUND" )
        SET(OpenSG_${UPPERCOMPONENT}_LIBRARY_DEBUG "OpenSG_${UPPERCOMPONENT}_LIBRARY_DEBUG-NOTFOUND")

	IF (WIN32)
        FIND_LIBRARY(OpenSG_${UPPERCOMPONENT}_LIBRARY_RELEASE
            NAMES  ${COMPONENT}
            HINTS  ${__OpenSG_LIBRARIES_SEARCH_DIRS}
        )

		#message(STATUS "OpenSG Component: " ${COMPONENT})

        FIND_LIBRARY(OpenSG_${UPPERCOMPONENT}_LIBRARY_DEBUG
	    # 1.8 Added the "D" suffix
            NAMES  ${COMPONENT}D
            HINTS  ${__OpenSG_LIBRARIES_SEARCH_DIRS}
            # 1.8 Removed next line
	    #PATH_SUFFIXES "debug"
        )
	ELSE (WIN32)
	FIND_LIBRARY(OpenSG_${UPPERCOMPONENT}_LIBRARY_RELEASE
            NAMES  ${COMPONENT}
            HINTS  ${__OpenSG_LIBRARIES_SEARCH_DIRS}
	    PATH_SUFFIXES "/opt"
        )

		#message(STATUS "OpenSG Component: " ${COMPONENT})

        FIND_LIBRARY(OpenSG_${UPPERCOMPONENT}_LIBRARY_DEBUG
            NAMES  ${COMPONENT}
            HINTS  ${__OpenSG_LIBRARIES_SEARCH_DIRS}
	    PATH_SUFFIXES "/dbg"
        )
	ENDIF(WIN32)

        __OpenSG_ADJUST_LIB_VARS(${UPPERCOMPONENT})
    ENDFOREACH(COMPONENT)
    # ------------------------------------------------------------------------
    #  End finding OpenSG libraries
    # ------------------------------------------------------------------------

    SET(OpenSG_INCLUDE_DIRS "${OpenSG_INCLUDE_DIR}" "${OpenSG_INCLUDE_DIR}/OpenSG")

    SET(OpenSG_FOUND FALSE)

    IF(OpenSG_INCLUDE_DIR)
        SET(OpenSG_FOUND TRUE)

        # check if all requested components were found
        SET(__OpenSG_CHECKED_COMPONENT FALSE)
        SET(__OpenSG_MISSING_COMPONENTS)

        FOREACH(COMPONENT ${OpenSG_FIND_COMPONENTS})
            STRING(TOUPPER ${COMPONENT} COMPONENT)
            SET(__OpenSG_CHECKED_COMPONENT TRUE)

            IF(NOT OpenSG_${COMPONENT}_FOUND)
                STRING(TOLOWER ${COMPONENT} COMPONENT)
                LIST(APPEND __OpenSG_MISSING_COMPONENTS ${COMPONENT})
                SET(OpenSG_FOUND FALSE)
            ENDIF(NOT OpenSG_${COMPONENT}_FOUND)
        ENDFOREACH(COMPONENT)

        IF(__OpenSG_MISSING_COMPONENTS)
            # We were unable to find some libraries, so generate a sensible
            # error message that lists the libraries we were unable to find.
            SET(OpenSG_ERROR_REASON
                "${OpenSG_ERROR_REASON}\nThe following OpenSG libraries could not be found:\n")
            FOREACH(COMPONENT ${__OpenSG_MISSING_COMPONENTS})
                SET(OpenSG_ERROR_REASON
                    "${OpenSG_ERROR_REASON}        ${COMPONENT}\n")
            ENDFOREACH(COMPONENT)

            LIST(LENGTH OpenSG_FIND_COMPONENTS __OpenSG_NUM_COMPONENTS_WANTED)
            LIST(LENGTH __OpenSG_MISSING_COMPONENTS __OpenSG_NUM_MISSING_COMPONENTS)
            IF(${__OpenSG_NUM_COMPONENTS_WANTED} EQUAL ${__OpenSG_NUM_MISSING_COMPONENTS})
                SET(OpenSG_ERROR_REASON
                "${OpenSG_ERROR_REASON}No OpenSG libraries were found. You may need to set OPENSG_LIBRARY_DIR to the directory containing OpenSG libraries or OPENSG_ROOT to the location of OpenSG.")
            ELSE(${__OpenSG_NUM_COMPONENTS_WANTED} EQUAL ${__OpenSG_NUM_MISSING_COMPONENTS})
                SET(OpenSG_ERROR_REASON
                "${OpenSG_ERROR_REASON}Some (but not all) of the required OpenSG libraries were found. You may need to install these additional OpenSG libraries. Alternatively, set OPENSG_LIBRARY_DIR to the directory containing OpenSG libraries or OPENSG_ROOT to the location of OpenSG.")
            ENDIF(${__OpenSG_NUM_COMPONENTS_WANTED} EQUAL ${__OpenSG_NUM_MISSING_COMPONENTS})
        ENDIF(__OpenSG_MISSING_COMPONENTS)

    ENDIF(OpenSG_INCLUDE_DIR)

    IF(OpenSG_FOUND)
        IF(NOT OpenSG_FIND_QUIETLY)
            MESSAGE(STATUS "OpenSG found.")
        ENDIF(NOT OpenSG_FIND_QUIETLY)

        IF (NOT OpenSG_FIND_QUIETLY)
            MESSAGE(STATUS "Found the following OpenSG libraries:")
        ENDIF(NOT OpenSG_FIND_QUIETLY)

        FOREACH(COMPONENT  ${OpenSG_FIND_COMPONENTS})
            STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
            IF(OpenSG_${UPPERCOMPONENT}_FOUND)
                IF(NOT OpenSG_FIND_QUIETLY)
                    MESSAGE(STATUS "  ${COMPONENT}")
                ENDIF(NOT OpenSG_FIND_QUIETLY)
                SET(OpenSG_LIBRARIES ${OpenSG_LIBRARIES} ${OpenSG_${UPPERCOMPONENT}_LIBRARY})
            ENDIF(OpenSG_${UPPERCOMPONENT}_FOUND)
        ENDFOREACH(COMPONENT)

    ELSE(OpenSG_FOUND)
        IF(OpenSG_FIND_REQUIRED)
            MESSAGE(SEND_ERROR "Unable to find the requested OpenSG libraries.\n${OpenSG_ERROR_REASON}")
        ENDIF(OpenSG_FIND_REQUIRED)
    ENDIF(OpenSG_FOUND)

ENDIF(__OpenSG_IN_CACHE)


================================================
FILE: FindOpenSGSupportlibs.cmake
================================================
# - Try to find OpenSGSupportlibs
# Once done, this will define
#
#  OpenSGSupportlibs_FOUND
#  OpenSGSupportlibs_INCLUDE_DIRS
#  OpenSGSupportlibs_LIBRARIES

if (NOT OpenSGSupportlibs_FOUND)

    include(LibFindMacros)

    # Visual Studio x32
    if (VS32)
      # Visual Studio x32
      find_path( OpenSGSupportlibs_INCLUDE_DIR
        NAMES zlib.h
        PATHS ${LIBRARIES_DIR}/supportlibs/include
          ${CMAKE_SOURCE_DIR}/../supportlibs/include )

      find_library(OpenSGSupportlibs_LIBRARY
        NAMES glut32 libjpg libpng tif32 zlib
        PATHS ${LIBRARIES_DIR}/supportlibs/lib
          ${CMAKE_SOURCE_DIR}/../supportlibs/lib )
    else ()
      if (VS64)
        # Visual Studio x64
        find_path( OpenSGSupportlibs_INCLUDE_DIR
        NAMES zlib.h
        PATHS ${LIBRARIES_DIR}/supportlibs_x64/include
          ${CMAKE_SOURCE_DIR}/../supportlibs_x64/include )

      find_library(OpenSGSupportlibs_LIBRARY
        NAMES glut32 libjpg libpng tif32 zlib
        PATHS ${LIBRARIES_DIR}/supportlibs_x64/lib
          ${CMAKE_SOURCE_DIR}/../supportlibs_x64/lib )
      endif()
    endif ()

    # Set the include dir variables and the libraries and let libfind_process do the rest.
    # NOTE: Singular variables for this library, plural for libraries this this lib depends on.
    set(OpenSGSupportlibs_PROCESS_INCLUDES OpenSGSupportlibs_INCLUDE_DIR)
    set(OpenSGSupportlibs_PROCESS_LIBS OpenSGSupportlibs_LIBRARY)
    libfind_process(OpenSGSupportlibs)

endif ()

================================================
FILE: FindShapelib.cmake
================================================
find_path(Shapelib_INCLUDE_DIR NAMES shapefil.h)

if(MSVC)
    set(Shapelib_LIBNAME shapelib)
else()
    set(Shapelib_LIBNAME shp)
endif()

find_library(Shapelib_LIBRARY NAMES ${Shapelib_LIBNAME})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Shapelib
    FOUND_VAR Shapelib_FOUND
    REQUIRED_VARS Shapelib_INCLUDE_DIR Shapelib_LIBRARY
)

set(Shapelib_INCLUDE_DIRS ${Shapelib_INCLUDE_DIR})
set(Shapelib_LIBRARIES ${Shapelib_LIBRARY})

mark_as_advanced(Shapelib_INCLUDE_DIR Shapelib_LIBRARY)


================================================
FILE: FindVRPN.cmake
================================================
# - try to find VRPN library
#
# Cache Variables:
#  VRPN_LIBRARY
#  VRPN_SERVER_LIBRARY
#  VRPN_INCLUDE_DIR
#
# Non-cache variables you might use in your CMakeLists.txt:
#  VRPN_FOUND
#  VRPN_SERVER_LIBRARIES
#  VRPN_LIBRARIES
#  VRPN_INCLUDE_DIRS
#
# VRPN_ROOT_DIR is searched preferentially for these files
#
# Requires these CMake modules:
#  FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

set(VRPN_ROOT_DIR
	"${VRPN_ROOT_DIR}"
	CACHE
	PATH
	"Root directory to search for VRPN")

if("${CMAKE_SIZEOF_VOID_P}" MATCHES "8")
	set(_libsuffixes lib64 lib)

	# 64-bit dir: only set on win64
	file(TO_CMAKE_PATH "$ENV{ProgramW6432}" _progfiles)
else()
	set(_libsuffixes lib)
	if(NOT "$ENV{ProgramFiles(x86)}" STREQUAL "")
		# 32-bit dir: only set on win64
		file(TO_CMAKE_PATH "$ENV{ProgramFiles(x86)}" _progfiles)
	else()
		# 32-bit dir on win32, useless to us on win64
		file(TO_CMAKE_PATH "$ENV{ProgramFiles}" _progfiles)
	endif()
endif()

###
# Configure VRPN
###

find_path(VRPN_INCLUDE_DIR
	NAMES
	vrpn_Connection.h
	PATH_SUFFIXES
	include
	include/vrpn
	HINTS
	"${VRPN_ROOT_DIR}"
	PATHS
	"${_progfiles}/VRPN")

find_library(VRPN_LIBRARY
	NAMES
	vrpn
	PATH_SUFFIXES
	${_libsuffixes}
	HINTS
	"${VRPN_ROOT_DIR}"
	PATHS
	"${_progfiles}/VRPN")

find_library(VRPN_SERVER_LIBRARY
	NAMES
	vrpnserver
	PATH_SUFFIXES
	${_libsuffixes}
	HINTS
	"${VRPN_ROOT_DIR}"
	PATHS
	"${_progfiles}/VRPN")

###
# Dependencies
###
set(_deps_libs)
set(_deps_includes)
set(_deps_check)

find_package(quatlib)
list(APPEND _deps_libs ${QUATLIB_LIBRARIES})
list(APPEND _deps_includes ${QUATLIB_INCLUDE_DIRS})
list(APPEND _deps_check QUATLIB_FOUND)

if(NOT WIN32)
	find_package(Threads)
	list(APPEND _deps_libs ${CMAKE_THREAD_LIBS_INIT})
	list(APPEND _deps_check CMAKE_HAVE_THREADS_LIBRARY)
endif()


# handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(VRPN
	DEFAULT_MSG
	VRPN_LIBRARY
	VRPN_INCLUDE_DIR
	${_deps_check})

if(VRPN_FOUND)
	set(VRPN_INCLUDE_DIRS "${VRPN_INCLUDE_DIR}" ${_deps_includes})
	set(VRPN_LIBRARIES "${VRPN_LIBRARY}" ${_deps_libs})
	set(VRPN_SERVER_LIBRARIES "${VRPN_SERVER_LIBRARY}" ${_deps_libs})

	mark_as_advanced(VRPN_ROOT_DIR)
endif()

mark_as_advanced(VRPN_LIBRARY
	VRPN_SERVER_LIBRARY
	VRPN_INCLUDE_DIR)


================================================
FILE: Findcppcheck.cmake
================================================
# - try to find cppcheck tool
#
# Cache Variables:
#  CPPCHECK_EXECUTABLE
#
# Non-cache variables you might use in your CMakeLists.txt:
#  CPPCHECK_FOUND
#  CPPCHECK_POSSIBLEERROR_ARG
#  CPPCHECK_UNUSEDFUNC_ARG
#  CPPCHECK_STYLE_ARG
#  CPPCHECK_QUIET_ARG
#  CPPCHECK_INCLUDEPATH_ARG
#  CPPCHECK_FAIL_REGULAR_EXPRESSION
#  CPPCHECK_WARN_REGULAR_EXPRESSION
#  CPPCHECK_MARK_AS_ADVANCED - whether to mark our vars as advanced even
#    if we don't find this program.
#
# Requires these CMake modules:
#  FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

file(TO_CMAKE_PATH "${CPPCHECK_ROOT_DIR}" CPPCHECK_ROOT_DIR)
set(CPPCHECK_ROOT_DIR
    "${CPPCHECK_ROOT_DIR}"
    CACHE
    PATH
    "Path to search for cppcheck")

# cppcheck app bundles on Mac OS X are GUI, we want command line only
set(_oldappbundlesetting ${CMAKE_FIND_APPBUNDLE})
set(CMAKE_FIND_APPBUNDLE NEVER)

if(CPPCHECK_EXECUTABLE AND NOT EXISTS "${CPPCHECK_EXECUTABLE}")
    set(CPPCHECK_EXECUTABLE "notfound" CACHE PATH FORCE "")
endif()

# If we have a custom path, look there first.
if(CPPCHECK_ROOT_DIR)
    find_program(CPPCHECK_EXECUTABLE
        NAMES
        cppcheck
        cli
        PATHS
        "${CPPCHECK_ROOT_DIR}"
        PATH_SUFFIXES
        cli
        NO_DEFAULT_PATH)
endif()

find_program(CPPCHECK_EXECUTABLE NAMES cppcheck)

# Restore original setting for appbundle finding
set(CMAKE_FIND_APPBUNDLE ${_oldappbundlesetting})

# Find out where our test file is
get_filename_component(_cppcheckmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
set(_cppcheckdummyfile "${_cppcheckmoddir}/Findcppcheck.cpp")

function(_cppcheck_test_arg _resultvar _arg)
    if(NOT CPPCHECK_EXECUTABLE)
        set(${_resultvar} NO)
        return()
    endif()
    execute_process(COMMAND
        "${CPPCHECK_EXECUTABLE}"
        "${_arg}"
        "--quiet"
        "${_cppcheckdummyfile}"
        RESULT_VARIABLE
        _cppcheck_result
        OUTPUT_QUIET
        ERROR_QUIET)
    if("${_cppcheck_result}" EQUAL 0)
        set(${_resultvar} YES PARENT_SCOPE)
    else()
        set(${_resultvar} NO PARENT_SCOPE)
    endif()
endfunction()

function(_cppcheck_set_arg_var _argvar _arg)
    if("${${_argvar}}" STREQUAL "")
        _cppcheck_test_arg(_cppcheck_arg "${_arg}")
        if(_cppcheck_arg)
            set(${_argvar} "${_arg}" PARENT_SCOPE)
        endif()
    endif()
endfunction()

if(CPPCHECK_EXECUTABLE)

    # Check for the two types of command line arguments by just trying them
    _cppcheck_set_arg_var(CPPCHECK_STYLE_ARG "--enable=style")
    _cppcheck_set_arg_var(CPPCHECK_STYLE_ARG "--style")
    if("${CPPCHECK_STYLE_ARG}" STREQUAL "--enable=style")

        _cppcheck_set_arg_var(CPPCHECK_UNUSEDFUNC_ARG "--enable=unusedFunction")
        _cppcheck_set_arg_var(CPPCHECK_INFORMATION_ARG "--enable=information")
        _cppcheck_set_arg_var(CPPCHECK_MISSINGINCLUDE_ARG "--enable=missingInclude")
        _cppcheck_set_arg_var(CPPCHECK_POSIX_ARG "--enable=posix")
        _cppcheck_set_arg_var(CPPCHECK_POSSIBLEERROR_ARG "--enable=possibleError")
        _cppcheck_set_arg_var(CPPCHECK_POSSIBLEERROR_ARG "--enable=all")

        if(MSVC)
            set(CPPCHECK_TEMPLATE_ARG --template vs)
            set(CPPCHECK_FAIL_REGULAR_EXPRESSION "[(]error[)]")
            set(CPPCHECK_WARN_REGULAR_EXPRESSION "[(]style[)]")
        elseif(CMAKE_COMPILER_IS_GNUCXX)
            set(CPPCHECK_TEMPLATE_ARG --template gcc)
            set(CPPCHECK_FAIL_REGULAR_EXPRESSION " error: ")
            set(CPPCHECK_WARN_REGULAR_EXPRESSION " style: ")
        else()
            set(CPPCHECK_TEMPLATE_ARG --template gcc)
            set(CPPCHECK_FAIL_REGULAR_EXPRESSION " error: ")
            set(CPPCHECK_WARN_REGULAR_EXPRESSION " style: ")
        endif()
    elseif("${CPPCHECK_STYLE_ARG}" STREQUAL "--style")
        # Old arguments
        _cppcheck_set_arg_var(CPPCHECK_UNUSEDFUNC_ARG "--unused-functions")
        _cppcheck_set_arg_var(CPPCHECK_POSSIBLEERROR_ARG "--all")
        set(CPPCHECK_FAIL_REGULAR_EXPRESSION "error:")
        set(CPPCHECK_WARN_REGULAR_EXPRESSION "[(]style[)]")
    else()
        # No idea - some other issue must be getting in the way
        message(STATUS
            "WARNING: Can't detect whether CPPCHECK wants new or old-style arguments!")
    endif()

    set(CPPCHECK_QUIET_ARG "--quiet")
    set(CPPCHECK_INCLUDEPATH_ARG "-I")

endif()

set(CPPCHECK_ALL
    "${CPPCHECK_EXECUTABLE} ${CPPCHECK_POSSIBLEERROR_ARG} ${CPPCHECK_UNUSEDFUNC_ARG} ${CPPCHECK_STYLE_ARG} ${CPPCHECK_QUIET_ARG} ${CPPCHECK_INCLUDEPATH_ARG} some/include/path")

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(cppcheck
    DEFAULT_MSG
    CPPCHECK_ALL
    CPPCHECK_EXECUTABLE
    CPPCHECK_POSSIBLEERROR_ARG
    CPPCHECK_UNUSEDFUNC_ARG
    CPPCHECK_STYLE_ARG
    CPPCHECK_INCLUDEPATH_ARG
    CPPCHECK_QUIET_ARG)

if(CPPCHECK_FOUND OR CPPCHECK_MARK_AS_ADVANCED)
    mark_as_advanced(CPPCHECK_ROOT_DIR)
endif()

mark_as_advanced(CPPCHECK_EXECUTABLE)


================================================
FILE: Findcppcheck.cpp
================================================
/**
 * \file Findcppcheck.cpp
 * \brief Dummy C++ source file used by CMake module Findcppcheck.cmake
 *
 * \author
 * Ryan Pavlik, 2009-2010
 * <rpavlik@iastate.edu>
 * http://academic.cleardefinition.com/
 *
 */



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


================================================
FILE: Findquatlib.cmake
================================================
# - Find quatlib
# Find the quatlib headers and libraries.
#
#  QUATLIB_INCLUDE_DIRS - where to find quat.h
#  QUATLIB_LIBRARIES    - List of libraries when using quatlib.
#  QUATLIB_FOUND        - True if quatlib found.
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

if(TARGET quat)
	# Look for the header file.
	find_path(QUATLIB_INCLUDE_DIR NAMES quat.h
			PATHS ${quatlib_SOURCE_DIR})

	set(QUATLIB_LIBRARY "quat")

else()
	set(QUATLIB_ROOT_DIR
		"${QUATLIB_ROOT_DIR}"
		CACHE
		PATH
		"Root directory to search for quatlib")
	if(DEFINED VRPN_ROOT_DIR AND NOT QUATLIB_ROOT_DIR)
		set(QUATLIB_ROOT_DIR "${VRPN_ROOT_DIR}")
		mark_as_advanced(QUATLIB_ROOT_DIR)
	endif()

	if("${CMAKE_SIZEOF_VOID_P}" MATCHES "8")
		set(_libsuffixes lib64 lib)

		# 64-bit dir: only set on win64
		file(TO_CMAKE_PATH "$ENV{ProgramW6432}" _progfiles)
	else()
		set(_libsuffixes lib)
		if(NOT "$ENV{ProgramFiles(x86)}" STREQUAL "")
			# 32-bit dir: only set on win64
			file(TO_CMAKE_PATH "$ENV{ProgramFiles(x86)}" _progfiles)
		else()
			# 32-bit dir on win32, useless to us on win64
			file(TO_CMAKE_PATH "$ENV{ProgramFiles}" _progfiles)
		endif()
	endif()

	# Look for the header file.
	find_path(QUATLIB_INCLUDE_DIR
		NAMES
		quat.h
		HINTS
		"${QUATLIB_ROOT_DIR}"
		PATH_SUFFIXES
		include
		PATHS
		"${_progfiles}/VRPN"
		"${_progfiles}/quatlib")

	# Look for the library.
	find_library(QUATLIB_LIBRARY
		NAMES
		quat.lib
		libquat.a
		HINTS
		"${QUATLIB_ROOT_DIR}"
		PATH_SUFFIXES
		${_libsuffixes}
		PATHS
		"${_progfiles}/VRPN"
		"${_progfiles}/quatlib")
endif()

# handle the QUIETLY and REQUIRED arguments and set QUATLIB_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(quatlib
	DEFAULT_MSG
	QUATLIB_LIBRARY
	QUATLIB_INCLUDE_DIR)

if(QUATLIB_FOUND)
	set(QUATLIB_LIBRARIES ${QUATLIB_LIBRARY})
	if(NOT WIN32)
		list(APPEND QUATLIB_LIBRARIES m)
	endif()
	set(QUATLIB_INCLUDE_DIRS ${QUATLIB_INCLUDE_DIR})

	mark_as_advanced(QUATLIB_ROOT_DIR)
else()
	set(QUATLIB_LIBRARIES)
	set(QUATLIB_INCLUDE_DIRS)
endif()

mark_as_advanced(QUATLIB_LIBRARY QUATLIB_INCLUDE_DIR)


================================================
FILE: GetCPUDetails.cmake
================================================
# - Set a number of variables to indicate things about the current CPU and OS
#
#  CPU_INTEL
#  CPU_EXE_64BIT
#  CPU_EXE_32BIT
#  CPU_HAS_SSE
#  CPU_HAS_SSE2
#  CPU_HAS_SSE3
#  CPU_HAS_SSSE3
#  CPU_HAS_SSE4_1
#  CPU_HAS_SSE4_2
#
# Requires these CMake modules:
#  no additional modules required
#
# Original Author:
# 2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#


if(__get_cpu_details)
    return()
endif()
set(__get_cpu_details YES)

function(get_cpu_details)
    option(CPUDETAILS_VERBOSE
        "Should we display results of the CPU info check?"
        NO)
    mark_as_advanced(CPUDETAILS_VERBOSE)

    ###
    # CPU_INTEL

    if("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64" OR "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "i[3456]86")
        set(CPU_INTEL YES)
    elseif(APPLE)
        # Mac Intel boxes return i386 in 10.5 - so assume this is a PPC
        set(CPU_INTEL NO)
    else()
        # TODO: Assuming yes in case of doubt - probably not a great idea
        set(CPU_INTEL YES)
    endif()

    set(CPU_INTEL
        ${CPU_INTEL}
        CACHE
        INTERNAL
        "Intel x86 or x86_64 architecture machine?")

    ###
    # CPU_EXE_64BIT/32BIT
    if(CMAKE_SIZEOF_VOID_P EQUAL 8)
        set(CPU_EXE_64BIT ON)
        set(CPU_EXE_32BIT OFF)
    else()
        set(CPU_EXE_64BIT OFF)
        set(CPU_EXE_32BIT ON)
    endif()

    ###
    # CPU_HAS_SSE/SSE2/SSE3/SSSE3/SSE4.1/SSE4.2
    if(CPU_INTEL)
        if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
            # Use /proc/cpuinfo to find this out.
            file(STRINGS "/proc/cpuinfo" _cpuinfo)
            if(_cpuinfo MATCHES "(sse)|(xmm)")
                set(CPU_HAS_SSE YES)
            else()
                set(CPU_HAS_SSE NO)
            endif()

            if(_cpuinfo MATCHES "(sse2)|(xmm2)")
                set(CPU_HAS_SSE2 YES)
            else()
                set(CPU_HAS_SSE2 NO)
            endif()

            if(_cpuinfo MATCHES "(sse3)|(xmm3)")
                set(CPU_HAS_SSE3 YES)
            else()
                set(CPU_HAS_SSE3 NO)
            endif()

            if(_cpuinfo MATCHES "ssse3")
                set(CPU_HAS_SSSE3 YES)
            else()
                set(CPU_HAS_SSSE3 NO)
            endif()

            if(_cpuinfo MATCHES "(sse4_1)|(xmm4_1)")
                set(CPU_HAS_SSE4_1 YES)
            else()
                set(CPU_HAS_SSE4_1 NO)
            endif()

            if(_cpuinfo MATCHES "(sse4_2)|(xmm4_2)")
                set(CPU_HAS_SSE4_2 YES)
            else()
                set(CPU_HAS_SSE4_2 NO)
            endif()

        elseif(APPLE)
            # Mac OS X Intel requires SSE3
            set(CPU_HAS_SSE YES)
            set(CPU_HAS_SSE2 YES)
            set(CPU_HAS_SSE3 YES)
            set(CPU_HAS_SSSE3 NO)
            set(CPU_HAS_SSE4_1 NO)
            set(CPU_HAS_SSE4_2 NO)
        elseif(WIN32)
            if(CPU_EXE_64BIT)
                #TODO: Assume only common-denominator for 64-bit machines,
                # since I don't know how to check.
                set(CPU_HAS_SSE YES)
                set(CPU_HAS_SSE2 YES)
                set(CPU_HAS_SSE3 NO)
                set(CPU_HAS_SSSE3 NO)
                set(CPU_HAS_SSE4_1 NO)
                set(CPU_HAS_SSE4_2 NO)
            else()
                #TODO:  Assume no SSE, since I don't know how to check.
                set(CPU_HAS_SSE NO)
                set(CPU_HAS_SSE2 NO)
                set(CPU_HAS_SSE3 NO)
                set(CPU_HAS_SSSE3 NO)
                set(CPU_HAS_SSE4_1 NO)
                set(CPU_HAS_SSE4_2 NO)
            endif()
        endif()
    endif()

    set(CPU_INTEL
        ${CPU_INTEL}
        CACHE
        INTERNAL
        "Intel x86 or x86_64 architecture machine?")

    foreach(_var
        CPU_EXE_64BIT
        CPU_EXE_32BIT
        CPU_HAS_SSE
        CPU_HAS_SSE2
        CPU_HAS_SSE3
        CPU_HAS_SSSE3
        CPU_HAS_SSE4_1
        CPU_HAS_SSE4_2)
        set(${_var} ${${_var}} CACHE INTERNAL "")
    endforeach()

    if(CPUDETAILS_VERBOSE)
        foreach(_var
            CPU_INTEL
            CPU_EXE_64BIT
            CPU_EXE_32BIT
            CPU_HAS_SSE
            CPU_HAS_SSE2
            CPU_HAS_SSE3
            CPU_HAS_SSSE3
            CPU_HAS_SSE4_1
            CPU_HAS_SSE4_2)
            get_property(_help CACHE ${_var} PROPERTY HELPSTRING)
            message(STATUS "[get_cpu_details] ${_var} (${_help}): ${${_var}}")
        endforeach()
    endif()
endfunction()


================================================
FILE: GetGitRevisionDescription.cmake
================================================
# - Returns a version string from Git
#
# These functions force a re-configure on each git commit so that you can
# trust the values of the variables in your build system.
#
#  get_git_head_revision(<refspecvar> <hashvar> [<additional arguments to git describe> ...])
#
# Returns the refspec and sha hash of the current head revision
#
#  git_describe(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe on the source tree, and adjusting
# the output so that it tests false if an error occurs.
#
#  git_get_exact_tag(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe --exact-match on the source tree,
# and adjusting the output so that it tests false if there was no exact
# matching tag.
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

if(__get_git_revision_description)
    return()
endif()
set(__get_git_revision_description YES)

# We must run the following at "include" time, not at function call time,
# to find the path to this module rather than the path to a calling list file
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)

function(get_git_head_revision _refspecvar _hashvar)
    set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
    set(GIT_DIR "${GIT_PARENT_DIR}/.git")
    while(NOT EXISTS "${GIT_DIR}")    # .git dir not found, search parent directories
        set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
        get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
        if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
            # We have reached the root directory, we are not in git
            set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
            set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
            return()
        endif()
        set(GIT_DIR "${GIT_PARENT_DIR}/.git")
    endwhile()
    # check if this is a submodule
    if(NOT IS_DIRECTORY ${GIT_DIR})
        file(READ ${GIT_DIR} submodule)
        string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule})
        get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)

        if (IS_ABSOLUTE ${GIT_DIR_RELATIVE})
            set(GIT_DIR ${GIT_DIR_RELATIVE})
        else()
            get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE)
        endif()

    endif()
    set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
    if(NOT EXISTS "${GIT_DATA}")
        file(MAKE_DIRECTORY "${GIT_DATA}")
    endif()

    if(NOT EXISTS "${GIT_DIR}/HEAD")
        return()
    endif()
    set(HEAD_FILE "${GIT_DATA}/HEAD")
    configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)

    configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
        "${GIT_DATA}/grabRef.cmake"
        @ONLY)
    include("${GIT_DATA}/grabRef.cmake")

    set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
    set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
endfunction()

function(git_describe _var)
    if(NOT GIT_FOUND)
        find_package(Git QUIET)
    endif()
    get_git_head_revision(refspec hash)
    if(NOT GIT_FOUND)
        set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
        return()
    endif()
    if(NOT hash)
        set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
        return()
    endif()

    # TODO sanitize
    #if((${ARGN}" MATCHES "&&") OR
    #    (ARGN MATCHES "||") OR
    #    (ARGN MATCHES "\\;"))
    #    message("Please report the following error to the project!")
    #    message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
    #endif()

    #message(STATUS "Arguments to execute_process: ${ARGN}")

    execute_process(COMMAND
        ${GIT_EXECUTABLE}
        describe
        ${hash}
        ${ARGN}
        WORKING_DIRECTORY
        "${CMAKE_SOURCE_DIR}"
        RESULT_VARIABLE
        res
        OUTPUT_VARIABLE
        out
        ERROR_QUIET
        OUTPUT_STRIP_TRAILING_WHITESPACE)
    if(NOT res EQUAL 0)
        set(out "${out}-${res}-NOTFOUND")
    endif()

    set(${_var} "${out}" PARENT_SCOPE)
endfunction()

function(git_get_exact_tag _var)
    git_describe(out --exact-match ${ARGN})
    set(${_var} "${out}" PARENT_SCOPE)
endfunction()

function(git_get_tag _var)
    git_describe(out --tags ${ARGN})
    set(${_var} "${out}" PARENT_SCOPE)
endfunction()


================================================
FILE: GetGitRevisionDescription.cmake.in
================================================
# 
# Internal file for GetGitRevisionDescription.cmake
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

set(HEAD_HASH)

file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)

string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
if(HEAD_CONTENTS MATCHES "ref")
	# named branch
	string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
	if(EXISTS "@GIT_DIR@/${HEAD_REF}")
	configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
	elseif(EXISTS "@GIT_DIR@/logs/${HEAD_REF}")
		configure_file("@GIT_DIR@/logs/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
		set(HEAD_HASH "${HEAD_REF}")
	endif()
else()
	# detached HEAD
	configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
endif()

if(NOT HEAD_HASH)
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
string(STRIP "${HEAD_HASH}" HEAD_HASH)
endif()


================================================
FILE: LICENSE_1_0.txt
================================================
Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.


================================================
FILE: ListAllCMakeVariableValues.cmake
================================================
# From http://www.kitware.com/blog/home/post/300
#
# Usage:
#
#  include(ListAllCMakeVariableValues)
#  list_all_cmake_variable_values()

function(list_all_cmake_variable_values)
  message(STATUS "")
  get_cmake_property(vs VARIABLES)
  foreach(v ${vs})
    message(STATUS "${v}='${${v}}'")
  endforeach()
  message(STATUS "")
endfunction()


================================================
FILE: OptionRequires.cmake
================================================
# - Add an option that depends on one or more variables being true.
#
#  option_requires(<option_name> <description> <variable_name> [<variable_name>...])
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

function(option_requires name desc)
    set(args ${ARGN})

    set(OFF_BY_DEFAULT true)
    list(FIND args "OFF_BY_DEFAULT" _off_found)
    if(NOT _off_found EQUAL -1)
        list(REMOVE_AT args ${_off_found})
        set(OFF_BY_DEFAULT true)
    endif()

    set(found)
    set(missing)
    foreach(var ${args})
        if(${var})
            list(APPEND found ${var})
        else()
            list(APPEND missing ${var})
        endif()
    endforeach()

    if(NOT missing)
        set(OK TRUE)
    else()
        set(OK FALSE)
    endif()

    set(default ${OK})
    if(OFF_BY_DEFAULT)
        set(default OFF)
    endif()

    option(${name} "${desc}" ${default})

    if(${name} AND (NOT OK))
        message(FATAL_ERROR "${name} enabled but these dependencies were not valid: ${missing}")
    endif()

endfunction()


================================================
FILE: PrintVariables.cmake
================================================
# ------------------------- Begin Generic CMake Variable Logging ------------------

# /*    C++ comment style not allowed    */


# if you are building in-source, this is the same as CMAKE_SOURCE_DIR, otherwise 
# this is the top level directory of your build tree 
message( STATUS "CMAKE_BINARY_DIR:         " ${CMAKE_BINARY_DIR} )

# if you are building in-source, this is the same as CMAKE_CURRENT_SOURCE_DIR, otherwise this 
# is the directory where the compiled or generated files from the current CMakeLists.txt will go to 
message( STATUS "CMAKE_CURRENT_BINARY_DIR: " ${CMAKE_CURRENT_BINARY_DIR} )

# this is the directory, from which cmake was started, i.e. the top level source directory 
message( STATUS "CMAKE_SOURCE_DIR:         " ${CMAKE_SOURCE_DIR} )

# this is the directory where the currently processed CMakeLists.txt is located in 
message( STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR} )

# contains the full path to the top level directory of your build tree 
message( STATUS "PROJECT_BINARY_DIR: " ${PROJECT_BINARY_DIR} )

# contains the full path to the root of your project source directory,
# i.e. to the nearest directory where CMakeLists.txt contains the project() command 
message( STATUS "PROJECT_SOURCE_DIR: " ${PROJECT_SOURCE_DIR} )

# set this variable to specify a common place where CMake should put all executable files
# (instead of CMAKE_CURRENT_BINARY_DIR)
message( STATUS "EXECUTABLE_OUTPUT_PATH: " ${EXECUTABLE_OUTPUT_PATH} )

# set this variable to specify a common place where CMake should put all libraries 
# (instead of CMAKE_CURRENT_BINARY_DIR)
message( STATUS "LIBRARY_OUTPUT_PATH:     " ${LIBRARY_OUTPUT_PATH} )

# tell CMake to search first in directories listed in CMAKE_MODULE_PATH
# when you use find_package() or include()
message( STATUS "CMAKE_MODULE_PATH: " ${CMAKE_MODULE_PATH} )

# this is the complete path of the cmake which runs currently (e.g. /usr/local/bin/cmake) 
message( STATUS "CMAKE_COMMAND: " ${CMAKE_COMMAND} )

# this is the CMake installation directory 
message( STATUS "CMAKE_ROOT: " ${CMAKE_ROOT} )

# this is the filename including the complete path of the file where this variable is used. 
message( STATUS "CMAKE_CURRENT_LIST_FILE: " ${CMAKE_CURRENT_LIST_FILE} )

# this is linenumber where the variable is used
message( STATUS "CMAKE_CURRENT_LIST_LINE: " ${CMAKE_CURRENT_LIST_LINE} )

# this is used when searching for include files e.g. using the find_path() command.
message( STATUS "CMAKE_INCLUDE_PATH: " ${CMAKE_INCLUDE_PATH} )

# this is used when searching for libraries e.g. using the find_library() command.
message( STATUS "CMAKE_LIBRARY_PATH: " ${CMAKE_LIBRARY_PATH} )

# the complete system name, e.g. "Linux-2.4.22", "FreeBSD-5.4-RELEASE" or "Windows 5.1" 
message( STATUS "CMAKE_SYSTEM: " ${CMAKE_SYSTEM} )

# the short system name, e.g. "Linux", "FreeBSD" or "Windows"
message( STATUS "CMAKE_SYSTEM_NAME: " ${CMAKE_SYSTEM_NAME} )

# only the version part of CMAKE_SYSTEM 
message( STATUS "CMAKE_SYSTEM_VERSION: " ${CMAKE_SYSTEM_VERSION} )

# the processor name (e.g. "Intel(R) Pentium(R) M processor 2.00GHz") 
message( STATUS "CMAKE_SYSTEM_PROCESSOR: " ${CMAKE_SYSTEM_PROCESSOR} )

# is TRUE on all UNIX-like OS's, including Apple OS X and CygWin
message( STATUS "UNIX: " ${UNIX} )

# is TRUE on Windows, including CygWin 
message( STATUS "WIN32: " ${WIN32} )

# is TRUE on Apple OS X
message( STATUS "APPLE: " ${APPLE} )

# is TRUE when using the MinGW compiler in Windows
message( STATUS "MINGW: " ${MINGW} )

# is TRUE on Windows when using the CygWin version of cmake
message( STATUS "CYGWIN: " ${CYGWIN} )

# is TRUE on Windows when using a Borland compiler 
message( STATUS "BORLAND: " ${BORLAND} )

# Microsoft compiler 
message( STATUS "MSVC: " ${MSVC} )
message( STATUS "MSVC_IDE: " ${MSVC_IDE} )
message( STATUS "MSVC60: " ${MSVC60} )
message( STATUS "MSVC70: " ${MSVC70} )
message( STATUS "MSVC71: " ${MSVC71} )
message( STATUS "MSVC80: " ${MSVC80} )
message( STATUS "CMAKE_COMPILER_2005: " ${CMAKE_COMPILER_2005} )


# set this to true if you don't want to rebuild the object files if the rules have changed, 
# but not the actual source files or headers (e.g. if you changed the some compiler switches) 
message( STATUS "CMAKE_SKIP_RULE_DEPENDENCY: " ${CMAKE_SKIP_RULE_DEPENDENCY} )

# since CMake 2.1 the install rule depends on all, i.e. everything will be built before installing. 
# If you don't like this, set this one to true.
message( STATUS "CMAKE_SKIP_INSTALL_ALL_DEPENDENCY: " ${CMAKE_SKIP_INSTALL_ALL_DEPENDENCY} )

# If set, runtime paths are not added when using shared libraries. Default it is set to OFF
message( STATUS "CMAKE_SKIP_RPATH: " ${CMAKE_SKIP_RPATH} )

# set this to true if you are using makefiles and want to see the full compile and link 
# commands instead of only the shortened ones 
message( STATUS "CMAKE_VERBOSE_MAKEFILE: " ${CMAKE_VERBOSE_MAKEFILE} )

# this will cause CMake to not put in the rules that re-run CMake. This might be useful if 
# you want to use the generated build files on another machine. 
message( STATUS "CMAKE_SUPPRESS_REGENERATION: " ${CMAKE_SUPPRESS_REGENERATION} )


# A simple way to get switches to the compiler is to use add_definitions(). 
# But there are also two variables exactly for this purpose: 

# the compiler flags for compiling C sources 
message( STATUS "CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS} )

# the compiler flags for compiling C++ sources 
message( STATUS "CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS} )


# Choose the type of build.  Example: set(CMAKE_BUILD_TYPE Debug) 
message( STATUS "CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE} )

# if this is set to ON, then all libraries are built as shared libraries by default.
message( STATUS "BUILD_SHARED_LIBS: " ${BUILD_SHARED_LIBS} )

# the compiler used for C files 
message( STATUS "CMAKE_C_COMPILER: " ${CMAKE_C_COMPILER} )

# the compiler used for C++ files 
message( STATUS "CMAKE_CXX_COMPILER: " ${CMAKE_CXX_COMPILER} )

# if the compiler is a variant of gcc, this should be set to 1 
message( STATUS "CMAKE_COMPILER_IS_GNUCC: " ${CMAKE_COMPILER_IS_GNUCC} )

# if the compiler is a variant of g++, this should be set to 1 
message( STATUS "CMAKE_COMPILER_IS_GNUCXX : " ${CMAKE_COMPILER_IS_GNUCXX} )

# the tools for creating libraries 
message( STATUS "CMAKE_AR: " ${CMAKE_AR} )
message( STATUS "CMAKE_RANLIB: " ${CMAKE_RANLIB} )

#
#message( STATUS ": " ${} )

# ------------------------- End of Generic CMake Variable Logging ------------------


================================================
FILE: ProcessorCount.cmake
================================================
# - ProcessorCount(var)
# Determine the number of processors/cores and save value in ${var}
#
# Sets the variable named ${var} to the number of physical cores available on
# the machine if the information can be determined. Otherwise it is set to 0.
# Currently this functionality is implemented for AIX, cygwin, FreeBSD, HPUX,
# IRIX, Linux, Mac OS X, QNX, Sun and Windows.
#
# This function is guaranteed to return a positive integer (>=1) if it
# succeeds. It returns 0 if there's a problem determining the processor count.
#
# Example use, in a ctest -S dashboard script:
#
#   include(ProcessorCount)
#   ProcessorCount(N)
#   if(NOT N EQUAL 0)
#     set(CTEST_BUILD_FLAGS -j${N})
#     set(ctest_test_args ${ctest_test_args} PARALLEL_LEVEL ${N})
#   endif()
#
# This function is intended to offer an approximation of the value of the
# number of compute cores available on the current machine, such that you
# may use that value for parallel building and parallel testing. It is meant
# to help utilize as much of the machine as seems reasonable. Of course,
# knowledge of what else might be running on the machine simultaneously
# should be used when deciding whether to request a machine's full capacity
# all for yourself.

# A more reliable way might be to compile a small C program that uses the CPUID
# instruction, but that again requires compiler support or compiling assembler
# code.

#=============================================================================
# Copyright 2010-2011 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
#  License text for the above reference.)

function(ProcessorCount var)
  # Unknown:
  set(count 0)

  if(WIN32)
    # Windows:
    set(count "$ENV{NUMBER_OF_PROCESSORS}")
    #message("ProcessorCount: WIN32, trying environment variable")
  endif()

  if(NOT count)
    # Mac, FreeBSD, OpenBSD (systems with sysctl):
    find_program(ProcessorCount_cmd_sysctl sysctl
      PATHS /usr/sbin /sbin)
    if(ProcessorCount_cmd_sysctl)
      execute_process(COMMAND ${ProcessorCount_cmd_sysctl} -n hw.ncpu
        ERROR_QUIET
        OUTPUT_STRIP_TRAILING_WHITESPACE
        OUTPUT_VARIABLE count)
      #message("ProcessorCount: trying sysctl '${ProcessorCount_cmd_sysctl}'")
    endif()
  endif()

  if(NOT count)
    # Linux (systems with getconf):
    find_program(ProcessorCount_cmd_getconf getconf)
    if(ProcessorCount_cmd_getconf)
      execute_process(COMMAND ${ProcessorCount_cmd_getconf} _NPROCESSORS_ONLN
        ERROR_QUIET
        OUTPUT_STRIP_TRAILING_WHITESPACE
        OUTPUT_VARIABLE count)
      #message("ProcessorCount: trying getconf '${ProcessorCount_cmd_getconf}'")
    endif()
  endif()

  if(NOT count)
    # HPUX (systems with machinfo):
    find_program(ProcessorCount_cmd_machinfo machinfo
      PATHS /usr/contrib/bin)
    if(ProcessorCount_cmd_machinfo)
      execute_process(COMMAND ${ProcessorCount_cmd_machinfo}
        ERROR_QUIET
        OUTPUT_STRIP_TRAILING_WHITESPACE
        OUTPUT_VARIABLE machinfo_output)
      string(REGEX MATCHALL "Number of CPUs = ([0-9]+)" procs "${machinfo_output}")
      set(count "${CMAKE_MATCH_1}")
      #message("ProcessorCount: trying machinfo '${ProcessorCount_cmd_machinfo}'")
    endif()
  endif()

  if(NOT count)
    # IRIX (systems with hinv):
    find_program(ProcessorCount_cmd_hinv hinv
      PATHS /sbin)
    if(ProcessorCount_cmd_hinv)
      execute_process(COMMAND ${ProcessorCount_cmd_hinv}
        ERROR_QUIET
        OUTPUT_STRIP_TRAILING_WHITESPACE
        OUTPUT_VARIABLE hinv_output)
      string(REGEX MATCHALL "([0-9]+) .* Processors" procs "${hinv_output}")
      set(count "${CMAKE_MATCH_1}")
      #message("ProcessorCount: trying hinv '${ProcessorCount_cmd_hinv}'")
    endif()
  endif()

  if(NOT count)
    # AIX (systems with lsconf):
    find_program(ProcessorCount_cmd_lsconf lsconf
      PATHS /usr/sbin)
    if(ProcessorCount_cmd_lsconf)
      execute_process(COMMAND ${ProcessorCount_cmd_lsconf}
        ERROR_QUIET
        OUTPUT_STRIP_TRAILING_WHITESPACE
        OUTPUT_VARIABLE lsconf_output)
      string(REGEX MATCHALL "Number Of Processors: ([0-9]+)" procs "${lsconf_output}")
      set(count "${CMAKE_MATCH_1}")
      #message("ProcessorCount: trying lsconf '${ProcessorCount_cmd_lsconf}'")
    endif()
  endif()

  if(NOT count)
    # QNX (systems with pidin):
    find_program(ProcessorCount_cmd_pidin pidin)
    if(ProcessorCount_cmd_pidin)
      execute_process(COMMAND ${ProcessorCount_cmd_pidin} info
        ERROR_QUIET
        OUTPUT_STRIP_TRAILING_WHITESPACE
        OUTPUT_VARIABLE pidin_output)
      string(REGEX MATCHALL "Processor[0-9]+: " procs "${pidin_output}")
      list(LENGTH procs count)
      #message("ProcessorCount: trying pidin '${ProcessorCount_cmd_pidin}'")
    endif()
  endif()

  if(NOT count)
    # Sun (systems where uname -X emits "NumCPU" in its output):
    find_program(ProcessorCount_cmd_uname uname)
    if(ProcessorCount_cmd_uname)
      execute_process(COMMAND ${ProcessorCount_cmd_uname} -X
        ERROR_QUIET
        OUTPUT_STRIP_TRAILING_WHITESPACE
        OUTPUT_VARIABLE uname_X_output)
      string(REGEX MATCHALL "NumCPU = ([0-9]+)" procs "${uname_X_output}")
      set(count "${CMAKE_MATCH_1}")
      #message("ProcessorCount: trying uname -X '${ProcessorCount_cmd_uname}'")
    endif()
  endif()

  # Execute this code when all previously attempted methods return empty
  # output:
  #
  if(NOT count)
    # Systems with /proc/cpuinfo:
    set(cpuinfo_file /proc/cpuinfo)
    if(EXISTS "${cpuinfo_file}")
      file(STRINGS "${cpuinfo_file}" procs REGEX "^processor.: [0-9]+$")
      list(LENGTH procs count)
      #message("ProcessorCount: trying cpuinfo '${cpuinfo_file}'")
    endif()
  endif()

  # Since cygwin builds of CMake do not define WIN32 anymore, but they still
  # run on Windows, and will still have this env var defined:
  #
  if(NOT count)
    set(count "$ENV{NUMBER_OF_PROCESSORS}")
    #message("ProcessorCount: last fallback, trying environment variable")
  endif()

  # Ensure an integer return (avoid inadvertently returning an empty string
  # or an error string)... If it's not a decimal integer, return 0:
  #
  if(NOT count MATCHES "^[0-9]+$")
    set(count 0)
  endif()

  set(${var} ${count} PARENT_SCOPE)
endfunction()

================================================
FILE: README.md
================================================
Additional CMake Modules
========================

Introduction
------------

This is a collection of additional CMake modules.
Most of them are from Ryan Pavlik (<http://academic.cleardefinition.com>).

How to Integrate
----------------

These modules are probably best placed wholesale into a "cmake" subdirectory
of your project source.

If you use Git, try installing [git-subtree][1],
so you can easily use this repository for subtree merges, updating simply.

For the initial checkout:

	cd projectdir

	git subtree add --squash --prefix=cmake git@github.com:bilke/cmake-modules.git master

For updates:

	cd projectdir

	git subtree pull --squash --prefix=cmake git@github.com:bilke/cmake-modules.git master

For pushing to upstream:

	cd projectdir

	git subtree push --prefix=cmake git@github.com:bilke/cmake-modules.git master


How to Use
----------

At the minimum, all you have to do is add a line like this near the top
of your root CMakeLists.txt file (but not before your project() call):

	list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")


Licenses
--------

The modules that are written by Ryan Pavlik are all subject to this license:

> Copyright Iowa State University 2009-2011
>
> Distributed under the Boost Software License, Version 1.0.
>
> (See accompanying file `LICENSE_1_0.txt` or copy at
> <http://www.boost.org/LICENSE_1_0.txt>)

Modules based on those included with CMake as well as modules added by me (Lars
Bilke) are under the OSI-approved **BSD** license, which is included in each of
those modules. A few other modules are modified from other sources - when in
doubt, look at the .cmake.

Important License Note!
-----------------------

If you find this file inside of another project, rather at the top-level
directory, you're in a separate project that is making use of these modules.
That separate project can (and probably does) have its own license specifics.


[1]: http://github.com/apenwarr/git-subtree  "Git Subtree master"


================================================
FILE: ResetConfigurations.cmake
================================================
# - Re-set the available configurations to just RelWithDebInfo, Release, and Debug
#
# Requires these CMake modules:
#  no additional modules required
#
# Original Author:
# 2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#


if(__reset_configurations)
    return()
endif()
set(__reset_configurations YES)

if(CMAKE_CONFIGURATION_TYPES)
    set(CMAKE_CONFIGURATION_TYPES "RelWithDebInfo;Release;Debug")
    set(CMAKE_CONFIGURATION_TYPES
        "${CMAKE_CONFIGURATION_TYPES}"
        CACHE
        STRING
        "Reset the configurations to what we need"
        FORCE)
endif()


================================================
FILE: SetDefaultBuildType.cmake
================================================
# - Set a developer-chosen default build type
#
# Requires these CMake modules:
#  no additional modules required
#
# Original Author:
# 2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#


if(__set_default_build_type)
    return()
endif()
set(__set_default_build_type YES)

function(set_default_build_type _type)
    #if(DEFINED CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE)
    if(("${CMAKE_GENERATOR}" MATCHES "Makefiles" OR "${CMAKE_GENERATOR}" MATCHES "Ninja") AND NOT CMAKE_BUILD_TYPE)
        if(NOT __DEFAULT_BUILD_TYPE_SET)
            set(CMAKE_BUILD_TYPE "${_type}" CACHE STRING "" FORCE)
            set(__DEFAULT_BUILD_TYPE_SET YES CACHE INTERNAL "")
        endif()
    endif()
endfunction()


================================================
FILE: cotire-license
================================================
Copyright (c) 2012-2016 Sascha Kratky

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.


================================================
FILE: cotire.cmake
================================================
# - cotire (compile time reducer)
#
# See the cotire manual for usage hints.
#
#=============================================================================
# Copyright 2012-2018 Sascha Kratky
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#=============================================================================

if(__COTIRE_INCLUDED)
	return()
endif()
set(__COTIRE_INCLUDED TRUE)

# call cmake_minimum_required, but prevent modification of the CMake policy stack in include mode
# cmake_minimum_required also sets the policy version as a side effect, which we have to avoid
if (NOT CMAKE_SCRIPT_MODE_FILE)
	cmake_policy(PUSH)
endif()
cmake_minimum_required(VERSION 2.8.12)
if (NOT CMAKE_SCRIPT_MODE_FILE)
	cmake_policy(POP)
endif()

set (COTIRE_CMAKE_MODULE_FILE "${CMAKE_CURRENT_LIST_FILE}")
set (COTIRE_CMAKE_MODULE_VERSION "1.8.0")

# activate select policies
if (POLICY CMP0025)
	# Compiler id for Apple Clang is now AppleClang
	cmake_policy(SET CMP0025 NEW)
endif()

if (POLICY CMP0026)
	# disallow use of the LOCATION target property
	cmake_policy(SET CMP0026 NEW)
endif()

if (POLICY CMP0038)
	# targets may not link directly to themselves
	cmake_policy(SET CMP0038 NEW)
endif()

if (POLICY CMP0039)
	# utility targets may not have link dependencies
	cmake_policy(SET CMP0039 NEW)
endif()

if (POLICY CMP0040)
	# target in the TARGET signature of add_custom_command() must exist
	cmake_policy(SET CMP0040 NEW)
endif()

if (POLICY CMP0045)
	# error on non-existent target in get_target_property
	cmake_policy(SET CMP0045 NEW)
endif()

if (POLICY CMP0046)
	# error on non-existent dependency in add_dependencies
	cmake_policy(SET CMP0046 NEW)
endif()

if (POLICY CMP0049)
	# do not expand variables in target source entries
	cmake_policy(SET CMP0049 NEW)
endif()

if (POLICY CMP0050)
	# disallow add_custom_command SOURCE signatures
	cmake_policy(SET CMP0050 NEW)
endif()

if (POLICY CMP0051)
	# include TARGET_OBJECTS expressions in a target's SOURCES property
	cmake_policy(SET CMP0051 NEW)
endif()

if (POLICY CMP0053)
	# simplify variable reference and escape sequence evaluation
	cmake_policy(SET CMP0053 NEW)
endif()

if (POLICY CMP0054)
	# only interpret if() arguments as variables or keywords when unquoted
	cmake_policy(SET CMP0054 NEW)
endif()

if (POLICY CMP0055)
	# strict checking for break() command
	cmake_policy(SET CMP0055 NEW)
endif()

include(CMakeParseArguments)
include(ProcessorCount)

function (cotire_get_configuration_types _configsVar)
	set (_configs "")
	if (CMAKE_CONFIGURATION_TYPES)
		list (APPEND _configs ${CMAKE_CONFIGURATION_TYPES})
	endif()
	if (CMAKE_BUILD_TYPE)
		list (APPEND _configs "${CMAKE_BUILD_TYPE}")
	endif()
	if (_configs)
		list (REMOVE_DUPLICATES _configs)
		set (${_configsVar} ${_configs} PARENT_SCOPE)
	else()
		set (${_configsVar} "None" PARENT_SCOPE)
	endif()
endfunction()

function (cotire_get_source_file_extension _sourceFile _extVar)
	# get_filename_component returns extension from first occurrence of . in file name
	# this function computes the extension from last occurrence of . in file name
	string (FIND "${_sourceFile}" "." _index REVERSE)
	if (_index GREATER -1)
		math (EXPR _index "${_index} + 1")
		string (SUBSTRING "${_sourceFile}" ${_index} -1 _sourceExt)
	else()
		set (_sourceExt "")
	endif()
	set (${_extVar} "${_sourceExt}" PARENT_SCOPE)
endfunction()

macro (cotire_check_is_path_relative_to _path _isRelativeVar)
	set (${_isRelativeVar} FALSE)
	if (IS_ABSOLUTE "${_path}")
		foreach (_dir ${ARGN})
			file (RELATIVE_PATH _relPath "${_dir}" "${_path}")
			if (NOT _relPath OR (NOT IS_ABSOLUTE "${_relPath}" AND NOT "${_relPath}" MATCHES "^\\.\\."))
				set (${_isRelativeVar} TRUE)
				break()
			endif()
		endforeach()
	endif()
endmacro()

function (cotire_filter_language_source_files _language _target _sourceFilesVar _excludedSourceFilesVar _cotiredSourceFilesVar)
	if (CMAKE_${_language}_SOURCE_FILE_EXTENSIONS)
		set (_languageExtensions "${CMAKE_${_language}_SOURCE_FILE_EXTENSIONS}")
	else()
		set (_languageExtensions "")
	endif()
	if (CMAKE_${_language}_IGNORE_EXTENSIONS)
		set (_ignoreExtensions "${CMAKE_${_language}_IGNORE_EXTENSIONS}")
	else()
		set (_ignoreExtensions "")
	endif()
	if (COTIRE_UNITY_SOURCE_EXCLUDE_EXTENSIONS)
		set (_excludeExtensions "${COTIRE_UNITY_SOURCE_EXCLUDE_EXTENSIONS}")
	else()
		set (_excludeExtensions "")
	endif()
	if (COTIRE_DEBUG AND _languageExtensions)
		message (STATUS "${_language} source file extensions: ${_languageExtensions}")
	endif()
	if (COTIRE_DEBUG AND _ignoreExtensions)
		message (STATUS "${_language} ignore extensions: ${_ignoreExtensions}")
	endif()
	if (COTIRE_DEBUG AND _excludeExtensions)
		message (STATUS "${_language} exclude extensions: ${_excludeExtensions}")
	endif()
	if (CMAKE_VERSION VERSION_LESS "3.1.0")
		set (_allSourceFiles ${ARGN})
	else()
		# as of CMake 3.1 target sources may contain generator expressions
		# since we cannot obtain required property information about source files added
		# through generator expressions at configure time, we filter them out
		string (GENEX_STRIP "${ARGN}" _allSourceFiles)
	endif()
	set (_filteredSourceFiles "")
	set (_excludedSourceFiles "")
	foreach (_sourceFile ${_allSourceFiles})
		get_source_file_property(_sourceIsHeaderOnly "${_sourceFile}" HEADER_FILE_ONLY)
		get_source_file_property(_sourceIsExternal "${_sourceFile}" EXTERNAL_OBJECT)
		get_source_file_property(_sourceIsSymbolic "${_sourceFile}" SYMBOLIC)
		if (NOT _sourceIsHeaderOnly AND NOT _sourceIsExternal AND NOT _sourceIsSymbolic)
			cotire_get_source_file_extension("${_sourceFile}" _sourceExt)
			if (_sourceExt)
				list (FIND _ignoreExtensions "${_sourceExt}" _ignoreIndex)
				if (_ignoreIndex LESS 0)
					list (FIND _excludeExtensions "${_sourceExt}" _excludeIndex)
					if (_excludeIndex GREATER -1)
						list (APPEND _excludedSourceFiles "${_sourceFile}")
					else()
						list (FIND _languageExtensions "${_sourceExt}" _sourceIndex)
						if (_sourceIndex GREATER -1)
							# consider source file unless it is excluded explicitly
							get_source_file_property(_sourceIsExcluded "${_sourceFile}" COTIRE_EXCLUDED)
							if (_sourceIsExcluded)
								list (APPEND _excludedSourceFiles "${_sourceFile}")
							else()
								list (APPEND _filteredSourceFiles "${_sourceFile}")
							endif()
						else()
							get_source_file_property(_sourceLanguage "${_sourceFile}" LANGUAGE)
							if ("${_sourceLanguage}" STREQUAL "${_language}")
								# add to excluded sources, if file is not ignored and has correct language without having the correct extension
								list (APPEND _excludedSourceFiles "${_sourceFile}")
							endif()
						endif()
					endif()
				endif()
			endif()
		endif()
	endforeach()
	# separate filtered source files from already cotired ones
	# the COTIRE_TARGET property of a source file may be set while a target is being processed by cotire
	set (_sourceFiles "")
	set (_cotiredSourceFiles "")
	foreach (_sourceFile ${_filteredSourceFiles})
		get_source_file_property(_sourceIsCotired "${_sourceFile}" COTIRE_TARGET)
		if (_sourceIsCotired)
			list (APPEND _cotiredSourceFiles "${_sourceFile}")
		else()
			get_source_file_property(_sourceCompileFlags "${_sourceFile}" COMPILE_FLAGS)
			if (_sourceCompileFlags)
				# add to excluded sources, if file has custom compile flags
				list (APPEND _excludedSourceFiles "${_sourceFile}")
			else()
				get_source_file_property(_sourceCompileOptions "${_sourceFile}" COMPILE_OPTIONS)
				if (_sourceCompileOptions)
					# add to excluded sources, if file has list of custom compile options
					list (APPEND _excludedSourceFiles "${_sourceFile}")
				else()
					list (APPEND _sourceFiles "${_sourceFile}")
				endif()
			endif()
		endif()
	endforeach()
	if (COTIRE_DEBUG)
		if (_sourceFiles)
			message (STATUS "Filtered ${_target} ${_language} sources: ${_sourceFiles}")
		endif()
		if (_excludedSourceFiles)
			message (STATUS "Excluded ${_target} ${_language} sources: ${_excludedSourceFiles}")
		endif()
		if (_cotiredSourceFiles)
			message (STATUS "Cotired ${_target} ${_language} sources: ${_cotiredSourceFiles}")
		endif()
	endif()
	set (${_sourceFilesVar} ${_sourceFiles} PARENT_SCOPE)
	set (${_excludedSourceFilesVar} ${_excludedSourceFiles} PARENT_SCOPE)
	set (${_cotiredSourceFilesVar} ${_cotiredSourceFiles} PARENT_SCOPE)
endfunction()

function (cotire_get_objects_with_property_on _filteredObjectsVar _property _type)
	set (_filteredObjects "")
	foreach (_object ${ARGN})
		get_property(_isSet ${_type} "${_object}" PROPERTY ${_property} SET)
		if (_isSet)
			get_property(_propertyValue ${_type} "${_object}" PROPERTY ${_property})
			if (_propertyValue)
				list (APPEND _filteredObjects "${_object}")
			endif()
		endif()
	endforeach()
	set (${_filteredObjectsVar} ${_filteredObjects} PARENT_SCOPE)
endfunction()

function (cotire_get_objects_with_property_off _filteredObjectsVar _property _type)
	set (_filteredObjects "")
	foreach (_object ${ARGN})
		get_property(_isSet ${_type} "${_object}" PROPERTY ${_property} SET)
		if (_isSet)
			get_property(_propertyValue ${_type} "${_object}" PROPERTY ${_property})
			if (NOT _propertyValue)
				list (APPEND _filteredObjects "${_object}")
			endif()
		endif()
	endforeach()
	set (${_filteredObjectsVar} ${_filteredObjects} PARENT_SCOPE)
endfunction()

function (cotire_get_source_file_property_values _valuesVar _property)
	set (_values "")
	foreach (_sourceFile ${ARGN})
		get_source_file_property(_propertyValue "${_sourceFile}" ${_property})
		if (_propertyValue)
			list (APPEND _values "${_propertyValue}")
		endif()
	endforeach()
	set (${_valuesVar} ${_values} PARENT_SCOPE)
endfunction()

function (cotire_resolve_config_properties _configurations _propertiesVar)
	set (_properties "")
	foreach (_property ${ARGN})
		if ("${_property}" MATCHES "<CONFIG>")
			foreach (_config ${_configurations})
				string (TOUPPER "${_config}" _upperConfig)
				string (REPLACE "<CONFIG>" "${_upperConfig}" _configProperty "${_property}")
				list (APPEND _properties ${_configProperty})
			endforeach()
		else()
			list (APPEND _properties ${_property})
		endif()
	endforeach()
	set (${_propertiesVar} ${_properties} PARENT_SCOPE)
endfunction()

function (cotire_copy_set_properties _configurations _type _source _target)
	cotire_resolve_config_properties("${_configurations}" _properties ${ARGN})
	foreach (_property ${_properties})
		get_property(_isSet ${_type} ${_source} PROPERTY ${_property} SET)
		if (_isSet)
			get_property(_propertyValue ${_type} ${_source} PROPERTY ${_property})
			set_property(${_type} ${_target} PROPERTY ${_property} "${_propertyValue}")
		endif()
	endforeach()
endfunction()

function (cotire_get_target_usage_requirements _target _config _targetRequirementsVar)
	set (_targetRequirements "")
	get_target_property(_librariesToProcess ${_target} LINK_LIBRARIES)
	while (_librariesToProcess)
		# remove from head
		list (GET _librariesToProcess 0 _library)
		list (REMOVE_AT _librariesToProcess 0)
		if (_library MATCHES "^\\$<\\$<CONFIG:${_config}>:([A-Za-z0-9_:-]+)>$")
			set (_library "${CMAKE_MATCH_1}")
		elseif (_config STREQUAL "None" AND _library MATCHES "^\\$<\\$<CONFIG:>:([A-Za-z0-9_:-]+)>$")
			set (_library "${CMAKE_MATCH_1}")
		endif()
		if (TARGET ${_library})
			list (FIND _targetRequirements ${_library} _index)
			if (_index LESS 0)
				list (APPEND _targetRequirements ${_library})
				# BFS traversal of transitive libraries
				get_target_property(_libraries ${_library} INTERFACE_LINK_LIBRARIES)
				if (_libraries)
					list (APPEND _librariesToProcess ${_libraries})
					list (REMOVE_DUPLICATES _librariesToProcess)
				endif()
			endif()
		endif()
	endwhile()
	set (${_targetRequirementsVar} ${_targetRequirements} PARENT_SCOPE)
endfunction()

function (cotire_filter_compile_flags _language _flagFilter _matchedOptionsVar _unmatchedOptionsVar)
	if (WIN32 AND CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
		set (_flagPrefix "[/-]")
	else()
		set (_flagPrefix "--?")
	endif()
	set (_optionFlag "")
	set (_matchedOptions "")
	set (_unmatchedOptions "")
	foreach (_compileFlag ${ARGN})
		if (_compileFlag)
			if (_optionFlag AND NOT "${_compileFlag}" MATCHES "^${_flagPrefix}")
				# option with separate argument
				list (APPEND _matchedOptions "${_compileFlag}")
				set (_optionFlag "")
			elseif ("${_compileFlag}" MATCHES "^(${_flagPrefix})(${_flagFilter})$")
				# remember option
				set (_optionFlag "${CMAKE_MATCH_2}")
			elseif ("${_compileFlag}" MATCHES "^(${_flagPrefix})(${_flagFilter})(.+)$")
				# option with joined argument
				list (APPEND _matchedOptions "${CMAKE_MATCH_3}")
				set (_optionFlag "")
			else()
				# flush remembered option
				if (_optionFlag)
					list (APPEND _matchedOptions "${_optionFlag}")
					set (_optionFlag "")
				endif()
				# add to unfiltered options
				list (APPEND _unmatchedOptions "${_compileFlag}")
			endif()
		endif()
	endforeach()
	if (_optionFlag)
		list (APPEND _matchedOptions "${_optionFlag}")
	endif()
	if (COTIRE_DEBUG AND _matchedOptions)
		message (STATUS "Filter ${_flagFilter} matched: ${_matchedOptions}")
	endif()
	if (COTIRE_DEBUG AND _unmatchedOptions)
		message (STATUS "Filter ${_flagFilter} unmatched: ${_unmatchedOptions}")
	endif()
	set (${_matchedOptionsVar} ${_matchedOptions} PARENT_SCOPE)
	set (${_unmatchedOptionsVar} ${_unmatchedOptions} PARENT_SCOPE)
endfunction()

function (cotire_is_target_supported _target _isSupportedVar)
	if (NOT TARGET "${_target}")
		set (${_isSupportedVar} FALSE PARENT_SCOPE)
		return()
	endif()
	get_target_property(_imported ${_target} IMPORTED)
	if (_imported)
		set (${_isSupportedVar} FALSE PARENT_SCOPE)
		return()
	endif()
	get_target_property(_targetType ${_target} TYPE)
	if (NOT _targetType MATCHES "EXECUTABLE|(STATIC|SHARED|MODULE|OBJECT)_LIBRARY")
		set (${_isSupportedVar} FALSE PARENT_SCOPE)
		return()
	endif()
	set (${_isSupportedVar} TRUE PARENT_SCOPE)
endfunction()

function (cotire_get_target_compile_flags _config _language _target _flagsVar)
	string (TOUPPER "${_config}" _upperConfig)
	# collect options from CMake language variables
	set (_compileFlags "")
	if (CMAKE_${_language}_FLAGS)
		set (_compileFlags "${_compileFlags} ${CMAKE_${_language}_FLAGS}")
	endif()
	if (CMAKE_${_language}_FLAGS_${_upperConfig})
		set (_compileFlags "${_compileFlags} ${CMAKE_${_language}_FLAGS_${_upperConfig}}")
	endif()
	if (_target)
		# add target compile flags
		get_target_property(_targetflags ${_target} COMPILE_FLAGS)
		if (_targetflags)
			set (_compileFlags "${_compileFlags} ${_targetflags}")
		endif()
	endif()
	if (UNIX)
		separate_arguments(_compileFlags UNIX_COMMAND "${_compileFlags}")
	elseif(WIN32)
		separate_arguments(_compileFlags WINDOWS_COMMAND "${_compileFlags}")
	else()
		separate_arguments(_compileFlags)
	endif()
	# target compile options
	if (_target)
		get_target_property(_targetOptions ${_target} COMPILE_OPTIONS)
		if (_targetOptions)
			list (APPEND _compileFlags ${_targetOptions})
		endif()
	endif()
	# interface compile options from linked library targets
	if (_target)
		set (_linkedTargets "")
		cotire_get_target_usage_requirements(${_target} ${_config} _linkedTargets)
		foreach (_linkedTarget ${_linkedTargets})
			get_target_property(_targetOptions ${_linkedTarget} INTERFACE_COMPILE_OPTIONS)
			if (_targetOptions)
				list (APPEND _compileFlags ${_targetOptions})
			endif()
		endforeach()
	endif()
	# handle language standard properties
	if (CMAKE_${_language}_STANDARD_DEFAULT)
		# used compiler supports language standard levels
		if (_target)
			get_target_property(_targetLanguageStandard ${_target} ${_language}_STANDARD)
			if (_targetLanguageStandard)
				set (_type "EXTENSION")
				get_property(_isSet TARGET ${_target} PROPERTY ${_language}_EXTENSIONS SET)
				if (_isSet)
					get_target_property(_targetUseLanguageExtensions ${_target} ${_language}_EXTENSIONS)
					if (NOT _targetUseLanguageExtensions)
						set (_type "STANDARD")
					endif()
				endif()
				if (CMAKE_${_language}${_targetLanguageStandard}_${_type}_COMPILE_OPTION)
					list (APPEND _compileFlags "${CMAKE_${_language}${_targetLanguageStandard}_${_type}_COMPILE_OPTION}")
				endif()
			endif()
		endif()
	endif()
	# handle the POSITION_INDEPENDENT_CODE target property
	if (_target)
		get_target_property(_targetPIC ${_target} POSITION_INDEPENDENT_CODE)
		if (_targetPIC)
			get_target_property(_targetType ${_target} TYPE)
			if (_targetType STREQUAL "EXECUTABLE" AND CMAKE_${_language}_COMPILE_OPTIONS_PIE)
				list (APPEND _compileFlags "${CMAKE_${_language}_COMPILE_OPTIONS_PIE}")
			elseif (CMAKE_${_language}_COMPILE_OPTIONS_PIC)
				list (APPEND _compileFlags "${CMAKE_${_language}_COMPILE_OPTIONS_PIC}")
			endif()
		endif()
	endif()
	# handle visibility target properties
	if (_target)
		get_target_property(_targetVisibility ${_target} ${_language}_VISIBILITY_PRESET)
		if (_targetVisibility AND CMAKE_${_language}_COMPILE_OPTIONS_VISIBILITY)
			list (APPEND _compileFlags "${CMAKE_${_language}_COMPILE_OPTIONS_VISIBILITY}${_targetVisibility}")
		endif()
		get_target_property(_targetVisibilityInlines ${_target} VISIBILITY_INLINES_HIDDEN)
		if (_targetVisibilityInlines AND CMAKE_${_language}_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN)
			list (APPEND _compileFlags "${CMAKE_${_language}_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN}")
		endif()
	endif()
	# platform specific flags
	if (APPLE)
		get_target_property(_architectures ${_target} OSX_ARCHITECTURES_${_upperConfig})
		if (NOT _architectures)
			get_target_property(_architectures ${_target} OSX_ARCHITECTURES)
		endif()
		if (_architectures)
			foreach (_arch ${_architectures})
				list (APPEND _compileFlags "-arch" "${_arch}")
			endforeach()
		endif()
		if (CMAKE_OSX_SYSROOT)
			if (CMAKE_${_language}_SYSROOT_FLAG)
				list (APPEND _compileFlags "${CMAKE_${_language}_SYSROOT_FLAG}" "${CMAKE_OSX_SYSROOT}")
			else()
				list (APPEND _compileFlags "-isysroot" "${CMAKE_OSX_SYSROOT}")
			endif()
		endif()
		if (CMAKE_OSX_DEPLOYMENT_TARGET)
			if (CMAKE_${_language}_OSX_DEPLOYMENT_TARGET_FLAG)
				list (APPEND _compileFlags "${CMAKE_${_language}_OSX_DEPLOYMENT_TARGET_FLAG}${CMAKE_OSX_DEPLOYMENT_TARGET}")
			else()
				list (APPEND _compileFlags "-mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
			endif()
		endif()
	endif()
	if (COTIRE_DEBUG AND _compileFlags)
		message (STATUS "Target ${_target} compile flags: ${_compileFlags}")
	endif()
	set (${_flagsVar} ${_compileFlags} PARENT_SCOPE)
endfunction()

function (cotire_get_target_include_directories _config _language _target _includeDirsVar _systemIncludeDirsVar)
	set (_includeDirs "")
	set (_systemIncludeDirs "")
	# default include dirs
	if (CMAKE_INCLUDE_CURRENT_DIR)
		list (APPEND _includeDirs "${CMAKE_CURRENT_BINARY_DIR}")
		list (APPEND _includeDirs "${CMAKE_CURRENT_SOURCE_DIR}")
	endif()
	set (_targetFlags "")
	cotire_get_target_compile_flags("${_config}" "${_language}" "${_target}" _targetFlags)
	# parse additional include directories from target compile flags
	if (CMAKE_INCLUDE_FLAG_${_language})
		string (STRIP "${CMAKE_INCLUDE_FLAG_${_language}}" _includeFlag)
		string (REGEX REPLACE "^[-/]+" "" _includeFlag "${_includeFlag}")
		if (_includeFlag)
			set (_dirs "")
			cotire_filter_compile_flags("${_language}" "${_includeFlag}" _dirs _ignore ${_targetFlags})
			if (_dirs)
				list (APPEND _includeDirs ${_dirs})
			endif()
		endif()
	endif()
	# parse additional system include directories from target compile flags
	if (CMAKE_INCLUDE_SYSTEM_FLAG_${_language})
		string (STRIP "${CMAKE_INCLUDE_SYSTEM_FLAG_${_language}}" _includeFlag)
		string (REGEX REPLACE "^[-/]+" "" _includeFlag "${_includeFlag}")
		if (_includeFlag)
			set (_dirs "")
			cotire_filter_compile_flags("${_language}" "${_includeFlag}" _dirs _ignore ${_targetFlags})
			if (_dirs)
				list (APPEND _systemIncludeDirs ${_dirs})
			endif()
		endif()
	endif()
	# target include directories
	get_directory_property(_dirs DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" INCLUDE_DIRECTORIES)
	if (_target)
		get_target_property(_targetDirs ${_target} INCLUDE_DIRECTORIES)
		if (_targetDirs)
			list (APPEND _dirs ${_targetDirs})
		endif()
		get_target_property(_targetDirs ${_target} INTERFACE_SYSTEM_INCLUDE_DIRECTORIES)
		if (_targetDirs)
			list (APPEND _systemIncludeDirs ${_targetDirs})
		endif()
	endif()
	# interface include directories from linked library targets
	if (_target)
		set (_linkedTargets "")
		cotire_get_target_usage_requirements(${_target} ${_config} _linkedTargets)
		foreach (_linkedTarget ${_linkedTargets})
			get_target_property(_linkedTargetType ${_linkedTarget} TYPE)
			if (CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE AND NOT CMAKE_VERSION VERSION_LESS "3.4.0" AND
				_linkedTargetType MATCHES "(STATIC|SHARED|MODULE|OBJECT)_LIBRARY")
				# CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE refers to CMAKE_CURRENT_BINARY_DIR and CMAKE_CURRENT_SOURCE_DIR
				# at the time, when the target was created. These correspond to the target properties BINARY_DIR and SOURCE_DIR
				# which are only available with CMake 3.4 or later.
				get_target_property(_targetDirs ${_linkedTarget} BINARY_DIR)
				if (_targetDirs)
					list (APPEND _dirs ${_targetDirs})
				endif()
				get_target_property(_targetDirs ${_linkedTarget} SOURCE_DIR)
				if (_targetDirs)
					list (APPEND _dirs ${_targetDirs})
				endif()
			endif()
			get_target_property(_targetDirs ${_linkedTarget} INTERFACE_INCLUDE_DIRECTORIES)
			if (_targetDirs)
				list (APPEND _dirs ${_targetDirs})
			endif()
			get_target_property(_targetDirs ${_linkedTarget} INTERFACE_SYSTEM_INCLUDE_DIRECTORIES)
			if (_targetDirs)
				list (APPEND _systemIncludeDirs ${_targetDirs})
			endif()
		endforeach()
	endif()
	if (dirs)
		list (REMOVE_DUPLICATES _dirs)
	endif()
	list (LENGTH _includeDirs _projectInsertIndex)
	foreach (_dir ${_dirs})
		if (CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE)
			cotire_check_is_path_relative_to("${_dir}" _isRelative "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}")
			if (_isRelative)
				list (LENGTH _includeDirs _len)
				if (_len EQUAL _projectInsertIndex)
					list (APPEND _includeDirs "${_dir}")
				else()
					list (INSERT _includeDirs _projectInsertIndex "${_dir}")
				endif()
				math (EXPR _projectInsertIndex "${_projectInsertIndex} + 1")
			else()
				list (APPEND _includeDirs "${_dir}")
			endif()
		else()
			list (APPEND _includeDirs "${_dir}")
		endif()
	endforeach()
	list (REMOVE_DUPLICATES _includeDirs)
	list (REMOVE_DUPLICATES _systemIncludeDirs)
	if (CMAKE_${_language}_IMPLICIT_INCLUDE_DIRECTORIES)
		list (REMOVE_ITEM _includeDirs ${CMAKE_${_language}_IMPLICIT_INCLUDE_DIRECTORIES})
	endif()
	if (WIN32 AND NOT MINGW)
		# convert Windows paths in include directories to CMake paths
		if (_includeDirs)
			set (_paths "")
			foreach (_dir ${_includeDirs})
				file (TO_CMAKE_PATH "${_dir}" _path)
				list (APPEND _paths "${_path}")
			endforeach()
			set (_includeDirs ${_paths})
		endif()
		if (_systemIncludeDirs)
			set (_paths "")
			foreach (_dir ${_systemIncludeDirs})
				file (TO_CMAKE_PATH "${_dir}" _path)
				list (APPEND _paths "${_path}")
			endforeach()
			set (_systemIncludeDirs ${_paths})
		endif()
	endif()
	if (COTIRE_DEBUG AND _includeDirs)
		message (STATUS "Target ${_target} include dirs: ${_includeDirs}")
	endif()
	set (${_includeDirsVar} ${_includeDirs} PARENT_SCOPE)
	if (COTIRE_DEBUG AND _systemIncludeDirs)
		message (STATUS "Target ${_target} system include dirs: ${_systemIncludeDirs}")
	endif()
	set (${_systemIncludeDirsVar} ${_systemIncludeDirs} PARENT_SCOPE)
endfunction()

function (cotire_get_target_export_symbol _target _exportSymbolVar)
	set (_exportSymbol "")
	get_target_property(_targetType ${_target} TYPE)
	get_target_property(_enableExports ${_target} ENABLE_EXPORTS)
	if (_targetType MATCHES "(SHARED|MODULE)_LIBRARY" OR
		(_targetType STREQUAL "EXECUTABLE" AND _enableExports))
		get_target_property(_exportSymbol ${_target} DEFINE_SYMBOL)
		if (NOT _exportSymbol)
			set (_exportSymbol "${_target}_EXPORTS")
		endif()
		string (MAKE_C_IDENTIFIER "${_exportSymbol}" _exportSymbol)
	endif()
	set (${_exportSymbolVar} ${_exportSymbol} PARENT_SCOPE)
endfunction()

function (cotire_get_target_compile_definitions _config _language _target _definitionsVar)
	string (TOUPPER "${_config}" _upperConfig)
	set (_configDefinitions "")
	# CMAKE_INTDIR for multi-configuration build systems
	if (NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".")
		list (APPEND _configDefinitions "CMAKE_INTDIR=\"${_config}\"")
	endif()
	# target export define symbol
	cotire_get_target_export_symbol("${_target}" _defineSymbol)
	if (_defineSymbol)
		list (APPEND _configDefinitions "${_defineSymbol}")
	endif()
	# directory compile definitions
	get_directory_property(_definitions DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" COMPILE_DEFINITIONS)
	if (_definitions)
		list (APPEND _configDefinitions ${_definitions})
	endif()
	get_directory_property(_definitions DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" COMPILE_DEFINITIONS_${_upperConfig})
	if (_definitions)
		list (APPEND _configDefinitions ${_definitions})
	endif()
	# target compile definitions
	get_target_property(_definitions ${_target} COMPILE_DEFINITIONS)
	if (_definitions)
		list (APPEND _configDefinitions ${_definitions})
	endif()
	get_target_property(_definitions ${_target} COMPILE_DEFINITIONS_${_upperConfig})
	if (_definitions)
		list (APPEND _configDefinitions ${_definitions})
	endif()
	# interface compile definitions from linked library targets
	set (_linkedTargets "")
	cotire_get_target_usage_requirements(${_target} ${_config} _linkedTargets)
	foreach (_linkedTarget ${_linkedTargets})
		get_target_property(_definitions ${_linkedTarget} INTERFACE_COMPILE_DEFINITIONS)
		if (_definitions)
			list (APPEND _configDefinitions ${_definitions})
		endif()
	endforeach()
	# parse additional compile definitions from target compile flags
	# and do not look at directory compile definitions, which we already handled
	set (_targetFlags "")
	cotire_get_target_compile_flags("${_config}" "${_language}" "${_target}" _targetFlags)
	cotire_filter_compile_flags("${_language}" "D" _definitions _ignore ${_targetFlags})
	if (_definitions)
		list (APPEND _configDefinitions ${_definitions})
	endif()
	list (REMOVE_DUPLICATES _configDefinitions)
	if (COTIRE_DEBUG AND _configDefinitions)
		message (STATUS "Target ${_target} compile definitions: ${_configDefinitions}")
	endif()
	set (${_definitionsVar} ${_configDefinitions} PARENT_SCOPE)
endfunction()

function (cotire_get_target_compiler_flags _config _language _target _compilerFlagsVar)
	# parse target compile flags omitting compile definitions and include directives
	set (_targetFlags "")
	cotire_get_target_compile_flags("${_config}" "${_language}" "${_target}" _targetFlags)
	set (_flagFilter "D")
	if (CMAKE_INCLUDE_FLAG_${_language})
		string (STRIP "${CMAKE_INCLUDE_FLAG_${_language}}" _includeFlag)
		string (REGEX REPLACE "^[-/]+" "" _includeFlag "${_includeFlag}")
		if (_includeFlag)
			set (_flagFilter "${_flagFilter}|${_includeFlag}")
		endif()
	endif()
	if (CMAKE_INCLUDE_SYSTEM_FLAG_${_language})
		string (STRIP "${CMAKE_INCLUDE_SYSTEM_FLAG_${_language}}" _includeFlag)
		string (REGEX REPLACE "^[-/]+" "" _includeFlag "${_includeFlag}")
		if (_includeFlag)
			set (_flagFilter "${_flagFilter}|${_includeFlag}")
		endif()
	endif()
	set (_compilerFlags "")
	cotire_filter_compile_flags("${_language}" "${_flagFilter}" _ignore _compilerFlags ${_targetFlags})
	if (COTIRE_DEBUG AND _compilerFlags)
		message (STATUS "Target ${_target} compiler flags: ${_compilerFlags}")
	endif()
	set (${_compilerFlagsVar} ${_compilerFlags} PARENT_SCOPE)
endfunction()

function (cotire_add_sys_root_paths _pathsVar)
	if (APPLE)
		if (CMAKE_OSX_SYSROOT AND CMAKE_${_language}_HAS_ISYSROOT)
			foreach (_path IN LISTS ${_pathsVar})
				if (IS_ABSOLUTE "${_path}")
					get_filename_component(_path "${CMAKE_OSX_SYSROOT}/${_path}" ABSOLUTE)
					if (EXISTS "${_path}")
						list (APPEND ${_pathsVar} "${_path}")
					endif()
				endif()
			endforeach()
		endif()
	endif()
	set (${_pathsVar} ${${_pathsVar}} PARENT_SCOPE)
endfunction()

function (cotire_get_source_extra_properties _sourceFile _pattern _resultVar)
	set (_extraProperties ${ARGN})
	set (_result "")
	if (_extraProperties)
		list (FIND _extraProperties "${_sourceFile}" _index)
		if (_index GREATER -1)
			math (EXPR _index "${_index} + 1")
			list (LENGTH _extraProperties _len)
			math (EXPR _len "${_len} - 1")
			foreach (_index RANGE ${_index} ${_len})
				list (GET _extraProperties ${_index} _value)
				if (_value MATCHES "${_pattern}")
					list (APPEND _result "${_value}")
				else()
					break()
				endif()
			endforeach()
		endif()
	endif()
	set (${_resultVar} ${_result} PARENT_SCOPE)
endfunction()

function (cotire_get_source_compile_definitions _config _language _sourceFile _definitionsVar)
	set (_compileDefinitions "")
	if (NOT CMAKE_SCRIPT_MODE_FILE)
		string (TOUPPER "${_config}" _upperConfig)
		get_source_file_property(_definitions "${_sourceFile}" COMPILE_DEFINITIONS)
		if (_definitions)
			list (APPEND _compileDefinitions ${_definitions})
		endif()
		get_source_file_property(_definitions "${_sourceFile}" COMPILE_DEFINITIONS_${_upperConfig})
		if (_definitions)
			list (APPEND _compileDefinitions ${_definitions})
		endif()
	endif()
	cotire_get_source_extra_properties("${_sourceFile}" "^[a-zA-Z0-9_]+(=.*)?$" _definitions ${ARGN})
	if (_definitions)
		list (APPEND _compileDefinitions ${_definitions})
	endif()
	if (COTIRE_DEBUG AND _compileDefinitions)
		message (STATUS "Source ${_sourceFile} compile definitions: ${_compileDefinitions}")
	endif()
	set (${_definitionsVar} ${_compileDefinitions} PARENT_SCOPE)
endfunction()

function (cotire_get_source_files_compile_definitions _config _language _definitionsVar)
	set (_configDefinitions "")
	foreach (_sourceFile ${ARGN})
		cotire_get_source_compile_definitions("${_config}" "${_language}" "${_sourceFile}" _sourceDefinitions)
		if (_sourceDefinitions)
			list (APPEND _configDefinitions "${_sourceFile}" ${_sourceDefinitions} "-")
		endif()
	endforeach()
	set (${_definitionsVar} ${_configDefinitions} PARENT_SCOPE)
endfunction()

function (cotire_get_source_undefs _sourceFile _property _sourceUndefsVar)
	set (_sourceUndefs "")
	if (NOT CMAKE_SCRIPT_MODE_FILE)
		get_source_file_property(_undefs "${_sourceFile}" ${_property})
		if (_undefs)
			list (APPEND _sourceUndefs ${_undefs})
		endif()
	endif()
	cotire_get_source_extra_properties("${_sourceFile}" "^[a-zA-Z0-9_]+$" _undefs ${ARGN})
	if (_undefs)
		list (APPEND _sourceUndefs ${_undefs})
	endif()
	if (COTIRE_DEBUG AND _sourceUndefs)
		message (STATUS "Source ${_sourceFile} ${_property} undefs: ${_sourceUndefs}")
	endif()
	set (${_sourceUndefsVar} ${_sourceUndefs} PARENT_SCOPE)
endfunction()

function (cotire_get_source_files_undefs _property _sourceUndefsVar)
	set (_sourceUndefs "")
	foreach (_sourceFile ${ARGN})
		cotire_get_source_undefs("${_sourceFile}" ${_property} _undefs)
		if (_undefs)
			list (APPEND _sourceUndefs "${_sourceFile}" ${_undefs} "-")
		endif()
	endforeach()
	set (${_sourceUndefsVar} ${_sourceUndefs} PARENT_SCOPE)
endfunction()

macro (cotire_set_cmd_to_prologue _cmdVar)
	set (${_cmdVar} "${CMAKE_COMMAND}")
	if (COTIRE_DEBUG)
		list (APPEND ${_cmdVar} "--warn-uninitialized")
	endif()
	list (APPEND ${_cmdVar} "-DCOTIRE_BUILD_TYPE:STRING=$<CONFIGURATION>")
	if (XCODE)
		list (APPEND ${_cmdVar} "-DXCODE:BOOL=TRUE")
	endif()
	if (COTIRE_VERBOSE)
		list (APPEND ${_cmdVar} "-DCOTIRE_VERBOSE:BOOL=ON")
	elseif("${CMAKE_GENERATOR}" MATCHES "Makefiles")
		list (APPEND ${_cmdVar} "-DCOTIRE_VERBOSE:BOOL=$(VERBOSE)")
	endif()
endmacro()

function (cotire_init_compile_cmd _cmdVar _language _compilerLauncher _compilerExe _compilerArg1)
	if (NOT _compilerLauncher)
		set (_compilerLauncher ${CMAKE_${_language}_COMPILER_LAUNCHER})
	endif()
	if (NOT _compilerExe)
		set (_compilerExe "${CMAKE_${_language}_COMPILER}")
	endif()
	if (NOT _compilerArg1)
		set (_compilerArg1 ${CMAKE_${_language}_COMPILER_ARG1})
	endif()
	if (WIN32)
		file (TO_NATIVE_PATH "${_compilerExe}" _compilerExe)
	endif()
	string (STRIP "${_compilerArg1}" _compilerArg1)
	if ("${CMAKE_GENERATOR}" MATCHES "Make|Ninja")
		# compiler launcher is only supported for Makefile and Ninja
		set (${_cmdVar} ${_compilerLauncher} "${_compilerExe}" ${_compilerArg1} PARENT_SCOPE)
	else()
		set (${_cmdVar} "${_compilerExe}" ${_compilerArg1} PARENT_SCOPE)
	endif()
endfunction()

macro (cotire_add_definitions_to_cmd _cmdVar _language)
	foreach (_definition ${ARGN})
		if (WIN32 AND CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
			list (APPEND ${_cmdVar} "/D${_definition}")
		else()
			list (APPEND ${_cmdVar} "-D${_definition}")
		endif()
	endforeach()
endmacro()

function (cotire_add_includes_to_cmd _cmdVar _language _includesVar _systemIncludesVar)
	set (_includeDirs ${${_includesVar}} ${${_systemIncludesVar}})
	if (_includeDirs)
		list (REMOVE_DUPLICATES _includeDirs)
		foreach (_include ${_includeDirs})
			if (WIN32 AND CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
				file (TO_NATIVE_PATH "${_include}" _include)
				list (APPEND ${_cmdVar} "${CMAKE_INCLUDE_FLAG_${_language}}${CMAKE_INCLUDE_FLAG_SEP_${_language}}${_include}")
			else()
				set (_index -1)
				if ("${CMAKE_INCLUDE_SYSTEM_FLAG_${_language}}" MATCHES ".+")
					list (FIND ${_systemIncludesVar} "${_include}" _index)
				endif()
				if (_index GREATER -1)
					list (APPEND ${_cmdVar} "${CMAKE_INCLUDE_SYSTEM_FLAG_${_language}}${CMAKE_INCLUDE_FLAG_SEP_${_language}}${_include}")
				else()
					list (APPEND ${_cmdVar} "${CMAKE_INCLUDE_FLAG_${_language}}${CMAKE_INCLUDE_FLAG_SEP_${_language}}${_include}")
				endif()
			endif()
		endforeach()
	endif()
	set (${_cmdVar} ${${_cmdVar}} PARENT_SCOPE)
endfunction()

function (cotire_add_frameworks_to_cmd _cmdVar _language _includesVar _systemIncludesVar)
	if (APPLE)
		set (_frameworkDirs "")
		foreach (_include ${${_includesVar}})
			if (IS_ABSOLUTE "${_include}" AND _include MATCHES "\\.framework$")
				get_filename_component(_frameworkDir "${_include}" DIRECTORY)
				list (APPEND _frameworkDirs "${_frameworkDir}")
			endif()
		endforeach()
		set (_systemFrameworkDirs "")
		foreach (_include ${${_systemIncludesVar}})
			if (IS_ABSOLUTE "${_include}" AND _include MATCHES "\\.framework$")
				get_filename_component(_frameworkDir "${_include}" DIRECTORY)
				list (APPEND _systemFrameworkDirs "${_frameworkDir}")
			endif()
		endforeach()
		if (_systemFrameworkDirs)
			list (APPEND _frameworkDirs ${_systemFrameworkDirs})
		endif()
		if (_frameworkDirs)
			list (REMOVE_DUPLICATES _frameworkDirs)
			foreach (_frameworkDir ${_frameworkDirs})
				set (_index -1)
				if ("${CMAKE_${_language}_SYSTEM_FRAMEWORK_SEARCH_FLAG}" MATCHES ".+")
					list (FIND _systemFrameworkDirs "${_frameworkDir}" _index)
				endif()
				if (_index GREATER -1)
					list (APPEND ${_cmdVar} "${CMAKE_${_language}_SYSTEM_FRAMEWORK_SEARCH_FLAG}${_frameworkDir}")
				else()
					list (APPEND ${_cmdVar} "${CMAKE_${_language}_FRAMEWORK_SEARCH_FLAG}${_frameworkDir}")
				endif()
			endforeach()
		endif()
	endif()
	set (${_cmdVar} ${${_cmdVar}} PARENT_SCOPE)
endfunction()

macro (cotire_add_compile_flags_to_cmd _cmdVar)
	foreach (_flag ${ARGN})
		list (APPEND ${_cmdVar} "${_flag}")
	endforeach()
endmacro()

function (cotire_check_file_up_to_date _fileIsUpToDateVar _file)
	if (EXISTS "${_file}")
		set (_triggerFile "")
		foreach (_dependencyFile ${ARGN})
			if (EXISTS "${_dependencyFile}")
				# IS_NEWER_THAN returns TRUE if both files have the same timestamp
				# thus we do the comparison in both directions to exclude ties
				if ("${_dependencyFile}" IS_NEWER_THAN "${_file}" AND
					NOT "${_file}" IS_NEWER_THAN "${_dependencyFile}")
					set (_triggerFile "${_dependencyFile}")
					break()
				endif()
			endif()
		endforeach()
		if (_triggerFile)
			if (COTIRE_VERBOSE)
				get_filename_component(_fileName "${_file}" NAME)
				message (STATUS "${_fileName} update triggered by ${_triggerFile} change.")
			endif()
			set (${_fileIsUpToDateVar} FALSE PARENT_SCOPE)
		else()
			if (COTIRE_VERBOSE)
				get_filename_component(_fileName "${_file}" NAME)
				message (STATUS "${_fileName} is up-to-date.")
			endif()
			set (${_fileIsUpToDateVar} TRUE PARENT_SCOPE)
		endif()
	else()
		if (COTIRE_VERBOSE)
			get_filename_component(_fileName "${_file}" NAME)
			message (STATUS "${_fileName} does not exist yet.")
		endif()
		set (${_fileIsUpToDateVar} FALSE PARENT_SCOPE)
	endif()
endfunction()

macro (cotire_find_closest_relative_path _headerFile _includeDirs _relPathVar)
	set (${_relPathVar} "")
	foreach (_includeDir ${_includeDirs})
		if (IS_DIRECTORY "${_includeDir}")
			file (RELATIVE_PATH _relPath "${_includeDir}" "${_headerFile}")
			if (NOT IS_ABSOLUTE "${_relPath}" AND NOT "${_relPath}" MATCHES "^\\.\\.")
				string (LENGTH "${${_relPathVar}}" _closestLen)
				string (LENGTH "${_relPath}" _relLen)
				if (_closestLen EQUAL 0 OR _relLen LESS _closestLen)
					set (${_relPathVar} "${_relPath}")
				endif()
			endif()
		elseif ("${_includeDir}" STREQUAL "${_headerFile}")
			# if path matches exactly, return short non-empty string
			set (${_relPathVar} "1")
			break()
		endif()
	endforeach()
endmacro()

macro (cotire_check_header_file_location _headerFile _insideIncludeDirs _outsideIncludeDirs _headerIsInside)
	# check header path against ignored and honored include directories
	cotire_find_closest_relative_path("${_headerFile}" "${_insideIncludeDirs}" _insideRelPath)
	if (_insideRelPath)
		# header is inside, but could be become outside if there is a shorter outside match
		cotire_find_closest_relative_path("${_headerFile}" "${_outsideIncludeDirs}" _outsideRelPath)
		if (_outsideRelPath)
			string (LENGTH "${_insideRelPath}" _insideRelPathLen)
			string (LENGTH "${_outsideRelPath}" _outsideRelPathLen)
			if (_outsideRelPathLen LESS _insideRelPathLen)
				set (${_headerIsInside} FALSE)
			else()
				set (${_headerIsInside} TRUE)
			endif()
		else()
			set (${_headerIsInside} TRUE)
		endif()
	else()
		# header is outside
		set (${_headerIsInside} FALSE)
	endif()
endmacro()

macro (cotire_check_ignore_header_file_path _headerFile _headerIsIgnoredVar)
	if (NOT EXISTS "${_headerFile}")
		set (${_headerIsIgnoredVar} TRUE)
	elseif (IS_DIRECTORY "${_headerFile}")
		set (${_headerIsIgnoredVar} TRUE)
	elseif ("${_headerFile}" MATCHES "\\.\\.|[_-]fixed" AND "${_headerFile}" MATCHES "\\.h$")
		# heuristic: ignore C headers with embedded parent directory references or "-fixed" or "_fixed" in path
		# these often stem from using GCC #include_next tricks, which may break the precompiled header compilation
		# with the error message "error: no include path in which to search for header.h"
		set (${_headerIsIgnoredVar} TRUE)
	else()
		set (${_headerIsIgnoredVar} FALSE)
	endif()
endmacro()

macro (cotire_check_ignore_header_file_ext _headerFile _ignoreExtensionsVar _headerIsIgnoredVar)
	# check header file extension
	cotire_get_source_file_extension("${_headerFile}" _headerFileExt)
	set (${_headerIsIgnoredVar} FALSE)
	if (_headerFileExt)
		list (FIND ${_ignoreExtensionsVar} "${_headerFileExt}" _index)
		if (_index GREATER -1)
			set (${_headerIsIgnoredVar} TRUE)
		endif()
	endif()
endmacro()

macro (cotire_parse_line _line _headerFileVar _headerDepthVar)
	if (MSVC)
		# cl.exe /showIncludes produces different output, depending on the language pack used, e.g.:
		# English: "Note: including file:   C:\directory\file"
		# German: "Hinweis: Einlesen der Datei:   C:\directory\file"
		# We use a very general regular expression, relying on the presence of the : characters
		if (_line MATCHES "( +)([a-zA-Z]:[^:]+)$")
			string (LENGTH "${CMAKE_MATCH_1}" ${_headerDepthVar})
			get_filename_component(${_headerFileVar} "${CMAKE_MATCH_2}" ABSOLUTE)
		else()
			set (${_headerFileVar} "")
			set (${_headerDepthVar} 0)
		endif()
	else()
		if (_line MATCHES "^(\\.+) (.*)$")
			# GCC like output
			string (LENGTH "${CMAKE_MATCH_1}" ${_headerDepthVar})
			if (IS_ABSOLUTE "${CMAKE_MATCH_2}")
				set (${_headerFileVar} "${CMAKE_MATCH_2}")
			else()
				get_filename_component(${_headerFileVar} "${CMAKE_MATCH_2}" REALPATH)
			endif()
		else()
			set (${_headerFileVar} "")
			set (${_headerDepthVar} 0)
		endif()
	endif()
endmacro()

function (cotire_parse_includes _language _scanOutput _ignoredIncludeDirs _honoredIncludeDirs _ignoredExtensions _selectedIncludesVar _unparsedLinesVar)
	if (WIN32)
		# prevent CMake macro invocation errors due to backslash characters in Windows paths
		string (REPLACE "\\" "/" _scanOutput "${_scanOutput}")
	endif()
	# canonize slashes
	string (REPLACE "//" "/" _scanOutput "${_scanOutput}")
	# prevent semicolon from being interpreted as a line separator
	string (REPLACE ";" "\\;" _scanOutput "${_scanOutput}")
	# then separate lines
	string (REGEX REPLACE "\n" ";" _scanOutput "${_scanOutput}")
	list (LENGTH _scanOutput _len)
	# remove duplicate lines to speed up parsing
	list (REMOVE_DUPLICATES _scanOutput)
	list (LENGTH _scanOutput _uniqueLen)
	if (COTIRE_VERBOSE OR COTIRE_DEBUG)
		message (STATUS "Scanning ${_uniqueLen} unique lines of ${_len} for includes")
		if (_ignoredExtensions)
			message (STATUS "Ignored extensions: ${_ignoredExtensions}")
		endif()
		if (_ignoredIncludeDirs)
			message (STATUS "Ignored paths: ${_ignoredIncludeDirs}")
		endif()
		if (_honoredIncludeDirs)
			message (STATUS "Included paths: ${_honoredIncludeDirs}")
		endif()
	endif()
	set (_sourceFiles ${ARGN})
	set (_selectedIncludes "")
	set (_unparsedLines "")
	# stack keeps track of inside/outside project status of processed header files
	set (_headerIsInsideStack "")
	foreach (_line IN LISTS _scanOutput)
		if (_line)
			cotire_parse_line("${_line}" _headerFile _headerDepth)
			if (_headerFile)
				cotire_check_header_file_location("${_headerFile}" "${_ignoredIncludeDirs}" "${_honoredIncludeDirs}" _headerIsInside)
				if (COTIRE_DEBUG)
					message (STATUS "${_headerDepth}: ${_headerFile} ${_headerIsInside}")
				endif()
				# update stack
				list (LENGTH _headerIsInsideStack _stackLen)
				if (_headerDepth GREATER _stackLen)
					math (EXPR _stackLen "${_stackLen} + 1")
					foreach (_index RANGE ${_stackLen} ${_headerDepth})
						list (APPEND _headerIsInsideStack ${_headerIsInside})
					endforeach()
				else()
					foreach (_index RANGE ${_headerDepth} ${_stackLen})
						list (REMOVE_AT _headerIsInsideStack -1)
					endforeach()
					list (APPEND _headerIsInsideStack ${_headerIsInside})
				endif()
				if (COTIRE_DEBUG)
					message (STATUS "${_headerIsInsideStack}")
				endif()
				# header is a candidate if it is outside project
				if (NOT _headerIsInside)
					# get parent header file's inside/outside status
					if (_headerDepth GREATER 1)
						math (EXPR _index "${_headerDepth} - 2")
						list (GET _headerIsInsideStack ${_index} _parentHeaderIsInside)
					else()
						set (_parentHeaderIsInside TRUE)
					endif()
					# select header file if parent header file is inside project
					# (e.g., a project header file that includes a standard header file)
					if (_parentHeaderIsInside)
						cotire_check_ignore_header_file_path("${_headerFile}" _headerIsIgnored)
						if (NOT _headerIsIgnored)
							cotire_check_ignore_header_file_ext("${_headerFile}" _ignoredExtensions _headerIsIgnored)
							if (NOT _headerIsIgnored)
								list (APPEND _selectedIncludes "${_headerFile}")
							else()
								# fix header's inside status on stack, it is ignored by extension now
								list (REMOVE_AT _headerIsInsideStack -1)
								list (APPEND _headerIsInsideStack TRUE)
							endif()
						endif()
						if (COTIRE_DEBUG)
							message (STATUS "${_headerFile} ${_ignoredExtensions} ${_headerIsIgnored}")
						endif()
					endif()
				endif()
			else()
				if (MSVC)
					# for cl.exe do not keep unparsed lines which solely consist of a source file name
					string (FIND "${_sourceFiles}" "${_line}" _index)
					if (_index LESS 0)
						list (APPEND _unparsedLines "${_line}")
					endif()
				else()
					list (APPEND _unparsedLines "${_line}")
				endif()
			endif()
		endif()
	endforeach()
	list (REMOVE_DUPLICATES _selectedIncludes)
	set (${_selectedIncludesVar} ${_selectedIncludes} PARENT_SCOPE)
	set (${_unparsedLinesVar} ${_unparsedLines} PARENT_SCOPE)
endfunction()

function (cotire_scan_includes _includesVar)
	set(_options "")
	set(_oneValueArgs COMPILER_ID COMPILER_EXECUTABLE COMPILER_ARG1 COMPILER_VERSION LANGUAGE UNPARSED_LINES SCAN_RESULT)
	set(_multiValueArgs COMPILE_DEFINITIONS COMPILE_FLAGS INCLUDE_DIRECTORIES SYSTEM_INCLUDE_DIRECTORIES
		IGNORE_PATH INCLUDE_PATH IGNORE_EXTENSIONS INCLUDE_PRIORITY_PATH COMPILER_LAUNCHER)
	cmake_parse_arguments(_option "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
	set (_sourceFiles ${_option_UNPARSED_ARGUMENTS})
	if (NOT _option_LANGUAGE)
		set (_option_LANGUAGE "CXX")
	endif()
	if (NOT _option_COMPILER_ID)
		set (_option_COMPILER_ID "${CMAKE_${_option_LANGUAGE}_ID}")
	endif()
	if (NOT _option_COMPILER_VERSION)
		set (_option_COMPILER_VERSION "${CMAKE_${_option_LANGUAGE}_COMPILER_VERSION}")
	endif()
	cotire_init_compile_cmd(_cmd "${_option_LANGUAGE}" "${_option_COMPILER_LAUNCHER}" "${_option_COMPILER_EXECUTABLE}" "${_option_COMPILER_ARG1}")
	cotire_add_definitions_to_cmd(_cmd "${_option_LANGUAGE}" ${_option_COMPILE_DEFINITIONS})
	cotire_add_compile_flags_to_cmd(_cmd ${_option_COMPILE_FLAGS})
	cotire_add_includes_to_cmd(_cmd "${_option_LANGUAGE}" _option_INCLUDE_DIRECTORIES _option_SYSTEM_INCLUDE_DIRECTORIES)
	cotire_add_frameworks_to_cmd(_cmd "${_option_LANGUAGE}" _option_INCLUDE_DIRECTORIES _option_SYSTEM_INCLUDE_DIRECTORIES)
	cotire_add_makedep_flags("${_option_LANGUAGE}" "${_option_COMPILER_ID}" "${_option_COMPILER_VERSION}" _cmd)
	# only consider existing source files for scanning
	set (_existingSourceFiles "")
	foreach (_sourceFile ${_sourceFiles})
		if (EXISTS "${_sourceFile}")
			list (APPEND _existingSourceFiles "${_sourceFile}")
		endif()
	endforeach()
	if (NOT _existingSourceFiles)
		set (${_includesVar} "" PARENT_SCOPE)
		return()
	endif()
	# add source files to be scanned
	if (WIN32)
		foreach (_sourceFile ${_existingSourceFiles})
			file (TO_NATIVE_PATH "${_sourceFile}" _sourceFileNative)
			list (APPEND _cmd "${_sourceFileNative}")
		endforeach()
	else()
		list (APPEND _cmd ${_existingSourceFiles})
	endif()
	if (COTIRE_VERBOSE)
		message (STATUS "execute_process: ${_cmd}")
	endif()
	if (MSVC_IDE OR _option_COMPILER_ID MATCHES "MSVC")
		# cl.exe messes with the output streams unless the environment variable VS_UNICODE_OUTPUT is cleared
		unset (ENV{VS_UNICODE_OUTPUT})
	endif()
	execute_process(
		COMMAND ${_cmd}
		WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
		RESULT_VARIABLE _result
		OUTPUT_QUIET
		ERROR_VARIABLE _output)
	if (_result)
		message (STATUS "Result ${_result} scanning includes of ${_existingSourceFiles}.")
	endif()
	cotire_parse_includes(
		"${_option_LANGUAGE}" "${_output}"
		"${_option_IGNORE_PATH}" "${_option_INCLUDE_PATH}"
		"${_option_IGNORE_EXTENSIONS}"
		_includes _unparsedLines
		${_sourceFiles})
	if (_option_INCLUDE_PRIORITY_PATH)
		set (_sortedIncludes "")
		foreach (_priorityPath ${_option_INCLUDE_PRIORITY_PATH})
			foreach (_include ${_includes})
				string (FIND ${_include} ${_priorityPath} _position)
				if (_position GREATER -1)
					list (APPEND _sortedIncludes ${_include})
				endif()
			endforeach()
		endforeach()
		if (_sortedIncludes)
			list (INSERT _includes 0 ${_sortedIncludes})
			list (REMOVE_DUPLICATES _includes)
		endif()
	endif()
	set (${_includesVar} ${_includes} PARENT_SCOPE)
	if (_option_UNPARSED_LINES)
		set (${_option_UNPARSED_LINES} ${_unparsedLines} PARENT_SCOPE)
	endif()
	if (_option_SCAN_RESULT)
		set (${_option_SCAN_RESULT} ${_result} PARENT_SCOPE)
	endif()
endfunction()

macro (cotire_append_undefs _contentsVar)
	set (_undefs ${ARGN})
	if (_undefs)
		list (REMOVE_DUPLICATES _undefs)
		foreach (_definition ${_undefs})
			list (APPEND ${_contentsVar} "#undef ${_definition}")
		endforeach()
	endif()
endmacro()

macro (cotire_comment_str _language _commentText _commentVar)
	if ("${_language}" STREQUAL "CMAKE")
		set (${_commentVar} "# ${_commentText}")
	else()
		set (${_commentVar} "/* ${_commentText} */")
	endif()
endmacro()

function (cotire_write_file _language _file _contents _force)
	get_filename_component(_moduleName "${COTIRE_CMAKE_MODULE_FILE}" NAME)
	cotire_comment_str("${_language}" "${_moduleName} ${COTIRE_CMAKE_MODULE_VERSION} generated file" _header1)
	cotire_comment_str("${_language}" "${_file}" _header2)
	set (_contents "${_header1}\n${_header2}\n${_contents}")
	if (COTIRE_DEBUG)
		message (STATUS "${_contents}")
	endif()
	if (_force OR NOT EXISTS "${_file}")
		file (WRITE "${_file}" "${_contents}")
	else()
		file (READ "${_file}" _oldContents)
		if (NOT "${_oldContents}" STREQUAL "${_contents}")
			file (WRITE "${_file}" "${_contents}")
		else()
			if (COTIRE_DEBUG)
				message (STATUS "${_file} unchanged")
			endif()
		endif()
	endif()
endfunction()

function (cotire_generate_unity_source _unityFile)
	set(_options "")
	set(_oneValueArgs LANGUAGE)
	set(_multiValueArgs
		DEPENDS SOURCES_COMPILE_DEFINITIONS
		PRE_UNDEFS SOURCES_PRE_UNDEFS POST_UNDEFS SOURCES_POST_UNDEFS PROLOGUE EPILOGUE)
	cmake_parse_arguments(_option "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
	if (_option_DEPENDS)
		cotire_check_file_up_to_date(_unityFileIsUpToDate "${_unityFile}" ${_option_DEPENDS})
		if (_unityFileIsUpToDate)
			return()
		endif()
	endif()
	set (_sourceFiles ${_option_UNPARSED_ARGUMENTS})
	if (NOT _option_PRE_UNDEFS)
		set (_option_PRE_UNDEFS "")
	endif()
	if (NOT _option_SOURCES_PRE_UNDEFS)
		set (_option_SOURCES_PRE_UNDEFS "")
	endif()
	if (NOT _option_POST_UNDEFS)
		set (_option_POST_UNDEFS "")
	endif()
	if (NOT _option_SOURCES_POST_UNDEFS)
		set (_option_SOURCES_POST_UNDEFS "")
	endif()
	set (_contents "")
	if (_option_PROLOGUE)
		list (APPEND _contents ${_option_PROLOGUE})
	endif()
	if (_option_LANGUAGE AND _sourceFiles)
		if ("${_option_LANGUAGE}" STREQUAL "CXX")
			list (APPEND _contents "#ifdef __cplusplus")
		elseif ("${_option_LANGUAGE}" STREQUAL "C")
			list (APPEND _contents "#ifndef __cplusplus")
		endif()
	endif()
	set (_compileUndefinitions "")
	foreach (_sourceFile ${_sourceFiles})
		cotire_get_source_compile_definitions(
			"${_option_CONFIGURATION}" "${_option_LANGUAGE}" "${_sourceFile}" _compileDefinitions
			${_option_SOURCES_COMPILE_DEFINITIONS})
		cotire_get_source_undefs("${_sourceFile}" COTIRE_UNITY_SOURCE_PRE_UNDEFS _sourcePreUndefs ${_option_SOURCES_PRE_UNDEFS})
		cotire_get_source_undefs("${_sourceFile}" COTIRE_UNITY_SOURCE_POST_UNDEFS _sourcePostUndefs ${_option_SOURCES_POST_UNDEFS})
		if (_option_PRE_UNDEFS)
			list (APPEND _compileUndefinitions ${_option_PRE_UNDEFS})
		endif()
		if (_sourcePreUndefs)
			list (APPEND _compileUndefinitions ${_sourcePreUndefs})
		endif()
		if (_compileUndefinitions)
			cotire_append_undefs(_contents ${_compileUndefinitions})
			set (_compileUndefinitions "")
		endif()
		if (_sourcePostUndefs)
			list (APPEND _compileUndefinitions ${_sourcePostUndefs})
		endif()
		if (_option_POST_UNDEFS)
			list (APPEND _compileUndefinitions ${_option_POST_UNDEFS})
		endif()
		foreach (_definition ${_compileDefinitions})
			if (_definition MATCHES "^([a-zA-Z0-9_]+)=(.+)$")
				list (APPEND _contents "#define ${CMAKE_MATCH_1} ${CMAKE_MATCH_2}")
				list (INSERT _compileUndefinitions 0 "${CMAKE_MATCH_1}")
			else()
				list (APPEND _contents "#define ${_definition}")
				list (INSERT _compileUndefinitions 0 "${_definition}")
			endif()
		endforeach()
		# use absolute path as source file location
		get_filename_component(_sourceFileLocation "${_sourceFile}" ABSOLUTE)
		if (WIN32)
			file (TO_NATIVE_PATH "${_sourceFileLocation}" _sourceFileLocation)
		endif()
		list (APPEND _contents "#include \"${_sourceFileLocation}\"")
	endforeach()
	if (_compileUndefinitions)
		cotire_append_undefs(_contents ${_compileUndefinitions})
		set (_compileUndefinitions "")
	endif()
	if (_option_LANGUAGE AND _sourceFiles)
		list (APPEND _contents "#endif")
	endif()
	if (_option_EPILOGUE)
		list (APPEND _contents ${_option_EPILOGUE})
	endif()
	list (APPEND _contents "")
	string (REPLACE ";" "\n" _contents "${_contents}")
	if (COTIRE_VERBOSE)
		message ("${_contents}")
	endif()
	cotire_write_file("${_option_LANGUAGE}" "${_unityFile}" "${_contents}" TRUE)
endfunction()

function (cotire_generate_prefix_header _prefixFile)
	set(_options "")
	set(_oneValueArgs LANGUAGE COMPILER_EXECUTABLE COMPILER_ARG1 COMPILER_ID COMPILER_VERSION)
	set(_multiValueArgs DEPENDS COMPILE_DEFINITIONS COMPILE_FLAGS
		INCLUDE_DIRECTORIES SYSTEM_INCLUDE_DIRECTORIES IGNORE_PATH INCLUDE_PATH
		IGNORE_EXTENSIONS INCLUDE_PRIORITY_PATH COMPILER_LAUNCHER)
	cmake_parse_arguments(_option "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
	if (NOT _option_COMPILER_ID)
		set (_option_COMPILER_ID "${CMAKE_${_option_LANGUAGE}_ID}")
	endif()
	if (NOT _option_COMPILER_VERSION)
		set (_option_COMPILER_VERSION "${CMAKE_${_option_LANGUAGE}_COMPILER_VERSION}")
	endif()
	if (_option_DEPENDS)
		cotire_check_file_up_to_date(_prefixFileIsUpToDate "${_prefixFile}" ${_option_DEPENDS})
		if (_prefixFileIsUpToDate)
			# create empty log file
			set (_unparsedLinesFile "${_prefixFile}.log")
			file (WRITE "${_unparsedLinesFile}" "")
			return()
		endif()
	endif()
	set (_prologue "")
	set (_epilogue "")
	if (_option_COMPILER_ID MATCHES "Clang")
		set (_prologue "#pragma clang system_header")
	elseif (_option_COMPILER_ID MATCHES "GNU")
		set (_prologue "#pragma GCC system_header")
	elseif (_option_COMPILER_ID MATCHES "MSVC")
		set (_prologue "#pragma warning(push, 0)")
		set (_epilogue "#pragma warning(pop)")
	elseif (_option_COMPILER_ID MATCHES "Intel")
		# Intel compiler requires hdrstop pragma to stop generating PCH file
		set (_epilogue "#pragma hdrstop")
	endif()
	set (_sourceFiles ${_option_UNPARSED_ARGUMENTS})
	cotire_scan_includes(_selectedHeaders ${_sourceFiles}
		LANGUAGE "${_option_LANGUAGE}"
		COMPILER_LAUNCHER "${_option_COMPILER_LAUNCHER}"
		COMPILER_EXECUTABLE "${_option_COMPILER_EXECUTABLE}"
		COMPILER_ARG1 "${_option_COMPILER_ARG1}"
		COMPILER_ID "${_option_COMPILER_ID}"
		COMPILER_VERSION "${_option_COMPILER_VERSION}"
		COMPILE_DEFINITIONS ${_option_COMPILE_DEFINITIONS}
		COMPILE_FLAGS ${_option_COMPILE_FLAGS}
		INCLUDE_DIRECTORIES ${_option_INCLUDE_DIRECTORIES}
		SYSTEM_INCLUDE_DIRECTORIES ${_option_SYSTEM_INCLUDE_DIRECTORIES}
		IGNORE_PATH ${_option_IGNORE_PATH}
		INCLUDE_PATH ${_option_INCLUDE_PATH}
		IGNORE_EXTENSIONS ${_option_IGNORE_EXTENSIONS}
		INCLUDE_PRIORITY_PATH ${_option_INCLUDE_PRIORITY_PATH}
		UNPARSED_LINES _unparsedLines
		SCAN_RESULT _scanResult)
	cotire_generate_unity_source("${_prefixFile}"
		PROLOGUE ${_prologue} EPILOGUE ${_epilogue} LANGUAGE "${_option_LANGUAGE}" ${_selectedHeaders})
	set (_unparsedLinesFile "${_prefixFile}.log")
	if (_unparsedLines)
		if (COTIRE_VERBOSE OR _scanResult OR NOT _selectedHeaders)
			list (LENGTH _unparsedLines _skippedLineCount)
			if (WIN32)
				file (TO_NATIVE_PATH "${_unparsedLinesFile}" _unparsedLinesLogPath)
			else()
				set (_unparsedLinesLogPath "${_unparsedLinesFile}")
			endif()
			message (STATUS "${_skippedLineCount} line(s) skipped, see ${_unparsedLinesLogPath}")
		endif()
		string (REPLACE ";" "\n" _unparsedLines "${_unparsedLines}")
	endif()
	file (WRITE "${_unparsedLinesFile}" "${_unparsedLines}\n")
endfunction()

function (cotire_add_makedep_flags _language _compilerID _compilerVersion _flagsVar)
	set (_flags ${${_flagsVar}})
	if (_compilerID MATCHES "MSVC")
		# cl.exe options used
		# /nologo suppresses display of sign-on banner
		# /TC treat all files named on the command line as C source files
		# /TP treat all files named on the command line as C++ source files
		# /EP preprocess to stdout without #line directives
		# /showIncludes list include files
		set (_sourceFileTypeC "/TC")
		set (_sourceFileTypeCXX "/TP")
		if (_flags)
			# append to list
			list (APPEND _flags /nologo "${_sourceFileType${_language}}" /EP /showIncludes)
		else()
			# return as a flag string
			set (_flags "${_sourceFileType${_language}} /EP /showIncludes")
		endif()
	elseif (_compilerID MATCHES "GNU")
		# GCC options used
		# -H print the name of each header file used
		# -E invoke preprocessor
		# -fdirectives-only do not expand macros, requires GCC >= 4.3
		if (_flags)
			# append to list
			list (APPEND _flags -H -E)
			if (NOT "${_compilerVersion}" VERSION_LESS "4.3.0")
				list (APPEND _flags -fdirectives-only)
			endif()
		else()
			# return as a flag string
			set (_flags "-H -E")
			if (NOT "${_compilerVersion}" VERSION_LESS "4.3.0")
				set (_flags "${_flags} -fdirectives-only")
			endif()
		endif()
	elseif (_compilerID MATCHES "Clang")
		if (UNIX)
			# Clang options used
			# -H print the name of each header file used
			# -E invoke preprocessor
			# -fno-color-diagnostics do not print diagnostics in color
			# -Eonly just run preprocessor, no output
			if (_flags)
				# append to list
				list (APPEND _flags -H -E -fno-color-diagnostics -Xclang -Eonly)
			else()
				# return as a flag string
				set (_flags "-H -E -fno-color-diagnostics -Xclang -Eonly")
			endif()
		elseif (WIN32)
			# Clang-cl.exe options used
			# /TC treat all files named on the command line as C source files
			# /TP treat all files named on the command line as C++ source files
			# /EP preprocess to stdout without #line directives
			# -H print the name of each header file used
			# -fno-color-diagnostics do not print diagnostics in color
			# -Eonly just run preprocessor, no output
			set (_sourceFileTypeC "/TC")
			set (_sourceFileTypeCXX "/TP")
			if (_flags)
				# append to list
				list (APPEND _flags "${_sourceFileType${_language}}" /EP -fno-color-diagnostics -Xclang -H -Xclang -Eonly)
			else()
				# return as a flag string
				set (_flags "${_sourceFileType${_language}} /EP -fno-color-diagnostics -Xclang -H -Xclang -Eonly")
			endif()
		endif()
	elseif (_compilerID MATCHES "Intel")
		if (WIN32)
			# Windows Intel options used
			# /nologo do not display compiler version information
			# /QH display the include file order
			# /EP preprocess to stdout, omitting #line directives
			# /TC process all source or unrecognized file types as C source files
			# /TP process all source or unrecognized file types as C++ source files
			set (_sourceFileTypeC "/TC")
			set (_sourceFileTypeCXX "/TP")
			if (_flags)
				# append to list
				list (APPEND _flags /nologo "${_sourceFileType${_language}}" /EP /QH)
			else()
				# return as a flag string
				set (_flags "${_sourceFileType${_language}} /EP /QH")
			endif()
		else()
			# Linux / Mac OS X Intel options used
			# -H print the name of each header file used
			# -EP preprocess to stdout, omitting #line directives
			# -Kc++ process all source or unrecognized file types as C++ source files
			if (_flags)
				# append to list
				if ("${_language}" STREQUAL "CXX")
					list (APPEND _flags -Kc++)
				endif()
				list (APPEND _flags -H -EP)
			else()
				# return as a flag string
				if ("${_language}" STREQUAL "CXX")
					set (_flags "-Kc++ ")
				endif()
				set (_flags "${_flags}-H -EP")
			endif()
		endif()
	else()
		message (FATAL_ERROR "cotire: unsupported ${_language} compiler ${_compilerID} version ${_compilerVersion}.")
	endif()
	set (${_flagsVar} ${_flags} PARENT_SCOPE)
endfunction()

function (cotire_add_pch_compilation_flags _language _compilerID _compilerVersion _prefixFile _pchFile _hostFile _flagsVar)
	set (_flags ${${_flagsVar}})
	if (_compilerID MATCHES "MSVC")
		file (TO_NATIVE_PATH "${_prefixFile}" _prefixFileNative)
		file (TO_NATIVE_PATH "${_pchFile}" _pchFileNative)
		file (TO_NATIVE_PATH "${_hostFile}" _hostFileNative)
		# cl.exe options used
		# /Yc creates a precompiled header file
		# /Fp specifies precompiled header binary file name
		# /FI forces inclusion of file
		# /TC treat all files named on the command line as C source files
		# /TP treat all files named on the command line as C++ source files
		# /Zs syntax check only
		# /Zm precompiled header memory allocation scaling factor
		set (_sourceFileTypeC "/TC")
		set (_sourceFileTypeCXX "/TP")
		if (_flags)
			# append to list
			list (APPEND _flags /nologo "${_sourceFileType${_language}}"
				"/Yc${_prefixFileNative}" "/Fp${_pchFileNative}" "/FI${_prefixFileNative}" /Zs "${_hostFileNative}")
			if (COTIRE_PCH_MEMORY_SCALING_FACTOR)
				list (APPEND _flags "/Zm${COTIRE_PCH_MEMORY_SCALING_FACTOR}")
			endif()
		else()
			# return as a flag string
			set (_flags "/Yc\"${_prefixFileNative}\" /Fp\"${_pchFileNative}\" /FI\"${_prefixFileNative}\"")
			if (COTIRE_PCH_MEMORY_SCALING_FACTOR)
				set (_flags "${_flags} /Zm${COTIRE_PCH_MEMORY_SCALING_FACTOR}")
			endif()
		endif()
	elseif (_compilerID MATCHES "GNU")
		# GCC options used
		# -x specify the source language
		# -c compile but do not link
		# -o place output in file
		# note that we cannot use -w to suppress all warnings upon pre-compiling, because turning off a warning may
		# alter compile flags as a side effect (e.g., -Wwrite-string implies -fconst-strings)
		set (_xLanguage_C "c-header")
		set (_xLanguage_CXX "c++-header")
		if (_flags)
			# append to list
			list (APPEND _flags -x "${_xLanguage_${_language}}" -c "${_prefixFile}" -o "${_pchFile}")
		else()
			# return as a flag string
			set (_flags "-x ${_xLanguage_${_language}} -c \"${_prefixFile}\" -o \"${_pchFile}\"")
		endif()
	elseif (_compilerID MATCHES "Clang")
		if (UNIX)
			# Clang options used
			# -x specify the source language
			# -c compile but do not link
			# -o place output in file
			# -fno-pch-timestamp disable inclusion of timestamp in precompiled headers (clang 4.0.0+)
			set (_xLanguage_C "c-header")
			set (_xLanguage_CXX "c++-header")
			if (_flags)
				# append to list
				list (APPEND _flags -x "${_xLanguage_${_language}}" -c "${_prefixFile}" -o "${_pchFile}")
				if (NOT "${_compilerVersion}" VERSION_LESS "4.0.0")
					list (APPEND _flags -Xclang -fno-pch-timestamp)
				endif()
			else()
				# return as a flag string
				set (_flags "-x ${_xLanguage_${_language}} -c \"${_prefixFile}\" -o \"${_pchFile}\"")
				if (NOT "${_compilerVersion}" VERSION_LESS "4.0.0")
					set (_flags "${_flags} -Xclang -fno-pch-timestamp")
				endif()
			endif()
		elseif (WIN32)
			# Clang-cl.exe options used
			# /Yc creates a precompiled header file
			# /Fp specifies precompiled header binary file name
			# /FI forces inclusion of file
			# /Zs syntax check only
			# /TC treat all files named on the command line as C source files
			# /TP treat all files named on the command line as C++ source files
			set (_sourceFileTypeC "/TC")
			set (_sourceFileTypeCXX "/TP")
			if (_flags)
				# append to list
				list (APPEND _flags "${_sourceFileType${_language}}"
						"/Yc${_prefixFile}" "/Fp${_pchFile}" "/FI${_prefixFile}" /Zs "${_hostFile}")
			else()
				# return as a flag string
				set (_flags "/Yc\"${_prefixFile}\" /Fp\"${_pchFile}\" /FI\"${_prefixFile}\"")
			endif()
		endif()
	elseif (_compilerID MATCHES "Intel")
		if (WIN32)
			file (TO_NATIVE_PATH "${_prefixFile}" _prefixFileNative)
			file (TO_NATIVE_PATH "${_pchFile}" _pchFileNative)
			file (TO_NATIVE_PATH "${_hostFile}" _hostFileNative)
			# Windows Intel options used
			# /nologo do not display compiler version information
			# /Yc create a precompiled header (PCH) file
			# /Fp specify a path or file name for precompiled header files
			# /FI tells the preprocessor to include a specified file name as the header file
			# /TC process all source or unrecognized file types as C source files
			# /TP process all source or unrecognized file types as C++ source files
			# /Zs syntax check only
			# /Wpch-messages enable diagnostics related to pre-compiled headers (requires Intel XE 2013 Update 2)
			set (_sourceFileTypeC "/TC")
			set (_sourceFileTypeCXX "/TP")
			if (_flags)
				# append to list
				list (APPEND _flags /nologo "${_sourceFileType${_language}}"
					"/Yc" "/Fp${_pchFileNative}" "/FI${_prefixFileNative}" /Zs "${_hostFileNative}")
				if (NOT "${_compilerVersion}" VERSION_LESS "13.1.0")
					list (APPEND _flags "/Wpch-messages")
				endif()
			else()
				# return as a flag string
				set (_flags "/Yc /Fp\"${_pchFileNative}\" /FI\"${_prefixFileNative}\"")
				if (NOT "${_compilerVersion}" VERSION_LESS "13.1.0")
					set (_flags "${_flags} /Wpch-messages")
				endif()
			endif()
		else()
			# Linux / Mac OS X Intel options used
			# -pch-dir location for precompiled header files
			# -pch-create name of the precompiled header (PCH) to create
			# -Kc++ process all source or unrecognized file types as C++ source files
			# -fsyntax-only check only for correct syntax
			# -Wpch-messages enable diagnostics related to pre-compiled headers (requires Intel XE 2013 Update 2)
			get_filename_component(_pchDir "${_pchFile}" DIRECTORY)
			get_filename_component(_pchName "${_pchFile}" NAME)
			set (_xLanguage_C "c-header")
			set (_xLanguage_CXX "c++-header")
			set (_pchSuppressMessages FALSE)
			if ("${CMAKE_${_language}_FLAGS}" MATCHES ".*-Wno-pch-messages.*")
				set(_pchSuppressMessages TRUE)
			endif()
			if (_flags)
				# append to list
				if ("${_language}" STREQUAL "CXX")
					list (APPEND _flags -Kc++)
				endif()
				list (APPEND _flags -include "${_prefixFile}" -pch-dir "${_pchDir}" -pch-create "${_pchName}" -fsyntax-only "${_hostFile}")
				if (NOT "${_compilerVersion}" VERSION_LESS "13.1.0")
					if (NOT _pchSuppressMessages)
						list (APPEND _flags -Wpch-messages)
					endif()
				endif()
			else()
				# return as a flag string
				set (_flags "-include \"${_prefixFile}\" -pch-dir \"${_pchDir}\" -pch-create \"${_pchName}\"")
				if (NOT "${_compilerVersion}" VERSION_LESS "13.1.0")
					if (NOT _pchSuppressMessages)
						set (_flags "${_flags} -Wpch-messages")
					endif()
				endif()
			endif()
		endif()
	else()
		message (FATAL_ERROR "cotire: unsupported ${_language} compiler ${_compilerID} version ${_compilerVersion}.")
	endif()
	set (${_flagsVar} ${_flags} PARENT_SCOPE)
endfunction()

function (cotire_add_prefix_pch_inclusion_flags _language _compilerID _compilerVersion _prefixFile _pchFile _flagsVar)
	set (_flags ${${_flagsVar}})
	if (_compilerID MATCHES "MSVC")
		file (TO_NATIVE_PATH "${_prefixFile}" _prefixFileNative)
		# cl.exe options used
		# /Yu uses a precompiled header file during build
		# /Fp specifies precompiled header binary file name
		# /FI forces inclusion of file
		# /Zm precompiled header memory allocation scaling factor
		if (_pchFile)
			file (TO_NATIVE_PATH "${_pchFile}" _pchFileNative)
			if (_flags)
				# append to list
				list (APPEND _flags "/Yu${_prefixFileNative}" "/Fp${_pchFileNative}" "/FI${_prefixFileNative}")
				if (COTIRE_PCH_MEMORY_SCALING_FACTOR)
					list (APPEND _flags "/Zm${COTIRE_PCH_MEMORY_SCALING_FACTOR}")
				endif()
			else()
				# return as a flag string
				set (_flags "/Yu\"${_prefixFileNative}\" /Fp\"${_pchFileNative}\" /FI\"${_prefixFileNative}\"")
				if (COTIRE_PCH_MEMORY_SCALING_FACTOR)
					set (_flags "${_flags} /Zm${COTIRE_PCH_MEMORY_SCALING_FACTOR}")
				endif()
			endif()
		else()
			# no precompiled header, force inclusion of prefix header
			if (_flags)
				# append to list
				list (APPEND _flags "/FI${_prefixFileNative}")
			else()
				# return as a flag string
				set (_flags "/FI\"${_prefixFileNative}\"")
			endif()
		endif()
	elseif (_compilerID MATCHES "GNU")
		# GCC options used
		# -include process include file as the first line of the primary source file
		# -Winvalid-pch warns if precompiled header is found but cannot be used
		# note: ccache requires the -include flag to be used in order to process precompiled header correctly
		if (_flags)
			# append to list
			list (APPEND _flags -Winvalid-pch -include "${_prefixFile}")
		else()
			# return as a flag string
			set (_flags "-Winvalid-pch -include \"${_prefixFile}\"")
		endif()
	elseif (_compilerID MATCHES "Clang")
		if (UNIX)
			# Clang options used
			# -include process include file as the first line of the primary source file
			# note: ccache requires the -include flag to be used in order to process precompiled header correctly
			if (_flags)
				# append to list
				list (APPEND _flags -include "${_prefixFile}")
			else()
				# return as a flag string
				set (_flags "-include \"${_prefixFile}\"")
			endif()
		elseif (WIN32)
			# Clang-cl.exe options used
			# /Yu uses a precompiled header file during build
			# /Fp specifies precompiled header binary file name
			# /FI forces inclusion of file
			if (_pchFile)
				if (_flags)
					# append to list
					list (APPEND _flags "/Yu${_prefixFile}" "/Fp${_pchFile}"
Download .txt
gitextract_lh4i7t6e/

├── CleanDirectoryList.cmake
├── CodeCoverage.cmake
├── CppcheckTargets.cmake
├── EnableProfiling.cmake
├── FindCVODE.cmake
├── FindFFTW.cmake
├── FindGDB.cmake
├── FindGSL.cmake
├── FindGitHub.cmake
├── FindITAPS.cmake
├── FindLAPACKLibs.cmake
├── FindLIS.cmake
├── FindMKL.cmake
├── FindMsysGit.cmake
├── FindNetCDF.cmake
├── FindOpenSG.cmake
├── FindOpenSGSupportlibs.cmake
├── FindShapelib.cmake
├── FindVRPN.cmake
├── Findcppcheck.cmake
├── Findcppcheck.cpp
├── Findquatlib.cmake
├── GetCPUDetails.cmake
├── GetGitRevisionDescription.cmake
├── GetGitRevisionDescription.cmake.in
├── LICENSE_1_0.txt
├── ListAllCMakeVariableValues.cmake
├── OptionRequires.cmake
├── PrintVariables.cmake
├── ProcessorCount.cmake
├── README.md
├── ResetConfigurations.cmake
├── SetDefaultBuildType.cmake
├── cotire-license
└── cotire.cmake
Download .txt
SYMBOL INDEX (1 symbols across 1 files)

FILE: Findcppcheck.cpp
  function main (line 14) | int main(int argc, char* argv[]) {
Condensed preview — 35 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (324K chars).
[
  {
    "path": "CleanDirectoryList.cmake",
    "chars": 1427,
    "preview": "# - Removes duplicate entries and non-directories from a provided list\n#\n#  clean_directory_list(<listvar> [<additional "
  },
  {
    "path": "CodeCoverage.cmake",
    "chars": 34983,
    "preview": "# Copyright (c) 2012 - 2017, Lars Bilke\n# All rights reserved.\n#\n# Redistribution and use in source and binary forms, wi"
  },
  {
    "path": "CppcheckTargets.cmake",
    "chars": 7383,
    "preview": "# - Run cppcheck on c++ source files as a custom target and a test\n#\n#  include(CppcheckTargets)\n#  add_cppcheck(<target"
  },
  {
    "path": "EnableProfiling.cmake",
    "chars": 1596,
    "preview": "# - Add flags to compile with profiling support - currently only for GCC\n#\n#  enable_profiling(<targetname>)\n#  globally"
  },
  {
    "path": "FindCVODE.cmake",
    "chars": 1380,
    "preview": "# Tries to find Sundials CVODE.\n#\n# This module will define the following variables:\n#  CVODE_INCLUDE_DIRS - Location of"
  },
  {
    "path": "FindFFTW.cmake",
    "chars": 664,
    "preview": "# - Find FFTW\n# Find the native FFTW includes and library\n#\n#  FFTW_INCLUDES    - where to find fftw3.h\n#  FFTW_LIBRARIE"
  },
  {
    "path": "FindGDB.cmake",
    "chars": 1654,
    "preview": "# - Try to find GDB\n#\n# Once done, this will define:\n#  GDB_FOUND - system has GDB\n#  GDB_COMMAND - the command to run\n#"
  },
  {
    "path": "FindGSL.cmake",
    "chars": 1088,
    "preview": "# - Find GSL\n# Find the native GSL includes and library\n#\n#  GSL_INCLUDES    - where to find gsl/gsl_*.h, etc.\n#  GSL_LI"
  },
  {
    "path": "FindGitHub.cmake",
    "chars": 1140,
    "preview": "# - Find GitHub for Windows\n#\n#   GITHUB_FOUND    - Was GitHub for Windows found\n#   GITHUB_BIN_DIR  - Path to the bin-d"
  },
  {
    "path": "FindITAPS.cmake",
    "chars": 7521,
    "preview": "# - Try to find ITAPS\n#\n# This will define\n#\n#  ITAPS_FOUND          - Requested components were found\n#  ITAPS_INCLUDES"
  },
  {
    "path": "FindLAPACKLibs.cmake",
    "chars": 2498,
    "preview": "# - Try to find LAPACK and BLAS libraries\n# Once done, this will define\n#  LAPACKLIBS_LIBRARIES, all libraries to link a"
  },
  {
    "path": "FindLIS.cmake",
    "chars": 491,
    "preview": "# - Try to find LIS\n# Once done, this will define\n#\n#  LIS_FOUND\n#  LIS_INCLUDE_DIRS\n#  LIS_LIBRARIES\n#\n#  Environment v"
  },
  {
    "path": "FindMKL.cmake",
    "chars": 1829,
    "preview": "# Find Intel Math Karnel Library (MKL)\n#\n# Options\n# - MKL_DIR      MKL root directory\n# - MKL_OPENMP   use OpenMP threa"
  },
  {
    "path": "FindMsysGit.cmake",
    "chars": 1474,
    "preview": "# The module defines the following variables:\n#   MSYSGIT_BIN_DIR - path to the tool binaries\n#   MSYSGIT_FOUND - true i"
  },
  {
    "path": "FindNetCDF.cmake",
    "chars": 727,
    "preview": "# - Find NetCDF\n# Find the native NetCDF includes and library\n\n# TODO:\n#       - Check for system netcdf\n#       - Make "
  },
  {
    "path": "FindOpenSG.cmake",
    "chars": 15476,
    "preview": "# Copyright (c) 2012 - 2015, Lars Bilke\n# All rights reserved.\n#\n# Redistribution and use in source and binary forms, wi"
  },
  {
    "path": "FindOpenSGSupportlibs.cmake",
    "chars": 1490,
    "preview": "# - Try to find OpenSGSupportlibs\n# Once done, this will define\n#\n#  OpenSGSupportlibs_FOUND\n#  OpenSGSupportlibs_INCLUD"
  },
  {
    "path": "FindShapelib.cmake",
    "chars": 520,
    "preview": "find_path(Shapelib_INCLUDE_DIR NAMES shapefil.h)\n\nif(MSVC)\n    set(Shapelib_LIBNAME shapelib)\nelse()\n    set(Shapelib_LI"
  },
  {
    "path": "FindVRPN.cmake",
    "chars": 2725,
    "preview": "# - try to find VRPN library\n#\n# Cache Variables:\n#  VRPN_LIBRARY\n#  VRPN_SERVER_LIBRARY\n#  VRPN_INCLUDE_DIR\n#\n# Non-cac"
  },
  {
    "path": "Findcppcheck.cmake",
    "chars": 5343,
    "preview": "# - try to find cppcheck tool\n#\n# Cache Variables:\n#  CPPCHECK_EXECUTABLE\n#\n# Non-cache variables you might use in your "
  },
  {
    "path": "Findcppcheck.cpp",
    "chars": 268,
    "preview": "/**\n * \\file Findcppcheck.cpp\n * \\brief Dummy C++ source file used by CMake module Findcppcheck.cmake\n *\n * \\author\n * R"
  },
  {
    "path": "Findquatlib.cmake",
    "chars": 2454,
    "preview": "# - Find quatlib\n# Find the quatlib headers and libraries.\n#\n#  QUATLIB_INCLUDE_DIRS - where to find quat.h\n#  QUATLIB_L"
  },
  {
    "path": "GetCPUDetails.cmake",
    "chars": 4753,
    "preview": "# - Set a number of variables to indicate things about the current CPU and OS\n#\n#  CPU_INTEL\n#  CPU_EXE_64BIT\n#  CPU_EXE"
  },
  {
    "path": "GetGitRevisionDescription.cmake",
    "chars": 4718,
    "preview": "# - Returns a version string from Git\n#\n# These functions force a re-configure on each git commit so that you can\n# trus"
  },
  {
    "path": "GetGitRevisionDescription.cmake.in",
    "chars": 1199,
    "preview": "# \n# Internal file for GetGitRevisionDescription.cmake\n#\n# Requires CMake 2.6 or newer (uses the 'function' command)\n#\n#"
  },
  {
    "path": "LICENSE_1_0.txt",
    "chars": 1338,
    "preview": "Boost Software License - Version 1.0 - August 17th, 2003\n\nPermission is hereby granted, free of charge, to any person or"
  },
  {
    "path": "ListAllCMakeVariableValues.cmake",
    "chars": 341,
    "preview": "# From http://www.kitware.com/blog/home/post/300\n#\n# Usage:\n#\n#  include(ListAllCMakeVariableValues)\n#  list_all_cmake_v"
  },
  {
    "path": "OptionRequires.cmake",
    "chars": 1357,
    "preview": "# - Add an option that depends on one or more variables being true.\n#\n#  option_requires(<option_name> <description> <va"
  },
  {
    "path": "PrintVariables.cmake",
    "chars": 6491,
    "preview": "# ------------------------- Begin Generic CMake Variable Logging ------------------\n\n# /*    C++ comment style not allow"
  },
  {
    "path": "ProcessorCount.cmake",
    "chars": 6672,
    "preview": "# - ProcessorCount(var)\n# Determine the number of processors/cores and save value in ${var}\n#\n# Sets the variable named "
  },
  {
    "path": "README.md",
    "chars": 1981,
    "preview": "Additional CMake Modules\n========================\n\nIntroduction\n------------\n\nThis is a collection of additional CMake m"
  },
  {
    "path": "ResetConfigurations.cmake",
    "chars": 878,
    "preview": "# - Re-set the available configurations to just RelWithDebInfo, Release, and Debug\n#\n# Requires these CMake modules:\n#  "
  },
  {
    "path": "SetDefaultBuildType.cmake",
    "chars": 1001,
    "preview": "# - Set a developer-chosen default build type\n#\n# Requires these CMake modules:\n#  no additional modules required\n#\n# Or"
  },
  {
    "path": "cotire-license",
    "chars": 1062,
    "preview": "Copyright (c) 2012-2016 Sascha Kratky\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of t"
  },
  {
    "path": "cotire.cmake",
    "chars": 174860,
    "preview": "# - cotire (compile time reducer)\n#\n# See the cotire manual for usage hints.\n#\n#========================================"
  }
]

About this extraction

This page contains the full source code of the bilke/cmake-modules GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 35 files (293.7 KB), approximately 80.0k tokens, and a symbol index with 1 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!