[cmake-developers] FindSTLSoft.cmake, Problems?
mikkoi
mikko.koivunalho at iki.fi
Mon Dec 28 07:31:56 EST 2015
Hi,
A CMake project depends on the header only library STLSoft
(http://www.stlsoft.org/).
We rely on the developer having STLSoft installed or "installed"
(pointed to by an environment variable) on his system for compilation.
To make sure the developer's version is high enough, I created this
FindSTLSoft.cmake file.
Can someone read it through, and say if there are any errors or
antipatterns.
I'm still learning CMake, so I might have made mistakes.
Thank you.
By the way, if it is good enough, it can be added to the CMake
distribution.
--
Mikko Koivunalho
LinkedIn: http://www.linkedin.com/in/MikkoKoivunalho
AboutMe: http://about.me/mikkokoivunalho
Blog: http://exercisesinintegrationanddelivery.blogspot.com
# - Find STLSoft
# This module finds if STLSoft is installed and determines where the
# include files and libraries are. This code sets the following
# variables:
# STLSOFT_FOUND - TRUE/FALSE - Found/not found (N.B. all upper case.)
# STLSoft_INCLUDE_DIR - path to include
# STLSoft_VERSION_MAJOR
# STLSoft_VERSION_MINOR
# STLSoft_VERSION_PATCH
# STLSoft_VERSION
# STLSoft_VERSION_COUNT
# The minimum required version of STLSoft can be specified using the
# standard CMake syntax, e.g. FIND_PACKAGE(STLSoft 1.9.117)
#
# Usage as follows:
# find_package(STLSoft)
# find_package(STLSoft 1.9.117 REQUIRED)
# find_package(STLSoft 1.9.117 EXACT QUIET REQUIRED)
#----------------------------------------------------------------------------------
include(FindPackageHandleStandardArgs)
# try to get global environment variable first...
set(_STLSOFT_ROOT "$ENV{STLSOFT}")
if(_STLSOFT_ROOT)
set(STLSoft_INCLUDE_DIR ${_STLSOFT_ROOT}/include)
else(_STLSOFT_ROOT)
find_path(STLSoft_INCLUDE_DIR
NAMES
stlsoft.h
)
endif(_STLSOFT_ROOT)
if(EXISTS "${STLSoft_INCLUDE_DIR}/stlsoft/stlsoft.h")
file(READ "${STLSoft_INCLUDE_DIR}/stlsoft/stlsoft.h"
_stlsoft_h_CONTENT)
string(REGEX REPLACE ".*#define[ ]+_STLSOFT_VER_MAJOR[ ]+([0-9]+).*"
"\\1"
STLSoft_VERSION_MAJOR "${_stlsoft_h_CONTENT}")
string(REGEX REPLACE ".*#define[ ]+_STLSOFT_VER_MINOR[ ]+([0-9]+).*"
"\\1"
STLSoft_VERSION_MINOR "${_stlsoft_h_CONTENT}")
string(REGEX REPLACE ".*#define[ ]+_STLSOFT_VER_REVISION[
]+([0-9]+).*" "\\1"
STLSoft_VERSION_PATCH "${_stlsoft_h_CONTENT}")
set(STLSoft_VERSION
"${STLSoft_VERSION_MAJOR}.${STLSoft_VERSION_MINOR}.${STLSoft_VERSION_PATCH}")
set(STLSoft_VERSION_COUNT 3)
# Sets the STLSOFT_FOUND variable.
find_package_handle_standard_args( STLSoft
REQUIRED_VARS
STLSoft_INCLUDE_DIR
VERSION_VAR
STLSoft_VERSION
)
mark_as_advanced(STLSoft_INCLUDE_DIR
STLSoft_VERSION_MAJOR
STLSoft_VERSION_MINOR
STLSoft_VERSION_PATCH
STLSoft_VERSION
STLSoft_VERSION_COUNT
)
else(EXISTS "${STLSoft_INCLUDE_DIR}/stlsoft/stlsoft.h")
if(NOT STLSoft_FIND_QUIETLY)
message(FATAL_ERROR "No STLSoft package found... Please point us
with the STLSOFT env var!")
endif(NOT STLSoft_FIND_QUIETLY)
endif(EXISTS "${STLSoft_INCLUDE_DIR}/stlsoft/stlsoft.h")
More information about the cmake-developers
mailing list