Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake find_path not working as expected

Tags:

cmake

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?

like image 539
CDZ Avatar asked Mar 20 '17 12:03

CDZ


1 Answers

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
like image 123
Florian Avatar answered Oct 18 '22 00:10

Florian