CMake: opengl include dirs are called differently on different platforms

Cmake founds includes a directory for opengl, but opengl headers are in a subdirectory that is named differently on different platforms (and possibly compilers): gl on Windows, GL on Linux, OpenGL (as far as I know) on Mac, Thus adding OPENGL_INCLUDE_DIRECTORY to include paths doesn't help much - I still have to include (or, and so on) in my sources. How can I deal with this?

+5
source share
1 answer

I suppose you mean OPENGL_INCLUDE_DIR, not OPENGL_INCLUDE_DIRECTORY.

You have a couple of options here. The easiest thing is to add ${OPENGL_INCLUDE_DIR}/GLor ${OPENGL_INCLUDE_DIR}/OpenGLto your search paths and use

#include "gl.h"

in the source code.

Windows, /gl /gl - /gl.

, CMakeLists.txt :

if(APPLE)
  include_directories(${OPENGL_INCLUDE_DIR}/OpenGL)
else()
  include_directories(${OPENGL_INCLUDE_DIR}/GL)
endif()


, CMake "gl.h" :

find_path(OpenglIncludeSubdir
            NAMES gl.h
            PATHS ${OPENGL_INCLUDE_DIR}
            PATH_SUFFIXES GL OpenGL
            NO_DEFAULT_PATH)
include_directories(${OpenglIncludeSubdir})

, :

#include "gl.h"


, (.. ${OPENGL_INCLUDE_DIR}) "gl.h", configure_file #include. , - :

#include "@OpenglSubdir@/gl.h"

configure_file @OpenglSubdir@ .

#include "GL/gl.h"

#include "OpenGL/gl.h"

.

To achieve this, you would do something like:

find_file(OpenglSubdir
            NAMES GL OpenGL
            PATHS ${OPENGL_INCLUDE_DIR}
            NO_DEFAULT_PATH)
get_filename_component(OpenglSubdir ${OpenglSubdir} NAME)
configure_file(${CMAKE_SOURCE_DIR}/my_config.h.in ${CMAKE_SOURCE_DIR}/my_config.h)
+6
source

All Articles