SFML community forums

General => General discussions => Topic started by: Arbaal on November 21, 2008, 10:31:33 am

Title: FindSFML for CMAKE
Post by: Arbaal on November 21, 2008, 10:31:33 am
I want to add a module to cmake for searching SFML. Before I will try to get it into the official CMAKE sources I ask here for tester.

I appended a simple program to test the module on your system and for showing how to bind it into your own program (if you are allready using cmake).

With this module it is possible to simply find SFML by using the following command:
Code: [Select]
Find_Package(SFML REQUIRED)

The module then set's following variables:
SFML_LIBRARY, the name of the library to link against
SFML_FOUND, if false, do not try to link to SFML
SFML_INCLUDE_DIR, where to find SFML headers

Asking for a specific version or a specific component is not yet possible.

Would be nice to get some feedback.

http://www.sendspace.com/file/341ed2
Title: FindSFML for CMAKE
Post by: geenux on January 28, 2009, 10:12:16 pm
Yeah, great work, it's just working like a charm under Debian GNU/Linux.
Very good, I can now use CMake with SFML, thanks.
Title: FindSFML for CMAKE
Post by: SamuraiCrow on January 28, 2009, 10:38:08 pm
It worked fine under XCode 3.1.2 on MacOSX 10.5.6.
Title: FindSFML for CMAKE
Post by: Emeric on June 19, 2009, 07:24:40 pm
The findsfml.cmake file is not available anymore on sendspace, is it still possible to get it ?

I'm a hudge fan of cmake and it would be great to easily use it with sfml.
Title: FindSFML for CMAKE
Post by: SamuraiCrow on June 27, 2009, 01:41:33 am
Here it is:

Code: [Select]

# Locate SFML library
# This module defines
# SFML_LIBRARY, the name of the library to link against
# SFML_FOUND, if false, do not try to link to SFML
# SFML_INCLUDE_DIR, where to find SFML headers
#
# Created by Nils Hasenbanck. Based on the FindSDL_*.cmake modules,
# created by Eric Wing, which were influenced by the FindSDL.cmake
# module, but with modifications to recognize OS X frameworks and
# additional Unix paths (FreeBSD, etc).

SET(SFML_COMPONENTS
    System
    Audio
    Graphics
    Network
    Window
)

SET(SFML_INCLUDE_SEARCH_DIR
    ~/Library/Frameworks
    /Library/Frameworks
    /usr/local/include/SFML
    /usr/include/SFML
    /usr/local/include
    /usr/include
    /sw/include/SFML # Fink
    /sw/include
    /opt/local/include/SFML # DarwinPorts
    /opt/local/include
    /opt/csw/include/SFML # Blastwave
    /opt/csw/include
    /opt/include/SFML
    /opt/include
)

SET(SFML_LIBRARY_SEARCH_DIR
    ~/Library/Frameworks
    /Library/Frameworks
    /usr/local
    /usr
    /sw
    /opt/local
    /opt/csw
    /opt
)

FOREACH(COMPONENT ${SFML_COMPONENTS})
    STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
    STRING(TOLOWER ${COMPONENT} LOWERCOMPONENT)
    FIND_LIBRARY(SFML_${UPPERCOMPONENT}_LIBRARY
        NAMES sfml-${LOWERCOMPONENT}
        HINTS
        $ENV{SFMLDIR}
        PATH_SUFFIXES lib64 lib
        PATHS ${SFML_LIBRARY_SEARCH_DIR}
    )
    FIND_PATH(SFML_${UPPERCOMPONENT}_INCLUDE_DIR ${COMPONENT}.hpp
        HINTS
        $ENV{SFMLDIR}
        PATH_SUFFIXES include
        PATHS ${SFML_INCLUDE_SEARCH_DIR}
    )
    IF(SFML_${UPPERCOMPONENT}_INCLUDE_DIR AND SFML_${UPPERCOMPONENT}_LIBRARY)
        LIST(APPEND SFML_LIBRARY ${SFML_${UPPERCOMPONENT}_LIBRARY})
        LIST(APPEND SFML_INCLUDE_DIR ${SFML_${UPPERCOMPONENT}_INCLUDE_DIR})
        LIST(REMOVE_DUPLICATES SFML_LIBRARY)
        LIST(REMOVE_DUPLICATES SFML_INCLUDE_DIR)
    ENDIF(SFML_${UPPERCOMPONENT}_INCLUDE_DIR AND SFML_${UPPERCOMPONENT}_LIBRARY)
ENDFOREACH(COMPONENT)

SET(SFML_FOUND "NO")
IF(SFML_SYSTEM_LIBRARY AND SFML_INCLUDE_DIR)
    SET(SFML_FOUND "YES")
