Skip to content

Instantly share code, notes, and snippets.

@3p3r
Created July 19, 2017 18:41
Show Gist options
  • Save 3p3r/bf19e8ba2a114fb4c5a62c00fca116e2 to your computer and use it in GitHub Desktop.
Save 3p3r/bf19e8ba2a114fb4c5a62c00fca116e2 to your computer and use it in GitHub Desktop.
A general purpose C++ header-only library finder
# Copyright (c) 2017 sepehr laal (MIT License)
#
# 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.
##______________________________________________________________________________
##
# This is a general purpose header-only library cmake finder. To use it, modify
# variables in the "Configuration" section below (variables starting with '_').
#
# Caveats: it does not support version / components.
#
# The following variables are set when found:
# <Package Name>_FOUND
# <Package Name>_INCLUDES
# <Package Name>_INCLUDE_DIR (same as <Package Name>_INCLUDES for convenience)
# <Package Name>_INCLUDE_DIRS (same as <Package Name>_INCLUDES for convenience)
##______________________________________________________________________________
## Configuration
set ( _package_name "RapidJson" )
set ( _package_header_candidates "rapidjson/rapidjson.h" )
set ( _package_suffix_candidates "include" )
##______________________________________________________________________________
## Check for the header files
# Force it to show up in the GUI
set ( ${_package_name}_ROOT "" CACHE PATH "${_package_name} root directory." )
find_path ( ${_package_name}_INCLUDES
NAMES "${_package_header_candidates}"
HINTS ${${_package_name}_ROOT} ${CMAKE_INSTALL_PREFIX}
PATH_SUFFIXES "${_package_suffix_candidates}"
)
##______________________________________________________________________________
## Actions taken when all components have been found
include( FindPackageHandleStandardArgs )
find_package_handle_standard_args (
${_package_name}
FOUND_VAR ${_package_name}_FOUND
REQUIRED_VARS ${_package_name}_INCLUDES
)
# Force it to show up in the GUI
set( ${_package_name}_FOUND ${${_package_name}_FOUND}
CACHE BOOL "${_package_name} found?" )
##______________________________________________________________________________
## Mark advanced variables
set( ${_package_name}_INCLUDE_DIR
"${${_package_name}_INCLUDES}" CACHE INTERNAL "" FORCE )
set( ${_package_name}_INCLUDE_DIRS
"${${_package_name}_INCLUDES}" CACHE INTERNAL "" FORCE )
mark_as_advanced (
${_package_name}_ROOT
${_package_name}_FOUND
${_package_name}_INCLUDES
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment