I'm attempting to build a CMakeLists.txt
for my project. It needs to include SDL, OpenGL, and GLEW as well as all of my *.cpp and *.h files in different directories. All files used to build the project are in the Project Source Directory that cmake is called in.
The error:
In file included from /home/me/repos/AlchemyEngine/alchemy/alcEngine.cpp:1:0:
/home/me/repos/AlchemyEngine/alchemy/alcEngine.h:69:18: fatal error: glew.h: No such file or directory
#include <glew.h>
I think it'd be easiest to show the steps for setting this project up in Visual Studio (which works as I used to develop from there) and hope I can get help recreating the setup in my CMakeLists.txt file.
Setting up the project in Visual Studio
1. Includes
Project -> *ProjectName* Properties -> VC++ Directories
Click Include Directories -> Click down-arrow- > edit
Browse for the include files (...\SDL2-OpenGL-GLEW-VC++\include)
2. Libraries
Project -> *ProjectName* Properties -> VC++ Directories
Click Library Directories -> Click down-arrow -> edit
Browse for the library files (...\SDL2-OpenGL-GLEW-VC++\lib)
3. Linkers
Project -> *ProjectName* Properties -> Linker -> Input
Click Additional Dependencies -> Click down arrow -> edit
Copy into box:
SDL2.lib
SDL2main.lib
SDL2_image.lib
OpenGL32.lib
glu32.lib
glew32.lib
4. DLLs
Build project with chosen entry point to create Debug folder with executable.
Copy the .dll files from the ...\SDL-OpenGL-GLEW-VC++\dropInExe folder and paste into the
Debug folder with the project executable
(...\*Project Folder*\Debug)
Here is my CMakeLists.txt
file as it stands
cmake_minimum_required (VERSION 3.5)
project (AlchemyEngine)
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
include_directories (
alchemy/
alchemy/event/
alchemy/scene/
alchemy/resource/
alchemy/render/
alchemy/util/
game/
#SDL2_OpenGL_GLEW_VC++/include
)
set( srcs
alchemy/alcEngine.cpp
alchemy/event/alcEvent.cpp
alchemy/render/alcRenderer.cpp
alchemy/render/alcSprite.cpp
alchemy/resource/alcResource.cpp
alchemy/resource/alcShader.cpp
alchemy/resource/alcTexture.cpp
alchemy/scene/alcObject.cpp
alchemy/scene/alcScene.cpp
alchemy/util/alcBlockAllocator.cpp
alchemy/util/alcStackAllocator.cpp
game/Player.cpp
Main.cpp
)
add_library (libraries STATIC SDL2_OpenGL_GLEW_VC++/include/)
add_executable (alc ${PROJECT_SOURCE_DIR}/${srcs})
target_link_libraries(alc libraries)
set_target_properties(libraries PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(alc PROPERTIES LINKER_LANGUAGE CXX)
After configuration and generation, $CMAKE_SOURCE_DIR/build/bin
contains:
liblibraries.a
glew32.dll
libpng16-16.dll
SDL2.dll
SDL2_image.dll
zlib1.dll
It seems to me that my method for including the header files is incorrect, but poking around the CMake documentation and other stack exchange posts hasn't produced any better results. I have a feeling it has to do with the linker step, but I cannot figure out how to specify the dependencies in CMake.
I can tree
and post the output too if the project structure is that important for this issue.
FINAL EDIT:
The error was fixed in the answer below, here is my final CMakeLists.txt for anyone interested
# Outputs executable(s) in {PROJECT_SOURCE_DIR}/build/bin/
# specify min version and project name
cmake_minimum_required (VERSION 3.5)
project (AlchemyEngine)
# set output paths for binaries/executable
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
# include project header files
include_directories (
alchemy/
alchemy/event/
alchemy/scene/
alchemy/resource/
alchemy/render/
alchemy/util/
game/
)
# create source files definition
set( srcs
alchemy/alcEngine.cpp
alchemy/event/alcEvent.cpp
alchemy/render/alcRenderer.cpp
alchemy/render/alcSprite.cpp
alchemy/resource/alcResource.cpp
alchemy/resource/alcShader.cpp
alchemy/resource/alcTexture.cpp
alchemy/scene/alcObject.cpp
alchemy/scene/alcScene.cpp
alchemy/util/alcBlockAllocator.cpp
alchemy/util/alcStackAllocator.cpp
game/Player.cpp
Main.cpp
)
# add a library target to be built from the source files
add_library (libraries STATIC SDL2_OpenGL_GLEW_VC++/lib/)
# specify include directories
target_include_directories(libraries PUBLIC SDL2_OpenGL_GLEW_VC++/include/)
# specify libraries to use when linking the library
target_link_libraries (libraries
${PROJECT_SOURCE_DIR}/SDL2_OpenGL_GLEW_VC++/lib/glew32.lib
${PROJECT_SOURCE_DIR}/SDL2_OpenGL_GLEW_VC++/lib/glew32s.lib
${PROJECT_SOURCE_DIR}/SDL2_OpenGL_GLEW_VC++/lib/SDL2_image.lib
${PROJECT_SOURCE_DIR}/SDL2_OpenGL_GLEW_VC++/lib/SDL2.lib
${PROJECT_SOURCE_DIR}/SDL2_OpenGL_GLEW_VC++/lib/SDL2main.lib
)
# create the executable using the source files defined above
add_executable (alc ${PROJECT_SOURCE_DIR}/${srcs})
# specify the headers
target_include_directories(alc PUBLIC ${PROJECT_SOURCE_DIR})
# link the library to the project
target_link_libraries(alc libraries)
# force the linker language because there's some c stuff in the library files
set_target_properties(libraries PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(alc PROPERTIES LINKER_LANGUAGE CXX)