SFML community forums

General => General discussions => Topic started by: Klaim on April 28, 2012, 05:19:08 pm

Title: SFML2 CMake - Project using only CMake
Post by: Klaim on April 28, 2012, 05:19:08 pm
I want to test SFML2 with a CMake-only project, so I just write this:

cmake_minimum_required( VERSION 2.8 )


project( game )

add_subdirectory( sfml )

set( GAME_ALL_SOURCES
        main.cpp
)

add_executable( game ${GAME_ALL_SOURCES}  )
target_link_libraries( sfml-main sfml-system sfml-window sfml-graphics sfml-audio )
 

My sfml folder contain the current sfml git repository clone.
Without the last line I got no error, but with the last line I got:
CMake Error at CMakeLists.txt:13 (target_link_libraries):
  Attempt to add link library "sfml-system" to target "sfml-main" which is
  not built in this directory.


CMake Error at CMakeLists.txt:13 (target_link_libraries):
  Attempt to add link library "sfml-window" to target "sfml-main" which is
  not built in this directory.


CMake Error at CMakeLists.txt:13 (target_link_libraries):
  Attempt to add link library "sfml-graphics" to target "sfml-main" which is
  not built in this directory.


CMake Error at CMakeLists.txt:13 (target_link_libraries):
  Attempt to add link library "sfml-audio" to target "sfml-main" which is not
  built in this directory.

 

I'm  not sure what I'm doing wrong here... ?

It looks like the sfml projects can't refer to each other once I've included the projects this way.
I dont understand... is the problem from my CMake script, or from CMake or from the SFML CMake scripts?
Title: Re: SFML2 CMake - Project using only CMake
Post by: Tank on April 28, 2012, 05:34:16 pm
You either have to use add_subdirectory (http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_subdirectory) and then link to SFML's project name(s) or you search the libraries with find_library (http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:find_library) and SFML's FindSFML.cmake.
Title: Re: SFML2 CMake - Project using only CMake
Post by: Laurent on April 28, 2012, 05:37:49 pm
The first argument of target_link_libraries must be your own target. Here you're trying to link all SFML modules to... sfml-main ;)
Title: Re: SFML2 CMake - Project using only CMake
Post by: Klaim on April 28, 2012, 05:44:49 pm
The first argument of target_link_libraries must be your own target. Here you're trying to link all SFML modules to... sfml-main ;)


I was sure it was me being oblivious (but I can also blame the obscure CMake syntaxe!!!!.... ok ok it's my fault).

Also, I should stop creating new projects after midnight (I'm in japan right now).

Thanks.