I am using cmake to manage compilation of my project and it is my first time to use cmake. This tool is very convenient, as there is plethora of scripts and functions which allows to check if all necessary libraries are installed on a given computer. Sometimes, however, these generic sripts does not cover some specific case or they are not available at all for a given library. My question is then as follows:
What is the right cmake-style way of veryfying whether a given header file (hpp or h) is available in the include path?
Justification:
Most straigforward way is probably to use CHECK_INCLUDE_FILE macros. For example, if I would like to use UnitTest++ library, I could write
CHECK_INCLUDE_FILE_CXX("UnitTest++.h" HAVE_UNITTESTXX)
IF(NOT HAVE_UNITTESTXX)
message( FATAL_ERROR "UnitTest++ is not found" )
ENDIF()
Unfortunately If it is done this way, the variable HAVE_UNITTESTXX is stored in the cache. If I install the UnitTest++ library in my system, cmake will still complain about UnitTest++.h not being installed. I can remove cache manually, but standard find package functions does not require that. I can also upgrade the code like this
CHECK_INCLUDE_FILE_CXX("UnitTest++.h" HAVE_UNITTESTXX)
IF(NOT HAVE_UNITTESTXX)
UNSET(HAVE_UNITTESTXX CACHE)
message( FATAL_ERROR "UnitTest++ is not found" )
ENDIF()
This solution works, but it does not look nice. I would like to know a cmake way to do this task.
Best regards!