ENDIF(SFML_SYSTEM_LIBRARY AND SFML_INCLUDE_DIR)

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SFML DEFAULT_MSG SFML_LIBRARY SFML_INCLUDE_DIR)
Title: thanks
Post by: Emeric on June 30, 2009, 06:35:50 pm
Thanks !
Working fine with Arch Linux.
Title: FindSFML for CMAKE
Post by: xarxer on December 18, 2009, 03:11:43 pm
Hey uhm..

I copy pasted what SamuraiCrow pasted, and put it in FindSFML.cmake and placed it in /usr/share/apps/cmake/modules/
but CMake says "Could not find module FindSFML.cmake or a configuration file for package SFML."

Did I place it wrong?
Ideas?

Thanks / Xarxer  :D
Title: FindSFML for CMAKE
Post by: xarxer on December 20, 2009, 10:05:12 am
Nevermind my previous post, I solved it..
It should be placed in /usr/share/cmake-2.8/Modules/..

Now I've run into another problem! :)

while setting
Code: [Select]
find_package(SFML REQUIRED) in the CMakeLists.txt, compiler says undefined reference to pretty much everything that has anything to do with SFML; sf::VideoMode::VideoMode(), sf::RenderWindow::RenderWindow() etc. etc.


Tried to add "SFML/Graphics.hpp" to the ADD_EXECUTABLE(), but this generates a lot of other errors..

Does anyone know what I'm doing wrong?

EDIT:

Well it seems I solved this one as well..
I had missed target_link_libraries()

 :)
Title: visual studio 2008
Post by: Osbios on April 04, 2010, 04:45:30 pm
I already played around with sfml and cmake on a ubuntu systems. I was supprised by the fact, that the original cmake on windows did not come with a sfml script.

So I ended up here...

...still there was no support for windows. So I add support for visual studo 2008.

You just have to set the the enviroment variable SFMLDIR to the SFML directory.
And make sure to have a SET(CMAKE_BUILD_TYPE Release) in your cmake project!!!
Because the vs compiler uses the debug option by default. You would end up with the release SFML components in a debug executable. That can cause unexpected behavior and crashes of you application!

I do not have that much experienc with cmake so this file is still limited to create release versions only. Maybe I add support for the debug files later.

I created working nmake files and vs2008 projects with this:

Save this file as "FindSFML.cmake"
Code: [Select]
# Locate SFML library
# This module defines
# SFML_LIBRARY, the name of the library to link against
# SFML_FOUND, if false, do not try to link to SFML
# SFML_INCLUDE_DIR, where to find SFML headers
#
# Created by Nils Hasenbanck. Based on the FindSDL_*.cmake modules,
# created by Eric Wing, which were influenced by the FindSDL.cmake
# module, but with modifications to recognize OS X frameworks and
# additional Unix paths (FreeBSD, etc).
#
# Changelog:
# 2010-04-04 Add support for wxWIN with visual studio 2008 (9.0)

SET( SFMLDIR $ENV{SFMLDIR} )
IF(MSVC)
# Convert backslashes to slashes
    STRING(REGEX REPLACE "\\\\" "/" SFMLDIR "${SFMLDIR}")
ENDIF(MSVC)

SET(SFML_COMPONENTS
    System
    Audio
    Graphics
    Network
    Window
)

SET(SFML_INCLUDE_SEARCH_DIR
    ~/Library/Frameworks
    /Library/Frameworks
    /usr/local/include/SFML
    /usr/include/SFML
    /usr/local/include
    /usr/include
    /sw/include/SFML # Fink
    /sw/include
    /opt/local/include/SFML # DarwinPorts
    /opt/local/include
    /opt/csw/include/SFML # Blastwave
    /opt/csw/include
    /opt/include/SFML
    /opt/include
    ${SFMLDIR}/include #for wxWIN vc2008(9.0)
)

SET(SFML_LIBRARY_SEARCH_DIR
    ~/Library/Frameworks
    /Library/Frameworks
    /usr/local
    /usr
    /sw
    /opt/local
    /opt/csw
    /opt
    ${SFMLDIR}/lib/vc2008 #for wxWIN vc2008(9.0)
)

FOREACH(COMPONENT ${SFML_COMPONENTS})
    STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
    STRING(TOLOWER ${COMPONENT} LOWERCOMPONENT)
    FIND_LIBRARY(SFML_${UPPERCOMPONENT}_LIBRARY
        NAMES sfml-${LOWERCOMPONENT}
        PATH_SUFFIXES lib64 lib
        PATHS ${SFML_LIBRARY_SEARCH_DIR}
    )
   
    FIND_PATH(SFML_${UPPERCOMPONENT}_INCLUDE_DIR ${COMPONENT}.hpp
        PATH_SUFFIXES include SFML
        PATHS ${SFML_INCLUDE_SEARCH_DIR}
    )
    IF(MSVC)
