configure SFML for clion (windows) - c++

i am setting up a work environment for a school project on my windows computer. We are going to make a basic game using c++ and CLion. To make a game i need to use the SFML library. I have followed a few tutorials but i cant seem to get it to work anyway.
I have:
Downloaded CLion and configured it with MinGW
Downloaded SFML and copied its "findSFML.cmake" file to a new directory in my project that i call cmake_modules.
Edited my CMakeLists.txt file so it looks like this:
cmake_minimum_required(VERSION 3.6)
project(testet)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(testet ${SOURCE_FILES})
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")
find_package(SFML REQUIRED system window graphics network audio)
if (SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(testet ${SFML_LIBRARIES})
endif()
These are the three steps that i see on every tutorial / answer. But I get the following error anyway:
"C:\Program Files (x86)\JetBrains\CLion 2016.3\bin\cmake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\Benjamin\ClionProjects\testet
CMake Error at cmake_modules/FindSFML.cmake:355 (message):
Could NOT find SFML (missing: SFML_SYSTEM_LIBRARY SFML_WINDOW_LIBRARY
SFML_GRAPHICS_LIBRARY SFML_NETWORK_LIBRARY SFML_AUDIO_LIBRARY)
Call Stack (most recent call first):
CMakeLists.txt:10 (find_package)
So it cant find the SFML? But should'nt the "findSFML.cmake" solve this? Any help is appretiated... Thanks! :D

I believe you are missing the link_directories() call. You can use it like this:
link_directories("C:/Path_To_Library")
This should help solve your issue.

I have successfully configured SFML with CLion on Ubuntu 16.04 and I think it will be same for Window user also.
My project name is SFML_TEST so change every occurrence of SFML_TEST with your project name.
Create a new Clion C++ Project.
Navigate to /path/to/CLionProjects/[Project_Name]/CMakeLists.txt
After the following statement
add_executable(SFML_TEST ${SOURCE_FILES})
Add following lines of code
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")
find_package(SFML REQUIRED system window graphics network audio)
if (SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(SFML_TEST ${SFML_LIBRARIES})
endif()
Create a new directory /path/to/CLionProjects/[project_name]/cmake_modules/FindSFML.cmake
In FindSFML.cmake file paste the following line of code from the given file https://github.com/SFML/SFML/blob/master/cmake/Modules/FindSFML.cmake
Done!!!.. Happy Coding

my fix was, that I had to change the root path of SFML in the FindSFML.cmake
so just set(SFML_ROOT Z://your_project) after the block of comments and you are ready to go

Related

Using OpenCV on windows and Clion

So I'm trying to use OpenCV on windows (my ubunut is broken) and I can't configure my Clion to compile my openCV code.
first; i'm completely new to OpenCV so this question might be an easy one but I did all I could to find the problem to no avail.
I used MinGW and Clion and my codes run with no problem if I don't use OpenCv which indicates there's no problem with MinGW installation.
I downloaded OpenCv files and extracted them, then added them to System path.
after that I configured my Cmakelists.txt (my first time modifying it, so I was an amateur) like this.
After that I got this error:
Error:By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this
project has asked CMake to find a package configuration file provided
by "OpenCV", but CMake did not find one. Could not find a package
configuration file provided by "OpenCV" with any of the following
names: OpenCVConfig.cmake opencv-config.cmake Add the installation
prefix of "OpenCV" to CMAKE_PREFIX_PATH or set "OpenCV_DIR" to a
directory containing one of the above files. If "OpenCV" provides a
separate development package or SDK, be sure it has been installed.
I know I'm doing something wrong or missing a step but I can't figure out why. is there any guide or tutorial for my scenario or can anyone point me towards a correct direction?
thanks in advance and any help appreciated.
I managed to make those errors go away with changing my
CMakeLists.txt to:
cmake_minimum_required(VERSION 3.5)
project(something)
set(OpenCV_DIR "E:/Programs/programming/opencv/build2") find_package( OpenCV REQUIRED )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp) add_executable(something ${SOURCE_FILES})
add_executable( {SOURCE_FILES} DisplayImage ) target_link_libraries( ${OpenCV_LIBS} DisplayImage )
and building the libraries on my own by minGW and Cmake.

Setup CMake with SFML in VS2017

Just like in CLion I want to use SFML with Visual Studio 2017, but I'm still learning cmake and I don't know the commands or the logic of how cmake works at all. I've just seen some posts and got this litle script.
Note: I downloaded the latest version of sfml in the link provided, I just taked the extrated directory and put alongside CMakeLists.txt in my folder
#sets up the minimum version of cmake
cmake_minimum_required(VERSION 3.9)
#how the project will be called
project (space_impact)
#set c++11 standard
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" -std=c++11)
#set source files
set (SOURCE_FILES main.cpp)
#we add the executable of the program
add_executable (space_impact ${SOURCE_FILES})
#taked from a mac-clion tutorial, doesn't work
set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/SFML/cmake-modules/")
find_package (SFML REQUIRED system window graphics network audio)
if (SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(space_impact ${SFML_LIBRARIES})
endif()
that thing gave me errors:
Error CMake Error at SFML/cmake-modules/FindSFML.cmake:355 (message):
Could NOT find SFML (missing: SFML_SYSTEM_LIBRARY SFML_WINDOW_LIBRARY
SFML_GRAPHICS_LIBRARY SFML_NETWORK_LIBRARY SFML_AUDIO_LIBRARY) SFML/cmake-modules/FindSFML.cmake
I want everything to be dynamic, but I don't know how can I do that..
So my question is what should I do for setting up correctly SFML with Cmake in Visual Studio.
I don't want the old-fashioned method from the official website
UPDATE
Here's my location....
The thing is.. the FindSFML.cmake script it's not working...
What files should I move for make it working?
Your script is perfectly fine, except three things I'd change:
Move the whole module detection before defining targets. I'm pretty sure you also have to define your include directories before.
Your if(SFML_FOUND) bracket is pretty pointless right now, because you've set SFML to be required, which means it will never get past find_package() unless it's found.
-std=c++11 is a GCC only flag (MSVC will always use the latest standard, unless specified). As such you'll have to check the compiler here or use CMAKE_CXX_STANDARD.
So the "cleaned" CMakeLists.txt could look like this:
#sets up the minimum version of cmake
cmake_minimum_required(VERSION 3.9) # personally I'd set this version as low as required; you don't have to require the cutting edge version
#how the project will be called
project (space_impact)
#set the C++ standard to be used
set (CMAKE_CXX_STANDARD 11)
#set source files
set (SOURCE_FILES main.cpp)
#look for SFML and add it
set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/SFML/cmake-modules/")
find_package (SFML REQUIRED system window graphics network audio)
include_directories(${SFML_INCLUDE_DIR})
#we add the executable of the program
add_executable (space_impact ${SOURCE_FILES})
target_link_libraries(space_impact ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
Note that adding SFML_DEPENDENCIES to the library list is optional, unless you're using a static version of SFML.
But what about your SFML issue? Since you don't have the SFML files installed in any directory looked into by default, you'll have to tell CMake where it's found using the CMake variable SFML_ROOT or the environment variable of the same name.
So the first time you're invoking CMake, it could look like this:
cmake -G "Visual Studio 15 2017" -DSFML_ROOT=path/to/sfml path/to/source
This is all you need to compile sfml in your cmake project.
find_package(SFML 2.5.1 COMPONENTS system graphics audio network REQUIRED)
add_executable (AwesomeProject "AwesomeProject.cpp" "AwesomeProject.h")
target_link_libraries(AwesomeProject PRIVATE sfml-audio sfml-graphics sfml-network sfml-system)
Also set SFML_DIR var to your sfml folder.

CLion unable to recognize OpenCV libraries (no IntelliSense)

I am trying to solve this thing for quite some time. After a few hours I just decided to post a question because I am out of ideas. I imported a project into CLion with the CMakeLists.txt already inside. I am working on ubuntu and have the newest cmake version (3.5.something, OpenCV is 2.4.x). I use clion just for the IntelliSense, I wont be using it for the compilation anyway (I use terminal for that).
By opening the project I get following warning messages (which I somehow succeeded to reduce to warnings). This happens for every add_library line in OpenCVModules.cmake (I post just one of them):
CMake Warning (dev) at /usr/local/share/OpenCV/OpenCVModules.cmake:53 (add_library):
ADD_LIBRARY called with SHARED option but the target platform does not
support dynamic linking. Building a STATIC library instead. This may lead
to problems.
Has anyone got ideas?
#CMakeLists.txt
# OpenCV:
find_package(OpenCV REQUIRED)
include_directories(${OPENCV_INCLUDE_DIR})
IF(OpenCV_FOUND)
MESSAGE(STATUS "OpenCV_LIBS = ${OpenCV_LIBS}")
ELSE(OpenCV_FOUND)
MESSAGE(STATUS "OpenCV_LIBS not found!")
ENDIF(OpenCV_FOUND)
project(cvtask1a)
file(GLOB SOURCES ${SOURCE_WILDCARDS})
include_directories(${CMAKE_SOURCE_DIR}/cgcvcommon)
add_executable(cvtask1a ${SOURCES})
target_link_libraries(cvtask1a ${OpenCV_LIBS})

How to use SFML libraries with Clion on Windows10

i'm trying to use SFML's library with CLion for a school project. I'm still not confident with programming and i am new to Clion.
After having download the library from SFML official site i read some tutorials, but i am a bit confused:
https://www.sfml-dev.org/tutorials/2.4/
Infact in the Getting Started section there are two voice that concern me: "Compiling with Cmake" and "..Code::Blocks (MinGW).
Well i tryed both but with no results, then i landed here.
I saw a topic that helped a bit configure SFML for clion (windows)
so i tried to follow the steps suggested.
The library is in C:\SFML-2.4.2
I copied FindSFML.cmake in SFMLProjects, located in C:\Users\Ludovico\ (the same path of the folder ClionProjects)
Then i gave it a try
cmake_minimum_required(VERSION 3.6)
project(provaSfml)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(provaSfml ${SOURCE_FILES})
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/SFMLProjects")
link_directories(C:/SFML-2.4.2/bin)
find_package(SFML REQUIRED system window graphics network audio)
if (SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(provaSfml ${SFML_LIBRARIES})
endif ()
These are the error messages
"C:\Program Files (x86)\JetBrains\CLion 2016.3.2\bin\cmake\bin\cmake.exe" - DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\Ludovico\CLionProjects\provaSfml
CMake Error at CMakeLists.txt:10 (find_package):
By not providing "FindSFML.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "SFML", but
CMake did not find one.
Could not find a package configuration file provided by "SFML" with any of
the following names:
SFMLConfig.cmake
sfml-config.cmake
Add the installation prefix of "SFML" to CMAKE_PREFIX_PATH or set
"SFML_DIR" to a directory containing one of the above files. If "SFML"
provides a separate development package or SDK, be sure it has been
installed.
I'm thinking i did some mistakes even in the organization of folder...
can someone tell me some advice in order to clean the mess i have in my head?
What can i do to fix these problems?

Missing sfml libraries for cmake

C++ newbie here, I'm trying to implement SFML library for CLion (Win 10).
I followed this http://www.sfml-dev.org/tutorials/2.0/compile-with-cmake.php guidelines and installed sfml using cmake gui and mingw.
Now when I try to include SMF libraries to project in CMakeLists.txt
cmake_minimum_required(VERSION 3.6)
project(untitled2)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(untitled2 ${SOURCE_FILES})
set(CMAKE_MODULE_PATH "C:/Program Files (x86)/SFML/cmake/Modules"${CMAKE_MODULE_PATH})
set(SFML_STATIC_LIBRARIES TRUE)
find_package(SFML COMPONENTS graphics window system REQUIRED)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(First ${SFML_Libraries})
Howewer, i'm getting an error
CMake Error at C:/Program Files (x86)/SFML/cmake/Modules/FindSFML.cmake:355 (message):
SFML found but some of its dependencies are missing ( FreeType libjpeg)
Call Stack (most recent call first):
CMakeLists.txt:13 (find_package)
But I thought those libs are included in Windows. I am doing something wrong? Where should I place FreeType and libjpeg files if I were to download them?
You shouldn't set any local system specific things (like paths) in your CMakeLists.txt. This defeats the whole purpose of a build system.
First, I'd suggest you create a sub directory "cmake" in your project and copy SFML's FindSFML.cmake module in there.
Then update your CMAKE_MODULE_PATH accordingly:
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
This will ensure the module is found. CMake's default modules are always found, you don't have to preserve the previous value of the variable (should typically be empty anyway).
Next, when creating your actual project files, you'll just have to pass SFML_ROOT to CMake, for example:
cmake "-DSFML_ROOT=C:/Program Files (x86)/SFML" path/to/source
In a similar way, you shouldn't set SFML_STATIC_LIBRARIES in your CMakeLists.txt unless you're somehow forced to use static libraries. So I'd actually add that to the command line as well:
cmake "-DSFML_ROOT=C:/Program Files (x86)/SFML" -DSFML_STATIC_LIBRARIES=TRUE path/to/source
You only have to set these once, they're stored in your CMakeCache.txt file later.
Last but not least, if you'd like to support static linking with SFML, you'll have to link SFML's dependencies as well:
target_link_libraries(First ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
Note that all these won't fix the error message you're getting. For some reason SFML's prebuilt dependencies aren't in C:\Program Files (x86)\SFML\lib. Are you sure you've got the correct prebuilt package?