CMake Issue - Need Help Getting it to work with GLEW and SFML

Started by
24 comments, last by hatfarm 10 years, 8 months ago

Yeah, I'm wondering if using SDL might be a better option, or if maybe I should use Qt. Qt 5.1 removes a need for GLEW at all, and would lose my need for GLM or SFML type stuff (and RapidXML). However, I'd have to go in and refactor all my code for the way Qt does things, which is no fun. However, I'd have a multiplatform project file that I understand pretty well already. Anyway, thanks again. I'm gonna keep plugging away, because I'd prefer not to have to refactor, but at some point I'm going to have to work on making actual code progress as opposed to CMake tinkering.

Advertisement

Before you do anything drastic. The best way I could help is with a buildable item. Make a copy, remove all your code and just stick a main file in there that creates a window. Assuming that still has the link problems, zip it up and let me take a look at it, can probably figure it out in fairly short order that way.

Wow! I got it to work. It started with me essentially copying your CMakeLists.txt and adjusting it in ways I knew I could get it to work. I think the problem was with FindSFML.cmake, because removing that and linking the directories made it compile (after some finessing). Here's my final file, maybe you can think of a way to make it more brief :)


cmake_minimum_required(VERSION 2.6)
project(BattleMap)

include_directories(
	"${PROJECT_BINARY_DIR}"
	$ENV{GLM_ROOT}
	$ENV{RAPIDXML_ROOT}
	$ENV{SFML_ROOT}/extlibs/headers
	$ENV{SFML_ROOT}/include
)

set(EXECUTABLE_NAME "BattleMap")
set(BattleMap_SRCS	
	battlemap.cpp
	battlemap.h
	
	bufferobject.cpp
	bufferobject.h
	
	camera.cpp
	camera.h
	
	globals.h
	
	vertices.h
	
	texture.cpp
	texture.h
	
	vao.cpp
	vao.h
	
	supertexture.cpp
	supertexture.h
	
	shaderprog.cpp
	shaderprog.h
	
	scene.cpp
	scene.h
	
	submapscene.cpp
	submapscene.h
	
	mapscene.cpp
	mapscene.h
	
	mousepointerscene.cpp
	mousepointerscene.h
	
	application.cpp
	application.h
	
	main.cpp
)

IF (WIN32)
	MESSAGE("IS Win32")
ELSE (WIN32)
	MESSAGE("NOT Win32")
ENDIF (WIN32)
	
ADD_DEFINITIONS( -DSFML_STATIC )
	
add_executable(${EXECUTABLE_NAME} ${BattleMap_SRCS})

add_library(sfml_main STATIC IMPORTED)
add_library(sfml_window STATIC IMPORTED)
add_library(sfml_system STATIC IMPORTED)
add_library(sfml_graphics STATIC IMPORTED)

set_target_properties(sfml_main PROPERTIES
       IMPORTED_LOCATION $ENV{SFML_ROOT}/lib/sfml-main.lib)

set_target_properties(sfml_window PROPERTIES
       IMPORTED_LOCATION $ENV{SFML_ROOT}/lib/sfml-window-s.lib)
	   
set_target_properties(sfml_system PROPERTIES
       IMPORTED_LOCATION $ENV{SFML_ROOT}/lib/sfml-system-s.lib)
	   
set_target_properties(sfml_graphics PROPERTIES
       IMPORTED_LOCATION $ENV{SFML_ROOT}/lib/sfml-graphics-s.lib)
	   
add_library(sfml_main_d STATIC IMPORTED)
add_library(sfml_window_d STATIC IMPORTED)
add_library(sfml_system_d STATIC IMPORTED)
add_library(sfml_graphics_d STATIC IMPORTED)

set_target_properties(sfml_main_d PROPERTIES
       IMPORTED_LOCATION $ENV{SFML_ROOT}/lib/sfml-main-d.lib)

set_target_properties(sfml_window_d PROPERTIES
       IMPORTED_LOCATION $ENV{SFML_ROOT}/lib/sfml-window-s-d.lib)
	   