# In wxWIN we need the root include directory without the "/SFML" at the end... so we have to remove it.
# This is a oversized "remove 5 chars at the right end of the string" function:
string(LENGTH ${SFML_${UPPERCOMPONENT}_INCLUDE_DIR} STRING_SIZE)
math(EXPR STRING_SIZE ${STRING_SIZE}-5)
string(SUBSTRING "${SFML_${UPPERCOMPONENT}_INCLUDE_DIR}" 0 ${STRING_SIZE} SFML_${UPPERCOMPONENT}_INCLUDE_DIR)
ENDIF(MSVC)

    IF(SFML_${UPPERCOMPONENT}_INCLUDE_DIR AND SFML_${UPPERCOMPONENT}_LIBRARY)
        LIST(APPEND SFML_LIBRARY ${SFML_${UPPERCOMPONENT}_LIBRARY})
        LIST(APPEND SFML_INCLUDE_DIR ${SFML_${UPPERCOMPONENT}_INCLUDE_DIR})
        LIST(REMOVE_DUPLICATES SFML_LIBRARY)
        LIST(REMOVE_DUPLICATES SFML_INCLUDE_DIR)
    ENDIF(SFML_${UPPERCOMPONENT}_INCLUDE_DIR AND SFML_${UPPERCOMPONENT}_LIBRARY)
ENDFOREACH(COMPONENT)

IF(WIN32)
#Now we are looking for "sfml-main.lib".
#Because we need it if we give ADD_EXECUTABLE the WIN32 switch to creat a GUI application (that one without a cmd promt)
FIND_LIBRARY( SFML_MAIN_LIBRARY
NAMES sfml-main
PATH_SUFFIXES lib64 lib
PATHS ${SFML_LIBRARY_SEARCH_DIR}
)
LIST(APPEND SFML_LIBRARY ${SFML_MAIN_LIBRARY})
ENDIF(WIN32)

SET(SFML_FOUND "NO")
IF(SFML_SYSTEM_LIBRARY AND SFML_INCLUDE_DIR)
    SET(SFML_FOUND "YES")
ENDIF(SFML_SYSTEM_LIBRARY AND SFML_INCLUDE_DIR)

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SFML DEFAULT_MSG SFML_LIBRARY SFML_INCLUDE_DIR)


And before you all copy FindSFML.cmake in your cmake module directory here is a much more elegant way:

Create a directory like "cmake_modules" in you project directory and move the "FindSFML.cmake" there.

Then add the line set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules") to your "CMakeLists.txt".
Now you can use it with the regular Find_Package(SFML REQUIRED COMPONENTS System).

This is very useful because people that compile your project dont have to copy around the "FindSFML.cmake" script.

EDIT: I added the SFML_main lib so you dont get linking errors if you create windows GUI applications (the one without the cmd promt)
Title: FindSFML for CMAKE
Post by: Osbios on April 09, 2010, 11:18:17 pm
Here is an updated cmake find script with component testing and the possibility to chose betwin the debug/nondebug static/shared versions of SFML.

I made some big changes. So please test it!
And tell me if you did have any problems or if it works with your configuration and system.

Ohh... and please tell me what a configuration and system you use, too! ;)

Code: [Select]
# Locate SFML library
# This module defines
# SFML_FOUND, if false, do not try to link to SFML
# SFML_LIBRARY, the name of the librarys to link against
# SFML_INCLUDE_DIR, where to find SFML headers
#
# By default this script will link to the shared-nondebug version of SFML
# You can change this by define this variables befor calling FIND_PACKAGE
#
# SFML_DEBUG - If defined it will link to the debug version of SFML
# SFML_STATIC - If defined it will link to the static version of SFML
#
# For example:
# SET(SFML_STATIC true)
# FIND_PACKAGE(SFML REQUIRED COMPONENTS System Window)
#
# Created by Nils Hasenbanck. Based on the FindSDL_*.cmake modules,
# created by Eric Wing, which were influenced by the FindSDL.cmake
# module, but with modifications to recognize OS X frameworks and
# additional Unix paths (FreeBSD, etc).
#
# Changelog:
# 2010-04-04 - Add support for visual studio 2008 (9.0)
# 2010-04-09 - Add support for visual studio 2005 (8.0)
#            - Now the test for the requested components is also implemented.
#            - It also will only link to the requested components
#            - You can chose wich debug/nondebug static/shared versions of the librarys you want to link to

SET(SFML_LIBRARY "")
SET(SFML_INCLUDE_DIR "")

