Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake's FIND_PACKAGE not setting variables

Tags:

cmake

I am currently trying to write my first non-trivial CMake project but I cannot examine any of FIND_PACKAGE()'s outputs as it does not appear to be ascribing values to the global variables I expect it should! For example, the following code:

MESSAGE("CMake version: ${CMAKE_VERSION}")
FIND_PACKAGE(Armadillo)
IF(Armadillo_FOUND)
    MESSAGE("Found Armadillo.")
    MESSAGE("Armadillo include dir is: ${ARMADILLO_INCLUDE_DIR}")
    MESSAGE("Armadillo lib's to be linked against: ${Armadillo_LIBRARIES}")
    MESSAGE("Armadillo lib version: ${PACKAGE_FIND_VERSION}")
ENDIF(Armadillo_FOUND)

produces the following terminal output

/build]$ CMake version: 2.6.4
/build]$ Found Armadillo.
/build]$ Armadillo include dir is:
/build]$ Armadillo lib's to be linked against:
/build]$ Armadillo lib version:

I know this is quite basic, but from all the tutorials I can find this should produce useful output. Any ideas??

like image 327
dmon Avatar asked Aug 13 '12 17:08

dmon


1 Answers

Thanks arrowdodger, your answer was helpful but this is not exactly the problem. The problem is that after doing FIND_PACKAGE(Armadillo) none of these variables are set (not even the ARMADILLO_FOUND) variable. The Armadillo_FOUND (note lowercase) variable is set, and appears to be set by the FIND_PACKAGE() function not the cmake module file.

After copying the module file to my directory and calling it with the INCLUDE() command instead of the FIND_PACKAGE() command I was able to locate the issue. It appears it relates to using cmake 2.6.4 with Armadillo 2.2.3 (both outdated versions, but I'm limited by our systems distributed build to these). As I have Armadillo installed and Find_PACKAGE() appears to detect this (setting Armadillo_FOUND to true) however, the following line in the module file fails (and is noted to do so):

# Checks 'REQUIRED', 'QUIET' and versions.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Armadillo
  REQUIRED_VARS ARMADILLO_LIBRARY ARMADILLO_INCLUDE_DIR
  VERSION_VAR ARMADILLO_VERSION_STRING)
# version_var fails with cmake < 2.8.4

FIND_PACKAGE() does not appear to fail at this line and, as noted above, FIND_PACKAGE() sets Armadillo_FOUND to true but all variables set in the module file are not propagated back to the CMakeLists.txt file due to this fail. Removing VERSION_VAR from the above list fixed the issue. Of course a better fix would be to update cmake and armadillo, but this is not an option for me :(

like image 54
dmon Avatar answered Nov 15 '22 09:11

dmon