cmake - find path to ignore a directory

2020-05-01 06:49发布

问题:

How do I make cmake ignore a directory when doing find_path? I'm trying to find the system's freetype2 library, but instead it is finding the one that inside my project. How do I get it to ignore that?

Here's what my FindFreeTypeTwo.cmake looks like

FIND_PATH(_FREETYPE2_INCLUDE_DIR ft2build.h PATH_SUFFIXES freetype2)
FIND_LIBRARY(_FREETYPE2_LIBRARIES NAMES freetype)

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Freetype2 DEFAULT_MSG _FREETYPE2_LIBRARIES _FREETYPE2_INCLUDE_DIR)

if (FREETYPE2_FOUND)
   set (FREETYPE2_INCLUDE_DIR ${_FREETYPE2_INCLUDE_DIR})
   set (FREETYPE2_LIBRARIES ${_FREETYPE2_LIBRARIES})
endif (FREETYPE2_FOUND)

This is what my file structure looks like.

  \ 
   \ src
    | CMakeLists.tst
     \ build
      \ cmake_config
       \ find_packages
        | FindFreeTypeTwo.cmake
   \ (folder to exclude)
   \ (other folders)

回答1:

You could change the parameters in the FIND_PATH(). Instead of using the PATH_SUFFIXES, you could use something like this FIND_PATH(_FREETYPE2_INCLUDE_DIR ft2build.h HINTS ENV FREETYPE2_INCLUDE_DIR PATHS /usr/local/include) This is something I usually use when I write cmake file.



标签: cmake