SET( SFMLDIR $ENV{SFMLDIR} )
IF(WIN32 AND NOT(CYGWIN))
# Convert backslashes to slashes
    STRING(REGEX REPLACE "\\\\" "/" SFMLDIR "${SFMLDIR}")
ENDIF(WIN32 AND NOT(CYGWIN))

SET(SFML_COMPONENTS
    System
    Audio
    Graphics
    Network
    Window
)

SET(SFML_MODE
_SHARED_NONDEBUG
_SHARED_DEBUG
_STATIC_NONDEBUG
_STATIC_DEBUG
)

SET(SFML_INCLUDE_SEARCH_DIR
    ~/Library/Frameworks
    /Library/Frameworks
    /usr/local/include/SFML
    /usr/include/SFML
    /usr/local/include
    /usr/include
    /sw/include/SFML # Fink
    /sw/include
    /opt/local/include/SFML # DarwinPorts
    /opt/local/include
    /opt/csw/include/SFML # Blastwave
    /opt/csw/include
    /opt/include/SFML
    /opt/include
    ${SFMLDIR}
    ${SFMLDIR}/include
)

SET(SFML_LIBRARY_SEARCH_DIR
    ~/Library/Frameworks
    /Library/Frameworks
    /usr/local
    /usr
    /sw
    /opt/local
    /opt/csw
    /opt
    ${SFMLDIR}
    ${SFMLDIR}/lib/vc2008
    ${SFMLDIR}/lib/vc2005
)

#looking for the include files
FOREACH(COMPONENT ${SFML_COMPONENTS})
STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
STRING(TOLOWER ${COMPONENT} LOWERCOMPONENT)

FIND_PATH(SFML_${UPPERCOMPONENT}_INCLUDE_DIR
${COMPONENT}.hpp
PATH_SUFFIXES include SFML
PATHS ${SFML_INCLUDE_SEARCH_DIR}
)

IF(SFML_${UPPERCOMPONENT}_INCLUDE_DIR)
IF(WIN32)
# In wxWIN we need the root include directory without the "/SFML" at the end... so we have to remove it.
# This is a oversized "remove 5 chars at the right end of the string" function:
string(LENGTH ${SFML_${UPPERCOMPONENT}_INCLUDE_DIR} STRING_SIZE)
math(EXPR STRING_SIZE ${STRING_SIZE}-5)
string(SUBSTRING "${SFML_${UPPERCOMPONENT}_INCLUDE_DIR}" 0 ${STRING_SIZE} SFML_${UPPERCOMPONENT}_INCLUDE_DIR)
ENDIF(WIN32)

LIST(APPEND SFML_INCLUDE_DIR ${SFML_${UPPERCOMPONENT}_INCLUDE_DIR})
LIST(REMOVE_DUPLICATES SFML_INCLUDE_DIR)
ENDIF(SFML_${UPPERCOMPONENT}_INCLUDE_DIR)
ENDFOREACH(COMPONENT)

#looking for the librarys
FOREACH(MODE ${SFML_MODE})
string(COMPARE EQUAL ${MODE} "_SHARED_NONDEBUG" string_equal_result)
IF(string_equal_result)
SET(_STA "")
SET(_DBG "")
ENDIF(string_equal_result)

string(COMPARE EQUAL ${MODE} "_SHARED_DEBUG" string_equal_result)
IF(string_equal_result)
SET(_STA "")
SET(_DBG "-d")
ENDIF(string_equal_result)

string(COMPARE EQUAL ${MODE} "_STATIC_NONDEBUG" string_equal_result)
IF(string_equal_result)
SET(_STA "-s")
SET(_DBG "")
ENDIF(string_equal_result)

string(COMPARE EQUAL ${MODE} "_STATIC_DEBUG" string_equal_result)
IF(string_equal_result)
SET(_STA "-s")
SET(_DBG "-d")
ENDIF(string_equal_result)

FOREACH(COMPONENT ${SFML_COMPONENTS})
STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
STRING(TOLOWER ${COMPONENT} LOWERCOMPONENT)
FIND_LIBRARY(SFML_${UPPERCOMPONENT}_LIBRARY${MODE}
NAMES sfml-${LOWERCOMPONENT}${_STA}${_DBG}
PATH_SUFFIXES lib64 lib
PATHS ${SFML_LIBRARY_SEARCH_DIR}
)
ENDFOREACH(COMPONENT)

IF(WIN32)
#Now we are looking for "sfml-main.lib".
#Because we need it if we give ADD_EXECUTABLE the WIN32 switch to creat a GUI application (that one without a cmd promt)
FIND_LIBRARY( SFML_MAIN_LIBRARY${MODE}
NAMES sfml-main${_DBG}
PATH_SUFFIXES lib64 lib
PATHS ${SFML_LIBRARY_SEARCH_DIR}
)
ENDIF(WIN32)
ENDFOREACH(MODE)


