Cmake find_path / find_library error

I am using CMake 2.8.2 version . The project uses a lot of external files and custom libraries (not available through find_package) and there is a long cascade of elements like the following:

find_path(XXX_INCLUDE_DIR XXX.h /XXX/include)
if (XXX_INCLUDE_DIR)
  message(STATUS "Includes (XXX) found in ${XXX_INCLUDE_DIR}")
else()
  message(FATAL_ERROR "Includes (XXX) not found")
endif()

      

There are over 20 things like this in the script - it doesn't look very good. According to the documentation, unfortunately, neither find_path nor find_library has a REQUIRED option that does the job here (as with find_package - if not found, the script stops). Do you have an idea how I can shorten the CMake script code? Something like

find_path(XXX_INCLUDE_DIR XXX.h /XXX/include REQUIED)

      

or something like that would be great.

+3


source to share


2 answers


You probably want to use macro or function .



+1


source


Put them in your custom FindXXX.cmake modules. Read the docs and take a look at FindPNG.cmake

. Put them in <project>/cmake/FindXXX.cmake

(or similar) and then add the directory containing these files to CMAKE_MODULE_PATH

and use find_package()

eg.



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

find_package(XXX REQUIRED)

      

+6


source







All Articles