john
john

Reputation: 29

CMake Error add_subdirectory given source "lib/sfml" which is not an existing directory

This is my very first time using CMake, so please be patient with me. My knowledge is very limited. I'm following a tutorial to recreate space invaders which I've linked below.

I used git-bash to set up my repo and now I'm setting up my build using CMake (cmake-gui) for Windows.

Repo Tutorial Link: https://dooglz.github.io/set09121/repo_setup.html

Build Tutorial link: https://dooglz.github.io/set09121/build_setup.html

Here is the CMake guide I was following: https://github.com/edinburgh-napier/aux_guides/blob/master/cmake_guide.pdf

From my understanding, for "Where is the source code," I created a folder called "Space Invader" with the CMakeLists.txt and the main.cpp. For "Where to build the binaries," I created an empty folder called "build.

When I press configure, I get this error message.

Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
CMake Error at CMakeLists.txt:15 (add_subdirectory):
  add_subdirectory given source "lib/sfml" which is not an existing
  directory.

This was the given CMakeLists.txt

cmake_minimum_required(VERSION 3.11)
# Require modern C++
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

project(Games_Engineering)

#### Setup Directories ####
#Main output directory
SET(OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/")
# Ouput all DLLs from all libs into main build folder
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY})

#### Add External Dependencies ####
add_subdirectory("lib/sfml")
set(SFML_INCS "lib/sfml/include")
link_directories("${CMAKE_BINARY_DIR}/lib/sfml/lib")

#### Practical 1 ####
file(GLOB_RECURSE SOURCES practical_1/*.cpp practical_1/*.h)
add_executable(PRACTICAL_1 ${SOURCES})
target_include_directories(PRACTICAL_1 PRIVATE ${SFML_INCS})
target_link_libraries(PRACTICAL_1 sfml-graphics)

main.cpp

int main(){
  sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
  sf::CircleShape shape(100.f);
  shape.setFillColor(sf::Color::Green);

  while (window.isOpen()){
      sf::Event event;
      while (window.pollEvent(event)){
      if (event.type == sf::Event::Closed){
        window.close();
      }
    }
    window.clear();
    window.draw(shape);
    window.display();
  }
  return 0;
}

I also tried creating a CMake with git-bash. The tutorial says to use the following commands:

mkdir projectname_build
cd projectname_build
cmake -G "Visual Studio 14 2015 Win64" ../projectname/

Or in my case for the last line (I'm guessing this is correct)

cmake -G "Visual Studio 16 2019" ../projectname/

But when I try with git-bash, I get this error:

bash: cmake: command not found

I'm okay with making a CMake with git-bash or CMake for Windows, so I'm open to any solution with those routes. I also don't want to change the code to where I'll have future issues trying to finish this project, which is why I linked the tutorial to show the work I've already done as well.

I've been searching for so long to find a solution and I'm so lost. Please look at the website links and please be patient with me. I apologize if any of this is confusing or worded wrong. I'm just a student trying to expand my skills.

Upvotes: 1

Views: 1541

Answers (1)

VonC
VonC

Reputation: 1327784

it didn't have anything mentioning recursive

True, it is mentioned only in the "Starting from scratch" includes:

Get/update SFML by running: git submodule update --init --recursive

Even without recursive, the command git submodule add https://github.com/SFML/SFML.git lib/sfml followed by git submodule update --init should be enough for your lib/sfml folder to be populated.

Upvotes: 0

Related Questions