#Test if we have the include directory, the system lib and other needed components
#We also fill SFML_LIBRARY here with all the files we like to link to

IF(NOT(SFML_DEBUG) AND NOT(SFML_STATIC))
SET(MODE_LABEL "_SHARED_NONDEBUG")
ENDIF(NOT(SFML_DEBUG) AND NOT(SFML_STATIC))

IF(SFML_DEBUG AND NOT(SFML_STATIC))
SET(MODE_LABEL "_SHARED_DEBUG")
ENDIF(SFML_DEBUG AND NOT(SFML_STATIC))

IF(NOT(SFML_DEBUG) AND SFML_STATIC)
SET(MODE_LABEL "_STATIC_NONDEBUG")
ENDIF(NOT(SFML_DEBUG) AND SFML_STATIC)

IF(SFML_DEBUG AND SFML_STATIC)
SET(MODE_LABEL "_STATIC_DEBUG")
ENDIF(SFML_DEBUG AND SFML_STATIC)

LIST(APPEND SFML_LIBRARY ${SFML_MAIN_LIBRARY${MODE_LABEL}})

LIST(APPEND SFML_FIND_COMPONENTS "System") #We allways need at last the System component
LIST(REMOVE_DUPLICATES SFML_FIND_COMPONENTS)

SET(SFML_FOUND "YES")
FOREACH(COMPONENT ${SFML_FIND_COMPONENTS})
SET( MODUL_NAME SFML_${COMPONENT}_LIBRARY${MODE_LABEL} )
STRING(TOUPPER ${MODUL_NAME} MODUL_NAME)

IF(NOT ${MODUL_NAME})
SET(SFML_FOUND "NO")
MESSAGE("-- SFML: Could not locate : ${MODUL_NAME}")
ELSE(NOT ${MODUL_NAME})
LIST(APPEND SFML_LIBRARY ${${MODUL_NAME}})
ENDIF(NOT ${MODUL_NAME})
ENDFOREACH(COMPONENT)

LIST(REMOVE_DUPLICATES SFML_LIBRARY)

IF(NOT SFML_INCLUDE_DIR)
SET(SFML_FOUND "NO")
MESSAGE("-- SFML: Could not locate include directory")
ENDIF(NOT SFML_INCLUDE_DIR)

IF(NOT SFML_FOUND)
MESSAGE(FATAL_ERROR "Components of SFML are missing!")
ENDIF(NOT SFML_FOUND)

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SFML DEFAULT_MSG SFML_LIBRARY SFML_INCLUDE_DIR)
Title: FindSFML for CMAKE
Post by: Svenstaro on April 11, 2010, 07:08:04 am
Awesome work. Can you try and bug CMake to put it into their official releases? CMake 3.0 is coming and it would be neat to have this .cmake script in there.
Title: FindSFML for CMAKE
Post by: Osbios on April 11, 2010, 03:10:03 pm
I like to get some feedback befor I try to get it in any official package.

If you find it so awesome did you use it? What System  was it? I guess it did run just fine?
Title: FindSFML for CMAKE
Post by: Svenstaro on April 11, 2010, 08:38:47 pm
I did work quite well in two of my projects, both Arch Linux x86_64 using my AUR SFML package.
Title: FindSFML for CMAKE
Post by: mongrol on April 14, 2010, 02:50:33 am
Osbios,
Also worked great here. Also on Archlinux i686 using Svenstaro's SFML package from AUR. Much better than the previous script too as I can now do a proper find package for individual components. Well done.
Title: FindSFML for CMAKE
Post by: Kolja on September 28, 2010, 02:25:05 pm
Doesn't work for me.

The problem is the linking, SFML_LIBRARY is set to
Code: [Select]
/Library/Frameworks/sfml-system.framework

I'm on OS X (10.6) obviously. /Library/Frameworks contains every sfml-<module>.framework, as well as SFML.framework.

An earlier version I tried (the first one posted inline here I believe) worked fine.

Can't see the fix from a first glance though, I'd expect the foreach loop to fill SFML_LIBRARY a bit more. But I only know cmake since yesterday, so no surprise there.

[edit]
http://www.sfml-dev.org/forum/viewtopic.php?p=15578#15578 still works fine. So it broke in the last version.
Title: FindSFML for CMAKE
Post by: Svenstaro on October 08, 2010, 12:37:49 am
You should probably also add ${SFMLDIR}/lib/mingw to the FindSFML.cmake for the next "release".
Title: FindSFML for CMAKE
Post by: Laurent on October 08, 2010, 08:07:27 am
By the way, I added my own FindSFML.cmake to the repository for SFML 2.0.
Title: FindSFML for CMAKE
Post by: Osbios on October 27, 2010, 07:53:57 pm
@Kolja:
Sorry for the late answer.

