With the removal of FindSFML.cmake in SFML 2.5, what is the preferred way of importing it?
I tried this, but it can't find SFMLConfig.cmake
cmake_minimum_required(VERSION 3.17)
project(untitled)
set(CMAKE_CXX_STANDARD 20)
find_package(SFML 2.5.1 COMPONENTS graphics REQUIRED)
add_executable(untitled "main.cpp")
target_link_libraries(untitled sfml-graphics)
The SFML directory is inside the project. I am using CMake with CLion on macOS Catalina
I'm also using clion and SFML inside a project directory and that's what I'm usually doing:
if(WIN32)
set(LIB_DIR libraries/win)
set(SHRD_EXT dll)
else()
set(LIB_DIR libraries/unix)
set(SHRD_EXT so)
endif(WIN32)
# find SFML 2.5
set(SFML_DIR ${LIB_DIR}/SFML-2.5.1/lib/cmake/SFML/)
find_package(SFML 2.5 COMPONENTS graphics window system audio network REQUIRED)```
In libraries/win and libraries/unix I have platform-specific sfml library.
I use sfml on both windows and linux depending on what device im on
My boiler plate CMakeLists.txt looks as follows:
cmake_minimum_required(VERSION 3.16)
project(AppName)
# Windows specific config
IF (WIN32)
# Include local sfml cmake config
set(SFML_DIR "C:/lib/SFML-2.5.1/lib/cmake/SFML")
# Link sfml statically (Optional)
set(SFML_STATIC_LIBRARIES TRUE)
ENDIF()
find_package(SFML 2.5.1 COMPONENTS graphics audio REQUIRED)
FILE(
GLOB
SOURCES
"src/*.cpp"
)
add_executable(AppName ${SOURCES})
target_link_libraries(AppName sfml-graphics sfml-audio)
target_include_directories(AppName
PRIVATE
"${PROJECT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/include"
)
Related
In my CMakeLists.txt I have:
cmake_minimum_required(VERSION 3.9)
# ... etc etc ...
find_package(CUDA 8.0 REQUIRED)
find_package(OpenCL REQUIRED)
and this finds CUDA and OpenCL. But - it prefers my system's non-NVIDIA OpenCL library over the library which comes with the CUDA installation. Actually, it's worse than that, since I get:
//Path to a file.
OpenCL_INCLUDE_DIR:PATH=/usr/local/cuda/include
//Path to a library.
OpenCL_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libOpenCL.so
in my CMakeCache.txt file.
How can I, from within CMakeLists.txt (i.e. not as the user but as the package maintainer), get CMake to switch the order of preference?
Note: Yes, it needs to be CMake 3.9 for compatibility reasons.
Since you're on CMake 3.9, your hands are very much tied.
If you were using CMake 3.17+ then you shouldn't find OpenCL at all. You would just use FindCUDAToolkit and the CUDA::OpenCL target:
cmake_minimum_required(VERSION 3.17)
project(test)
find_package(CUDAToolkit 8.0 REQUIRED)
add_executable(my_target ...)
target_link_libraries(my_target PRIVATE CUDA::OpenCL)
If you were using CMake 3.16, then you could still use FindCUDA and link to the CUDA-found OpenCL using the package variables:
cmake_minimum_required(VERSION 3.16)
project(test)
find_package(CUDA 8.0 REQUIRED)
cuda_add_executable(my_target ...)
target_link_libraries(my_target PRIVATE ${CUDA_OpenCL_LIBRARY})
If you were as far back as 3.12, then you could use the <Pkg>_ROOT variable to guide the search:
cmake_minimum_required(VERSION 3.12)
project(test)
find_package(CUDA 8.0 REQUIRED)
set(OpenCL_ROOT "${CUDA_TOOLKIT_ROOT_DIR}")
find_package(OpenCL REQUIRED)
and I would expect that to find the right OpenCL version.
But on earlier versions, the best you can do is use the CUDA root variable to find OpenCL inside the CUDA installation manually. Then, let FindOpenCL create the imported target:
cmake_minimum_required(VERSION 3.9)
project(test)
find_package(CUDA 8.0 REQUIRED)
find_path(
OpenCL_INCLUDE_DIR CL/opencl.h
HINTS "${CUDA_TOOLKIT_ROOT_DIR}/include"
NO_DEFAULT_PATH
)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(opencl_lib64 "${CUDA_TOOLKIT_ROOT_DIR}/lib64" )
endif()
find_library(
OpenCL_LIBRARY OpenCL
HINTS ${opencl_lib64} "${CUDA_TOOLKIT_ROOT_DIR}/lib"
PATH_SUFFIXES "${CMAKE_LIBRARY_ARCHITECTURE}"
NO_DEFAULT_PATH
)
find_package(OpenCL REQUIRED)
cuda_add_executable(my_target ...)
target_link_libraries(my_target PRIVATE OpenCL::OpenCL)
I recently updated my gtkmm framework to version 4.0.0 and updated code to be compatible with the framework. I'm using msys2 in JetBrains CLion on Windows. However when I'm compiling project I got wall of warnings and errors in various framework headers like gtkmm, glibmm etc. I can't find errors which could be related to my code. Here is my Cmake configurations
cmake_minimum_required (VERSION 3.17.5)
set (CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS " -lstdc++fs")
project (Accounter)
find_package(Boost 1.73 COMPONENTS date_time REQUIRED)
FIND_LIBRARY (LIBZIP_LIBRARY NAMES zip)
FIND_PATH (LIBZIP_INCLUDE_DIR zip.h PATH_SUFFIXES include/zip include ) # Find header
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE(PkgConfig REQUIRED)
pkg_check_modules(GTKMM gtkmm-4.0)
include_directories( ${GTKMM_INCLUDE_DIRS} )
link_directories( ${GTKMM_LIBRARY_DIRS} )
#ADD_DEFINITIONS(${GTK_CFLAGS_OTHER})
FIND_PACKAGE_HANDLE_STANDARD_ARGS(libzip DEFAULT_MSG LIBZIP_LIBRARY LIBZIP_INCLUDE_DIR)
link_directories((Accounting))
add_subdirectory(Accounting)
link_directories(OdsFile)
add_subdirectory(OdsFile)
link_directories(GUI)
add_subdirectory(GUI)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(Accounter main.cpp)
target_link_libraries(Accounter LINK_PUBLIC Accounting OdsFile GUI ${Boost_LIBRARIES} ${LIBZIP_LIBRARY} stdc++fs ${GTKMM_LIBRARIES} )
else()
message( FATAL_ERROR "Boost library is required for this library")
ENDIF().
The compile log is under this link . Do I miss something in cmake configuration? How it should be compiled? I'll provide additional info, files if it will be required. I think errors should be on my side not on framework.
I'm building a C++ program using CGAL, and I'm writing CMake install rules to deploy said program so that I can CPack the result and the end user doesn't have to install CGAL or any of its dependencies to use it. In order to do that, I need to include every shared library (DLLs on Windows etc) but I can't find a CMake variable that lets me do that. I searched around in the CGAL repo, but no luck. I tried using ${CGAL_LIBRARIES} but those don't give paths, and it doesn't seem like ${CGAL_LIBRARIES_DIRS} is a thing.
My current CMakeLists is based off the one generated by the dedicated CGAL script :
# Created by the script cgal_create_CMakeLists
# This is the CMake script for compiling a set of CGAL applications.
project( MeshCleaner )
cmake_minimum_required(VERSION 2.8.11)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
# CGAL and its components
find_package( CGAL QUIET COMPONENTS )
if ( NOT CGAL_FOUND )
message(STATUS "This project requires the CGAL library, and will not be compiled.")
return()
endif()
# Boost and its components
find_package( Boost REQUIRED )
if ( NOT Boost_FOUND )
message(STATUS "This project requires the Boost library, and will not be compiled.")
return()
endif()
# include for local directory
include_directories( BEFORE include )
# include for local package
# Creating entries for target: meshCleaner
# ############################
add_executable( ${PROJECT_NAME} main.cpp )
add_to_cached_list( CGAL_EXECUTABLE_TARGETS ${PROJECT_NAME} )
# Link the executable to CGAL and third-party libraries
target_link_libraries(${PROJECT_NAME} ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} )
install(TARGETS ${PROJECT_NAME} DESTINATION . COMPONENT Libraries)
message(${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES})
if(WIN32)
set(CMAKE_INSTALL_OPENMP_LIBRARIES TRUE)
include(InstallRequiredSystemLibraries)
endif()
include(${PROJECT_NAME}CPack)
The simplest way to "fix" that issue is to use CGAL as header-only. Please check the manual. Here is the direct link to the installation manual of CGAL-4.14, section "Header-only with CMake Configuration".
I am currently trying to configure my Cmake file to include the SFML libraries.
My CMakeLists.txt. I'm using OS X Yosemite if that matter at all.
cmake_minimum_required(VERSION 2.8.4)
project(SFMLTest)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=lib++")
set(SOURCE_FILES main.cpp)
add_executable(SFMLTest ${SOURCE_FILES})
#Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Users/Home/SFML-2.2-osx-clang-universal/cmake/Modules" ${CMAKE_MODULE_PATH})
find_package(SFML 2.2 REQUIRED system window graphics network audio)
if (SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(${main.cpp} ${SFML_Libraries})
endif()
and the error I am currently getting is
Error: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 notfind one.
Could not find a package configuration file provided by "SFML" (requested version 2.2)
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.
my FindSFML.cmake is located at
/Users/Home/SFML-2.2-osx-clang-universal/cmake/Modules
Your question says the full path to the find module is
/Users/Home/SFML-2.2-osx-clang-universal/cmake/Modules/FindSFML.cmake
But you're adding ${CMAKE_SOURCE_DIR}/Users/Home/SFML-2.2-osx-clang-universal/cmake/Modules to your CMAKE_MODULE_PATH. ${CMAKE_SOURCE_DIR} is the absolute path to the directory containing the top-level CMakeLists.txt file. If you know the absolute path to the module file you want to include, you should most certainly not prefix it with the source tree path. Just change the line to this:
set(CMAKE_MODULE_PATH "/Users/Home/SFML-2.2-osx-clang-universal/cmake/Modules" ${CMAKE_MODULE_PATH})
Also note that since you have REQUIRED specified among the arguments to find_package(), CMake will terminate with an error if the package cannot be found. Having if(SFML_FOUND) is therefore pointless.
This solution is perfect: https://oxymeos.shost.ca/article.php?about=work_with_the_SFML_in_CLion. I recommend it! It worked for me
You create a folder named "cmake_modules" at the root of the project and you place in this folder the "FindSFML.cmake" file (on Windows and Mac OS X: "[Your_SFML Location]/cmake/Modules/FindSFML.cmake", and on Linux: "[Your_SFML_location]/share/SFML/cmake/Modules/FindSFML.cmake".
The CMake configuration file (CMakeLists.txt) is then presented in this form:
cmake_minimum_required(VERSION 3.7)
project([your_project])
# Define the source and the executable
set(EXECUTABLE_NAME "[name_executable]")
add_executable(${EXECUTABLE_NAME} [project_files])
# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}" ${CMAKE_MODULE_PATH})
find_package(SFML 2 REQUIRED system window graphics network audio)
if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})
endif()
I have a problem with CMake. I have wrote a CMakeList.txt file. But when I run it with Cmake I got a strange error "CMake Error at CMakeLists.txt:17 (target_link_libraries):
Cannot specify link libraries for target "debug" which is not built by this
project.".
Is it possible to create a Cmake file that can build a project file for Debug and Release mode at the same time? Or is there a simple way to fix this error?
My CMakeLists.txt looks like this:
cmake_minimum_required (VERSION 2.8)
project (SimuVille)
# Import required CMake files
set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")
file(GLOB_RECURSE files
"*.cpp"
)
add_executable(debug ${files})
# Find the find Modules
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
#Find any version 2.X of SFML
#See the FindSFML.cmake file for additional details and instructions
find_package(SFML 2 REQUIRED system window graphics network audio)
if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})
endif()
#Find SfeMovie
find_package(sfeMovie REQUIRED)
if(SFEMOVIE_FOUND)
include_directories(${SFEMOVIE_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${SFEMOVIE_LIBRARY})
endif()
#Find Assimp
find_package(ASSIMP REQUIRED)
if(ASSIMP_FOUND)
include_directories(${ASSIMP_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${ASSIMP_LIBRARY})
endif()
#Find DevIL
find_package(DevIL REQUIRED)
if(IL_FOUND)
include_directories(${IL_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${IL_LIBRARY})
target_link_libraries(${EXECUTABLE_NAME} ${ILU_LIBRARY})
target_link_libraries(${EXECUTABLE_NAME} ${ILUT_LIBRARY})
endif()
#Find opengl libs
find_package(OpenGL REQUIRED)
include_directories(${OpenGL_INCLUDE_DIRS})
link_directories(${OpenGL_LIBRARY_DIRS})
add_definitions(${OpenGL_DEFINITIONS})
if(NOT OPENGL_FOUND)
message(ERROR " OPENGL not found!")
endif(NOT OPENGL_FOUND)
#file(GLOB_RECURSE hfiles
# "*.h"
#)
#add_executable(SimuVille ${hfiles})
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/Game)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine/SfmlObject)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine/Camera)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine/OpenglObject)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/GameEngine/Playable)
Edit: Added new source code.
Looks like your CMakeLists.txt doesn't contain either of two lines (which depends you are creating a library or a executable)
add_library(debug <files Name>)
OR
add_executable(debug <files Name>)
If you have these lines in your file, place it before target_link_libraries ()