Cmake find_path does not work as expected

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 -NOTFOUND:

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

Why? Any idea?

+4
source share
1 answer

Turn my comment into a response

In your first case, CMake just finds the header in the default paths.

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

I brought your example into my Ubuntu distribution and I could reproduce your problem with the current 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

Decision

PATH_SUFFIXES "include/GLES2" PATH_SUFFIXES "GLES2" :

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

:

-- gl2.h => /usr/include/GLES2
+1

Source: https://habr.com/ru/post/1672722/


All Articles