set_target_properties(sfml_system_d PROPERTIES
       IMPORTED_LOCATION $ENV{SFML_ROOT}/lib/sfml-system-s-d.lib)
	   
set_target_properties(sfml_graphics_d PROPERTIES
       IMPORTED_LOCATION $ENV{SFML_ROOT}/lib/sfml-graphics-s-d.lib)
	   
SET(link_sfml_main optimized sfml_main debug sfml_main_d)
SET(link_sfml_window optimized sfml_window debug sfml_window_d)
SET(link_sfml_system optimized sfml_system debug sfml_system_d)
SET(link_sfml_graphics optimized sfml_graphics debug sfml_graphics_d)
	   
TARGET_LINK_LIBRARIES(${EXECUTABLE_NAME}
	${link_sfml_main}
	${link_sfml_window}
	${link_sfml_system}
	${link_sfml_graphics}
)

SET_TARGET_PROPERTIES(${EXECUTABLE_NAME}
	PROPERTIES
	COMPILE_DEFINITIONS
	"GLEW_STATIC="
)

# Install target
install(TARGETS ${EXECUTABLE_NAME} DESTINATION bin)

Thank you again for your help. Without your file, I wouldn't have been able to get this working.

Now, I'm having an issue, but it's one I can stand to have. It's generating a bad VS2010 solution. When I try to run it, it tells me that it cannot find the file "path_to_bin\bin\Debug\ALL_BUILD". Any experience with anything like that? I'm not going to complain too much, but I'd like to be able to use the VS2010 debugger for debugging my code. Thanks.

And, that's just me being dumb. It's because VS2010 will have ALL_BUILD as the default project. Setting the BattleMap project as the default project fixed it.

Glad you figured it all out. I'll see if I can come up with any simplifications for your new listfile, though CMake is often quite verbose as you know, so maybe not. I'm going to be looking into the new 2.8.11 target usage requirement stuff because it solves a huge number of annoyances I have with CMake in larger projects. It makes all the nonsense with passing parent scoped variables up the context chains go away.

Of course I rather expect you might be back in a bit with issues getting it to build on OsX and Linux. I remember there being a couple gotcha's, mostly on OsX to make it all work.

I don't know how soon I'll be building in those environments. Right now the code is only barely functional and not really something anyone would want to use and the only Mac I've got is my wife's Macbook that's a little over 4 years old. As for Linux, I've got a virtual machine running Linux Mint that I could load up, but I really don't feel like troubleshooting that right now :) However, I'm sure it's a good idea to troubleshoot now as opposed to later when I'm just trying to build it for a friend real quick. Looking forward to your future articles!

As a note, I started experimenting with the new target usage requirements introduced in CMake 2.8.11. As soon as folks start pushing those out in their CMake environments your list files get quite a bit more simplified. No more futzing around with figuring out required includes, support libraries or compile definitions. All that work I did standardizing the parent scoped values goes away completely. I think a CMake Part 5 will be coming soon as the changes are well worth a good article. :)

So, I think I'm a day short of a necro on this, so just under the gun. However, I thought I'd post in this thread again because it's related to that. So, I've got it working in Windows, but I'm having issues with Linux. I have it generate a Makefile, but it's not listing my include directories/libraries. Any thoughts? It's essentially the same as the text that was posted above (just a few more source files).

So, I think I'm a day short of a necro on this, so just under the gun. However, I thought I'd post in this thread again because it's related to that. So, I've got it working in Windows, but I'm having issues with Linux. I have it generate a Makefile, but it's not listing my include directories/libraries. Any thoughts? It's essentially the same as the text that was posted above (just a few more source files).

My first thought is to double check that on Linux you have the static version of SFML installed, I don't believe most Linux installations bother with the static version and only install the shared library versions. As such, yup, you won't find what you are looking for. Perhaps for Linux just try to use the shared version and see if that changes anything for you.

This topic is closed to new replies.

Advertisement