cmake find_path not working as expected

14,872

Turning my comment into an answer

In your first case CMake just does find the header in the default paths.

CMAKE_FRAMEWORK_PATH seems a strange choice as an additional search path since the variable contains a "list of directories specifying a search path for OS X frameworks used by the find_library(), find_package(), find_path(), and find_file() commands."

I've given your example an try on my Ubuntu distribution and I could reproduce your problem with the flowing test:

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)

project(FindGL2)

unset(GLES_SDK_INCLUDE_DIR CACHE)
find_path(
    GLES_SDK_INCLUDE_DIR
    NAMES "GLES2/gl2.h"
    PATHS "${CMAKE_FRAMEWORK_PATH}/include"
)
message(STATUS "GLES2/gl2.h => ${GLES_SDK_INCLUDE_DIR}")

unset(GLES_SDK_INCLUDE_DIR CACHE)
find_path(
    GLES_SDK_INCLUDE_DIR
    NAMES "gl2.h"
    PATHS "${CMAKE_FRAMEWORK_PATH}/include/GLES2"
)
message(STATUS "gl2.h => ${GLES_SDK_INCLUDE_DIR}")

Gives

-- GLES2/gl2.h => /usr/include
-- gl2.h => GLES_SDK_INCLUDE_DIR-NOTFOUND

Solution

Use PATH_SUFFIXES "include/GLES2" or just PATH_SUFFIXES "GLES2" instead:

find_path(
    GLES_SDK_INCLUDE_DIR
    NAMES "gl2.h"
    PATH_SUFFIXES "GLES2"
)
message(STATUS "gl2.h => ${GLES_SDK_INCLUDE_DIR}")

Does give:

-- gl2.h => /usr/include/GLES2
Share:
14,872

Related videos on Youtube

CDZ
Author by

CDZ

Updated on September 15, 2022

Comments

  • CDZ
    CDZ over 1 year

    I have the following CMake script, it works:

    find_path(
      GLES_SDK_INCLUDE_DIR
      NAMES "GLES2/gl2.h"
      PATHS "${CMAKE_FRAMEWORK_PATH}/include")
    

    But this one returns a -NOTFOUND:

    find_path(
      GLES_SDK_INCLUDE_DIR
      NAMES "gl2.h"
      PATHS "${CMAKE_FRAMEWORK_PATH}/include/GLES2")
    

    Why? Any idea?

    • Florian
      Florian about 7 years
      Does find_path(GLES_SDK_INCLUDE_DIR NAMES "GLES2/gl2.h") also work? My guess is that CMake does find the header in the default paths. CMAKE_FRAMEWORK_PATH seems a strange choice as an additional search path since the variable contains a "list of directories specifying a search path for OS X frameworks used by the find_library(), find_package(), find_path(), and find_file() commands." That said you could try to add PATH_SUFFIXES "include/GLES2" instead of PATHS "${CMAKE_FRAMEWORK_PATH}/include/GLES2".