Помогите пожалуйста с установкой sfml через cmake FetchContent
Пользуюсь macOS, мучаюсь с установкой sfml. Всё вроде установила, но ошибка в cmakelist. Помогите пожалуйста, что нужно исправить? Вот что пишу в CMakeList:
project(NewSFMLProject LANGUAGES CXX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(INC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
include(FetchContent)
FetchContent_Declare(SFML
GIT_REPOSITORY https://github.com/SFML/SFML.git
GIT_TAG 2.6.1 sfml)
FetchContent_MakeAvailable(SFML)
add_executable(${PROJECT_NAME} main.cpp)
target_include_directories(${PROJECT_NAME} PUBLIC ${INC_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE sfml-graphics)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
install(TARGETS ${PROJECT_NAME})
Код программы:
#include <SFML/Graphics.hpp>
int main() {
sf::RenderWindow window(sf::VideoMode(640,480,32),"Hello SFML");
sf::Font font;
font.loadFromFile("OpenSans-Bold.ttf");
sf::Text text("Hello World",font,11);
text.setCharacterSize(32);
text.setPosition(window.getSize().x/2 - text.getGlobalBounds().width/2,
window.getSize().y/2 - text.getGlobalBounds().height/2);
while(window.isOpen()){
sf::Event event;
while(window.pollEvent(event)) {
if(event.type == sf::Event::Closed){
window.close();
}
window.clear(sf::Color::Black);
window.draw(text);
window.display();
}
}
return 0;
}
**Ошибка:**
[2/9] Performing update step for 'sfml-populate'
CMake Error at /Users/al/Documents/CLionProjects/NewSFMLProject/cmake-build-debug/_deps/sfml-subbuild/sfml-populate-prefix/tmp/sfml-populate-gitupdate.cmake:34 (message):
Failed to get the hash for HEAD:
fatal: not a git repository: '.git'
FAILED: sfml-populate-prefix/src/sfml-populate-stamp/sfml-populate-update /Users/al/Documents/CLionProjects/NewSFMLProject/cmake-build-debug/_deps/sfml-subbuild/sfml-populate-prefix/src/sfml-populate-stamp/sfml-populate-update
cd /Users/al/Documents/CLionProjects/NewSFMLProject/cmake-build-debug/_deps/sfml-src && /Applications/CLion.app/Contents/bin/cmake/mac/aarch64/bin/cmake -Dcan_fetch=YES -P /Users/al/Documents/CLionProjects/NewSFMLProject/cmake-build-debug/_deps/sfml-subbuild/sfml-populate-prefix/tmp/sfml-populate-gitupdate.cmake
ninja: build stopped: subcommand failed.
CMake Error at /Applications/CLion.app/Contents/bin/cmake/mac/aarch64/share/cmake-3.28/Modules/FetchContent.cmake:1679 (message):
Build step for sfml failed: 1
Call Stack (most recent call first):
/Applications/CLion.app/Contents/bin/cmake/mac/aarch64/share/cmake-3.28/Modules/FetchContent.cmake:1819:EVAL:2 (__FetchContent_directPopulate)
/Applications/CLion.app/Contents/bin/cmake/mac/aarch64/share/cmake-3.28/Modules/FetchContent.cmake:1819 (cmake_language)
/Applications/CLion.app/Contents/bin/cmake/mac/aarch64/share/cmake-3.28/Modules/FetchContent.cmake:2033 (FetchContent_Populate)
CMakeLists.txt:12 (FetchContent_MakeAvailable)
-- Configuring incomplete, errors occurred!
[Failed to reload]```
Ответы (1 шт):
Автор решения: Bearded Beaver
→ Ссылка
У вас ошибка в FetchContent_Declare
в последней строке
GIT_TAG 2.6.1 sfml)
^^^^
вот это не нужно.
Должно быть:
FetchContent_Declare(SFML
GIT_REPOSITORY https://github.com/SFML/SFML.git
GIT_TAG 2.6.1)
Еще у меня cmake ругался на отсутствие cmake_minimum_required
первой строкой в CMakeLists.