I never worked with OS X oe Mac, so I have no clue what the SFML_LIBRARY is supposed to look like. If you give me some more informations I can "try" to fix this.

What does the working SFML_LIBRARY looks like?
Title: FindSFML for CMAKE
Post by: Fierce_Dutch on November 17, 2010, 04:44:54 am
Quote from: "Laurent"
By the way, I added my own FindSFML.cmake to the repository for SFML 2.0.


Ok I have the SVN repository of sfml 2 and I am going to go download Cmake. So what do I do with cmake, i am confused from the previous posts and I couldn't find that file in my sfml folder.
Title: FindSFML for CMAKE
Post by: Laurent on November 17, 2010, 07:51:43 am
Quote
So what do I do with cmake

You read tutorials? ;)

Quote
I couldn't find that file in my sfml folder

It's under cmake/Modules. It automatically installs to the CMake folder when you install SFML.
Title: FindSFML for CMAKE
Post by: Fierce_Dutch on November 18, 2010, 12:42:19 am
Quote from: "Laurent"
Quote
So what do I do with cmake

You read tutorials? ;)

Quote
I couldn't find that file in my sfml folder

It's under cmake/Modules. It automatically installs to the CMake folder when you install SFML.


I did read the tutorials but I am really confused with all of this because my svn repository download has nothing that says sfml 2. so.......... Ya and what do you mean by instal sfml?
Title: FindSFML for CMAKE
Post by: Fierce_Dutch on November 18, 2010, 12:44:02 am
I actaully have been in the trunk the whole time in the repository. SO lets see here. I open cmake and open the cmake file in there?
Title: FindSFML for CMAKE
Post by: Fierce_Dutch on November 18, 2010, 01:02:42 am
Ok I have downloaded cmake and all i have is files. No exe or anything. I have tried running the vcvars32.bat and it opens and closes and doesn't let me type in cmake.. So what do i do??
Title: FindSFML for CMAKE
Post by: Fierce_Dutch on November 18, 2010, 07:16:54 am
I have cmake and I have the repository and everything and I am following the tutorial as best as I can but generate doesnt't show up on cmake
Title: FindSFML for CMAKE
Post by: Laurent on November 18, 2010, 08:07:09 am
Quote
but generate doesnt't show up on cmake

What do you mean? The "Generate" button? Then you probably have errors (in the log area below the buttons).

PS: no need to quote the same message again and again in all your messages ;)
Title: FindSFML for CMAKE
Post by: Fierce_Dutch on November 19, 2010, 02:57:15 am
Quote from: "Laurent"
Quote
but generate doesnt't show up on cmake

What do you mean? The "Generate" button? Then you probably have errors (in the log area below the buttons).

PS: no need to quote the same message again and again in all your messages ;)


ok now i got the files and everything and i put the libs in the linker of vc++.Then when I run a simple program to open a window, it says, sfml-window-d-2.dll is missing from your computer, and it's not! I made a solution with cmake then compiled everything in vc++ and put all the libs and include diretories in their correct place. ANd in the linker and vc++ directories area in vc++ 2010 i added the correct folders to the lib and executable directories and the include directories in there on the right debug or realease options. An din the linker input i inlcuded all the sfml-window-d.lib files and such for the release and debug but it still doesn't work. HELP!?!
Title: FindSFML for CMAKE
Post by: Laurent on November 19, 2010, 08:01:29 am
This has nothing to do with compiler or linker setup, these two steps complete successfully.

Now your executable needs to access the SFML DLLs to execute the functions they contain, so the DLLs must be in a known path when you run it. And known paths are the executable path, plus everything which is listed in the PATH environment variable.

And if you don't want to be bothered with DLLs, you can also choose to build SFML static libraries.
Title: FindSFML for CMAKE
Post by: Fierce_Dutch on November 19, 2010, 04:21:45 pm
Quote from: "Laurent"
This has nothing to do with compiler or linker setup, these two steps complete successfully.

Now your executable needs to access the SFML DLLs to execute the functions they contain, so the DLLs must be in a known path when you run it. And known paths are the executable path, plus everything which is listed in the PATH environment variable.

And if you don't want to be bothered with DLLs, you can also choose to build SFML static libraries.


Ok well i did intclude the executable path and such in vc++ 2010 but i guess i will just build statically. How do i do that?
Title: FindSFML for CMAKE
Post by: Laurent on November 19, 2010, 04:22:30 pm
Quote
i guess i will just build statically. How do i do that?

