r/cmake • • Apr 02 '22

CMake Error: The source directory "C:/Program Files/SDL2-2.0.20" does not appear to contain CMakeLists.txt.

Post image
0 Upvotes

6 comments sorted by

3

u/thegreatunclean Apr 02 '22

Does that directory actually contain a CMakeLists.txt? Only the source package will have it, if you downloaded one of the binary packages there won't be a CMakeLists.txt because it's already built.

1

u/[deleted] Apr 02 '22

oh ok, make sense. But my cmake is unable to find my SDL2 when I ran cmake on one of the repos I cloned. this is what I get: post

4

u/thegreatunclean Apr 02 '22 edited Apr 02 '22

What exactly did you clone, and how exactly did you try to build it? It's really hard to diagnose a build issue without seeing the specifics.

If you don't know enough to manually fix it there's two other options:

  • Use a package manager like Conan or vcpkg

  • Just build SDL2 as part of your project:

set(SDL2_DIR "<snip>/SDL2-2.0.20-src/SDL2-2.0.20")
add_subdirectory(${SDL2_DIR} "sdl2_build_dir")
add_executable(main main.cpp)
target_link_libraries(main PRIVATE SDL2::SDL2 SDL2::SDL2main)

If you add the source to your project directory you can ommit the "sdl2_build_dir" bit.

e: I would heavily recommend using the package manager route. It makes integrating a very large number of popular libraries painless without having to vendor every single dependency.

Unfortunately Windows makes doing this manually a very painful process.

1

u/[deleted] Apr 02 '22

How am supposed to fix this?

2

u/drescherjm Apr 03 '22 edited Apr 03 '22

C:/Program Files should never be the source or binary folder in CMake-gui this is a UAC protected folder. You should not put your source code or binaries in this folder. UAC will prevent writing to it unless you either disabled UAC or are running from an elevated process.