Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Linking with CMake  (Read 1930 times)

0 Members and 1 Guest are viewing this topic.

jaqb17

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Linking with CMake
« on: November 26, 2016, 12:26:02 am »
Hello!

I want to generate a simple project with CMake. Here is my CMakeLists.txt

Code: [Select]
cmake_minimum_required(VERSION 3.4)
 
project(Program)
 
set(SOURCE_FILES
        src/main.cpp
        )

set(SFML_ROOT "${CMAKE_SOURCE_DIR}/SFML/lib")
set(SFML_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/SFML/include")
set(SFML_LIBRARY_DIR "${CMAKE_SOURCE_DIR}/SFML/lib")
 
 
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/SFML/cmake/Modules")
 
find_package(SFML 2 REQUIRED window )
 
include_directories(
    ${SFML_INCLUDE_DIR}
)
 
add_executable(Program ${SOURCE_FILES}
        ${SFML_LIBRARIES}     
)
 
message ( ${SFML_LIBRARIES} )
 
target_link_libraries(Program ${SFML_LIBRARIES})

Everything works great on OSX, but on Windows SFML_LIBRARIES looks like this:
debug<path...>/lib/libsfml-window-d.aoptimized<path...>/lib/libsfml-window.a


...and because of that i got CMake error (check out screenshot).
What should I do to make it work on Windows?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Linking with CMake
« Reply #1 on: November 26, 2016, 09:28:08 am »
Quote
Everything works great on OSX, but on Windows SFML_LIBRARIES looks like this:
debug<path...>/lib/libsfml-window-d.aoptimized<path...>/lib/libsfml-window.a


...and because of that i got CMake error
No, not because of that. This part is perfectly fine. What's wrong is that you put libraries in add_executable (which should only contain source files).
Laurent Gomila - SFML developer

jaqb17

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Linking with CMake
« Reply #2 on: November 26, 2016, 10:12:32 am »
OK I removed SFML_LIBRARIES from add_executable, and generating works well, but now linking is a problem (undefined references).
I tried to build SFML by myself, and also modified my CMakeLists.txt. Now it looks like that:

Code: [Select]
cmake_minimum_required(VERSION 3.4)

project(Program)

set(SOURCE_FILES
        src/main.cpp
        )




set(SFML_ROOT "C:/Users/Komputer.DESKTOP-5G9R8AU/Desktop/SFML_ROOT/install")
set(SFML_INCLUDE_DIR "C:/Users/Komputer.DESKTOP-5G9R8AU/Desktop/SFML_ROOT/install/include")
set(SFML_LIBRARY_DIR "C:/Users/Komputer.DESKTOP-5G9R8AU/Desktop/SFML_ROOT/install/lib")



set(CMAKE_MODULE_PATH "C:/Users/Komputer.DESKTOP-5G9R8AU/Desktop/SFML_ROOT/install/cmake/Modules")


find_package(SFML 2 REQUIRED window)

include_directories(
    ${SFML_INCLUDE_DIR}
)

add_executable(Program ${SOURCE_FILES}

)

message ( ${SFML_LIBRARIES} )


target_link_libraries(Program ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})

Something I forgot?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Linking with CMake
« Reply #3 on: November 26, 2016, 10:28:09 am »
Quote
Something I forgot?
The error messages ;)
Laurent Gomila - SFML developer

jaqb17

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Linking with CMake
« Reply #4 on: November 26, 2016, 03:27:51 pm »
Here you go! :D
It throws error like this for every use of SFML object.
« Last Edit: November 26, 2016, 03:44:21 pm by jaqb17 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Linking with CMake
« Reply #5 on: November 26, 2016, 04:47:24 pm »
The window module depends on the system module, so you'll also have to find that. Additionally you shouldn't set SFML_INCLUDE_DIR and SFML_LIBRARY_DIR yourself, those are automatically set by FindSFML.cmake.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

jaqb17

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Linking with CMake
« Reply #6 on: December 01, 2016, 02:03:50 pm »
Oh shit! Right! I forgot about system module! Thanks sir! Now everything is fine.  ::)
« Last Edit: December 01, 2016, 02:11:43 pm by jaqb17 »

 

anything