It is explained in the CMake tutorial.
Title: FindSFML for CMAKE
Post by: Fierce_Dutch on November 20, 2010, 03:38:39 am
Quote from: "Laurent"
Quote
i guess i will just build statically. How do i do that?

It is explained in the CMake tutorial.


Ok in cmake I changed the build type to static and added static and in the options area i added it too. Then i compiled the sfml thing in vc++ statically and then i included that library as my release option and it still said my dll is missing.
Title: FindSFML for CMAKE
Post by: Laurent on November 20, 2010, 09:07:02 am
The static libraries have the -s suffix (sfml-system-s, sfml-window-s, etc.).
Title: FindSFML for CMAKE
Post by: Fierce_Dutch on November 20, 2010, 05:59:39 pm
Quote from: "Laurent"
The static libraries have the -s suffix (sfml-system-s, sfml-window-s, etc.).


Not in my folder, they are just normal..... Can you help me outwith the cmake part? I think i have failed there. And i havent been able to test anything for the past 4 days.. :(
Title: FindSFML for CMAKE
Post by: Laurent on November 20, 2010, 07:22:19 pm
Quote
Not in my folder, they are just normal.....

So you compiled the dynamic libraries.

Quote
Can you help me outwith the cmake part?

Sure. Tell me exactly what you did, and I'll tell you what's wrong.
Title: FindSFML for CMAKE
Post by: Fierce_Dutch on November 20, 2010, 07:44:11 pm
Quote from: "Laurent"
Quote
Not in my folder, they are just normal.....

So you compiled the dynamic libraries.

Quote
Can you help me outwith the cmake part?

Sure. Tell me exactly what you did, and I'll tell you what's wrong.


Here
I generated that and got the normla libs. I only used the two things i circled

(http://img151.imageshack.us/img151/4140/staticlibraries.png)
Title: FindSFML for CMAKE
Post by: Laurent on November 20, 2010, 08:08:09 pm
Well, what about reading the tutorial (http://www.sfml-dev.org/tutorials/2.0/compile-with-cmake.php) first? ;)

PS: you could make your image less large, it makes some of the forum buttons go outside the visible area. We don't need all that empty space.
Title: FindSFML for CMAKE
Post by: Fierce_Dutch on November 20, 2010, 08:21:25 pm
Quote from: "Laurent"
Well, what about reading the tutorial (http://www.sfml-dev.org/tutorials/2.0/compile-with-cmake.php) first? ;)

PS: you could make your image less large, it makes some of the forum buttons go outside the visible area. We don't need all that empty space.


Sorry about the image but where in the tutorial does it say how to build it statically in cmake? Visula studio doesn't give me all the options like you said it would btw
Title: FindSFML for CMAKE
Post by: Laurent on November 20, 2010, 08:23:35 pm
Quote
where in the tutorial does it say how to build it statically in cmake?

There:
Quote from: "tutorial"
BUILD_SHARED_LIBS
This boolean option controls whether you build the dynamic (shared) libraries of SFML, or the static ones.


Quote
Visula studio doesn't give me all the options like you said it would btw

Where did I say that?
Title: FindSFML for CMAKE
Post by: Fierce_Dutch on November 20, 2010, 08:29:02 pm
Quote from: "Laurent"
Quote
where in the tutorial does it say how to build it statically in cmake?

There:
Quote from: "tutorial"
BUILD_SHARED_LIBS
This boolean option controls whether you build the dynamic (shared) libraries of SFML, or the static ones.


Quote
Visula studio doesn't give me all the options like you said it would btw

Where did I say that?


I tried that just now and when i opened up the project it said that only system and main loaded
Title: FindSFML for CMAKE
Post by: Laurent on November 20, 2010, 09:01:40 pm
Do you mean that other projects contain errors? Which ones?
Title: FindSFML for CMAKE
Post by: Fierce_Dutch on November 20, 2010, 09:30:03 pm
Quote from: "Laurent"
Do you mean that other projects contain errors? Which ones?


No i generated the project for sfml and i tried both of the projects and the solution. (ALL_BUILD, INSTALL, and SFML solution) When i tried to open them in visual c++ 2010 it said it could not load these four things and here is the error:

Code: [Select]
C:\SFML\build\src\SFML\Audio\sfml-audio.vcxproj : error  : Unable to read the project file "sfml-audio.vcxproj".
C:\SFML\build\src\SFML\Audio\sfml-audio.vcxproj(112,29): The project file could not be loaded. An error occurred while parsing EntityName. Line 112, position 29.

C:\SFML\build\src\SFML\Graphics\sfml-graphics.vcxproj : error  : Unable to read the project file "sfml-graphics.vcxproj".
C:\SFML\build\src\SFML\Graphics\sfml-graphics.vcxproj(112,29): The project file could not be loaded. An error occurred while parsing EntityName. Line 112, position 29.

C:\SFML\build\src\SFML\Network\sfml-network.vcxproj : error  : Unable to read the project file "sfml-network.vcxproj".
C:\SFML\build\src\SFML\Network\sfml-network.vcxproj(112,29): The project file could not be loaded. An error occurred while parsing EntityName. Line 112, position 29.

C:\SFML\build\src\SFML\Window\sfml-window.vcxproj : error  : Unable to read the project file "sfml-window.vcxproj".
C:\SFML\build\src\SFML\Window\sfml-window.vcxproj(112,29): The project file could not be loaded. An error occurred while parsing EntityName. Line 112, position 29.

Title: FindSFML for CMAKE
Post by: Laurent on November 20, 2010, 11:02:09 pm
Do you use the latest revision of SFML? This kind of problem was fixed a few weeks ago.

http://www.sfml-dev.org/forum/viewtopic.php?t=3519
Title: FindSFML for CMAKE
Post by: Fierce_Dutch on November 21, 2010, 12:01:09 am
Quote from: "Laurent"
Do you use the latest revision of SFML? This kind of problem was fixed a few weeks ago.

http://www.sfml-dev.org/forum/viewtopic.php?t=3519


Ok I did everything and now when I try to run it in a program i get this:

Code: [Select]
1>------ Build started: Project: Easy_Image_Handler, Configuration: Debug Win32 ------
1>Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::RenderWindow::~RenderWindow(void)" (__imp_??1RenderWindow@sf@@UAE@XZ) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::Display(void)" (__imp_?Display@Window@sf@@QAEXXZ) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::RenderTarget::Clear(class sf::Color const &)" (__imp_?Clear@RenderTarget@sf@@QAEXABVColor@2@@Z) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Color::Color(unsigned char,unsigned char,unsigned char,unsigned char)" (__imp_??0Color@sf@@QAE@EEEE@Z) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Window::IsOpened(void)const " (__imp_?IsOpened@Window@sf@@QBE_NXZ) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::Create(class sf::VideoMode,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned long,struct sf::ContextSettings const &)" (__imp_?Create@Window@sf@@QAEXVVideoMode@2@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@KABUContextSettings@2@@Z) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (__imp_??0VideoMode@sf@@QAE@III@Z) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::RenderWindow::RenderWindow(void)" (__imp_??0RenderWindow@sf@@QAE@XZ) referenced in function _main
1>C:\Users\kid account\Documents\Visual Studio 2010\Projects\Easy_Image_Handler\Debug\Easy_Image_Handler.exe : fatal error LNK1120: 8 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========




I know i missed some stuff but this code should work.
Here is my code:

Code: [Select]
#include <SFML\Graphics.hpp>



int main()
{

sf::RenderWindow App;
App.Create(sf::VideoMode(800,600,8),"Hello");




// Start game loop
    while (App.IsOpened())
    {

App.Clear();
App.Display();
}
}
Title: FindSFML for CMAKE
Post by: Laurent on November 21, 2010, 12:08:28 am
Quote
I did that and now its's not building the dll's in vc++

Can you give more details when you have a new error? It's not easy to help you if I have to guess what you did and what happens.
Title: FindSFML for CMAKE
Post by: Fierce_Dutch on November 21, 2010, 12:12:49 am
Quote from: "Laurent"
Quote
I did that and now its's not building the dll's in vc++

Can you give more details when you have a new error? It's not easy to help you if I have to guess what you did and what happens.


Look above at my edited post
Title: FindSFML for CMAKE
Post by: Laurent on November 21, 2010, 12:25:00 am
You have to define SFML_STATIC to work with static libraries.
Title: FindSFML for CMAKE
Post by: Fierce_Dutch on November 21, 2010, 12:28:54 am
Quote from: "Laurent"
You have to define SFML_STATIC to work with static libraries.


Praise the Lord! I got it working thanks so much. HEY I will make a video tutorial about this for you if you would like.. I am guessing a lot of people have these questions. Unless I am the only idiot.... :)
Title: FindSFML for CMAKE
Post by: Laurent on November 21, 2010, 10:26:07 am
You're not an idiot, this SFML 2 stuff is very recent and I haven't written any tutorial about it yet (except the CMake one). So I expect people to ask such questions if they work with the latest SFML 2 revisions ;)

But don't worry, everything will be ready when SFML 2 is publicly out.
Title: FindSFML for CMAKE
Post by: dayday on July 12, 2011, 09:22:40 pm
Thank you man, you FindSFML module is fantastic, it helps a lot!