1
General / Re: Trouble linking libraries with Cmake
« on: November 23, 2016, 04:17:21 am »
Ok I went back and built SFML myself with the static options now my Cmake file is saying that it can't find the dependencies...
Is there a flag in cmake I am missing? Or is there a variable in cmakelist that I need to find the external dependencies?
EDIT: Nevermind I found it I had to point to the /install/ directory of my SFML folder based on the tutorial.
MAN was that a pain, I got it working now but I know very little on the in betweens of programming with cmake....
For future people trying to get Clion to work with SFML let me make it as cut and dry as possible.....
1. Download SFML source and put it in a folder.
2. Follow THIS:https://github.com/SFML/SFML/wiki/Tutorial:-Build-SFML-with-a-MinGW-Compiler
Cmake should look like this before generating makefiles->https://i.imgur.com/EHetsLR.png
3. Create a new Clion project and inside the project folder make another folder named cmake_modules and inside that create a file named FindSFML.cmake.
4. Inside FindSFML.cmake copy and paste the code for it found on github (The file is FindSFML.cmake)
5.Use the generic green circle code in the other tutorials for your main.cpp just to see if it's working.
6.Create another file inside your project folder named CMakeList.txt and post this code inside it
Anywhere you see SFMLDemo replace with your project name, and change the SFML_ROOT to your SFML root directory.
Boom. done.
Looks easy after doing it but a lot can go wrong. I might never fully understand why you can't just have a text file that states where SFML is, debug or release, and static or dyanmic linking. But I guess that's what cmake is, still not sure whats going on with the hiearchy of .cmake and .txt files either.... /noob rant
Thanks for the help though!
Code: [Select]
Error:SFML found but some of its dependencies are missing ( FreeType libjpeg OpenAL Ogg Vorbis VorbisFile VorbisEnc FLAC)
Is there a flag in cmake I am missing? Or is there a variable in cmakelist that I need to find the external dependencies?
EDIT: Nevermind I found it I had to point to the /install/ directory of my SFML folder based on the tutorial.
MAN was that a pain, I got it working now but I know very little on the in betweens of programming with cmake....
For future people trying to get Clion to work with SFML let me make it as cut and dry as possible.....
1. Download SFML source and put it in a folder.
2. Follow THIS:https://github.com/SFML/SFML/wiki/Tutorial:-Build-SFML-with-a-MinGW-Compiler
Cmake should look like this before generating makefiles->https://i.imgur.com/EHetsLR.png
3. Create a new Clion project and inside the project folder make another folder named cmake_modules and inside that create a file named FindSFML.cmake.
4. Inside FindSFML.cmake copy and paste the code for it found on github (The file is FindSFML.cmake)
5.Use the generic green circle code in the other tutorials for your main.cpp just to see if it's working.
6.Create another file inside your project folder named CMakeList.txt and post this code inside it
Code: [Select]
cmake_minimum_required(VERSION 3.2)
project(SFMLdemo)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static")
# Set default build type explicitly to Release
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build type." FORCE)
endif (NOT CMAKE_BUILD_TYPE)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/)
if(NOT SFML_ROOT)
set(SFML_ROOT "C:/SFML-2.4.1-build/install")
endif()
# Find SFML
set(SFML_STATIC_LIBRARIES TRUE)
find_package(SFML REQUIRED COMPONENTS audio graphics window system)
if(NOT SFML_FOUND)
message(FATAL_ERROR "SFML couldn't be located!")
endif()
include_directories(${SFML_INCLUDE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set(SOURCE_FILES main.cpp)
add_executable(SFMLdemo ${SOURCE_FILES})
target_link_libraries(SFMLdemo ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
Anywhere you see SFMLDemo replace with your project name, and change the SFML_ROOT to your SFML root directory.
Boom. done.
Looks easy after doing it but a lot can go wrong. I might never fully understand why you can't just have a text file that states where SFML is, debug or release, and static or dyanmic linking. But I guess that's what cmake is, still not sure whats going on with the hiearchy of .cmake and .txt files either.... /noob rant
Thanks for the help though!