1
votes

I want to include SDL2 and GLEW to my Cmake project

The scr files are in C:\libs\src and I createt all the libaries in CMAKE with PATH CMAKE_Install_PRÄFIX like in this documentation:

  1. Download and install CMake ( https://cmake.org/ ) and Visual Studio Community Edition ( https://visualstudio.microsoft.com/de/ )
  2. Create a directory libs or libraries (whatever suits you) where you install all your libraries. It is reasonable to have this on a low level as in the future you might want to add further libraries and use this folder also for other projects. The following explanations assume that you use C:/libs. If you want to use another directory, just adapt the directory the way you need it.
  3. Add C:/libs and C:/libs/bin to the Environment Variable Path ( https://www.computerhope.com/issues/ch000549.htm ).
  4. Create a subdirectory libs/src, copy all the libraries from cgAdvancedFramework/deps/ to this folder and extract them.
  5. SDL2:
    • Open cmake-gui
      • Source code: C:/libs/src/SDL2-2.0.12
      • Binaries: C:/libs/src/SDL2-2.0.12/build
      • Add entry
        • Name: CMAKE_INSTALL_PREFIX
        • Type: PATH
        • Value: C:\libs
        • Ok
      • Configure
        • Accept creating build directory
        • Use default native compiler --> Finish
      • Generate
      • Open Project (this should start Visual Studio)
    • Visual Studio
      • Solution Configuration: Debug
      • right-click ALL_BUILD --> Build (if errors appear, here you might have done something wrong before)
      • right-click INSTALL --> Build (if errors appear, ...)
      • do the same for Solution Configuration: RelWithDebInfo (optional but recommended)

My Project is locatet C:\Users\Documents...\dvs\volren

and the build dir is locatet C:\Users\Documents...\dvs\build and

C:\libs\include\GL

C:\libs\include\SDL2 ...

main.cpp:

#include <iostream>
#pragma once
#define NOMINMAX
#include <SDL2.h>   //dont find
#include <GL/glew.h> //dont find
#include <vtk3DS.h> // find

CMakelist.txt:

cmake_minimum_required(VERSION 2.8)

PROJECT(volren)

find_package(VTK REQUIRED)
include(${VTK_USE_FILE})

find_package(GLEW REQUIRED)
include_directories(${GLEW_INCLUDE_DIRS})

find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})

add_executable(volren MACOSX_BUNDLE main.cpp Camera.hpp Math.hpp Image.hpp)

target_link_libraries(volren ${VTK_LIBRARIES} ${GLEW_LIBRARIES} ${VTK_LIBRARIES}) 

Error: Can not open source file GL/glew.h

Where is my mistake ?

1

1 Answers

0
votes

It seems that you are on Windows, so why add MACOSX_BUNDLE in your add_executable ?

Also, are you sure GLEW_INCLUDE_DIRS, SDL2_INCLUDE_DIRS are the correct variable to use ? Did you check if they were populated ?