c++ - 如何使用 CMake 配置 TGUI + SFML
问题描述
我目前正在做一个项目,我决定将 TGUI 与 SFML 一起使用来创建菜单。SFML 与 CMake 配合得很好,我认为配置 TGUI 几乎是一回事,但我不确定......如何配置 TGUI?
我的代码现在看起来像这样:
#documentation for configuring SFML with CMake : https://en.sfml-dev.org/forums/index.php?topic=24070.0
cmake_minimum_required(VERSION 3.17.3)
set(CMAKE_CXX_STANDARD 14)
project(AlgorithmsSimulator)
#location of project's files
include_directories(${CMAKE_SOURCE_DIR})
#directory for excutables
file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
#object files
file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/lib)
#configuring SFML for windows
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(WINDOWS TRUE)
set(SFML_STATIC_LIBRARIES TRUE)
set(SFML_DIR "./SFML_Win/lib/cmake/SFML")
#MacOS
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(MACOSX TRUE)
set(SFML_INCLUDE_DIR "./SFML_macOS/include")
set(SFML_LIBRARY_DIR "./SFML_macOS/lib")
link_directories(SFML_LIBRARY_DIR)
include_directories(SFML_INCLUDE_DIR)
#Linux
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(LINUX TRUE)
#set(SFML_STATIC_LIBRARIES TRUE)
set(SFML_DIR "./SFML_Linux/lib/cmake/SFML")
else()
message(FATAL_ERROR "Your Operating System is not supported")
endif()
# TGUI configuration
set(TGUI_DIR "./TGUI/lib/cmake/TGUI")
#after configuring the paths of sfml for windows, macOS and linux cmake needs only to find the below packages
find_package(SFML 2.5 COMPONENTS audio graphics window system network REQUIRED)
find_package(TGUI 0.8 REQUIRED)
#compiling & list the header an source files in the solution explorer
set(HEADERS AlgorithmsImplementation.h)
set(SOURCES AlgorithmsImplementation.cpp Main.cpp)
add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES})
# sfml .dll files and the .dll files for tgui; when tgui-d is added I get this linking error: tgui-d.lib cannot be opened and when I exclude it, it says that it cannot found tgui-d.dll
target_link_libraries(${PROJECT_NAME} sfml-audio sfml-graphics sfml-window sfml-system sfml-network tgui tgui-d)
#this will allow us to install an .exe file of the project
install(TARGETS ${PROJECT_NAME} DESTINATION bin) #${CMAKE_INSTALL_PREFIX}/bin
install(FILES Main.cpp DESTINATION src) #${CMAKE_INSTALL_PREFIX}/src
解决方案
推荐阅读
- windows - 防止 DEL 命令删除特定文件
- java - 具有单个域对象和多个数据源的 SpringBoot
- java - 程序无法识别字符在数组中的位置
- python-3.x - 分配需要两个张量的形状匹配。lhs 形状= [5] rhs 形状= [1001]
- jenkins - 如何获取ansible库存文件名作为变量
- spring-integration - 应用过滤器时 StreamingMessageSource 不断触发
- html - asp.net在gridview的项目模板下显示值
- mysql - sql:列索引6上的扫描错误,名称“scheduled_date”:null:无法将类型[] uint8扫描到null.Time
- android - 安装 react-native-firebase 后 React Native Android 应用程序崩溃
- html - css - 意外换行
- 带有元素 display:flex 在 Internet Explorer(和 Edge)中