Using SDL2 with CMake

前端 未结 12 855
野性不改
野性不改 2020-11-28 10:47

I\'m trying to use CLion to create a SDL2 project. The problem is that the SDL headers can\'t be found when using #include\'s.

My CMakeLists.txt file:



        
12条回答
  •  独厮守ぢ
    2020-11-28 10:58

    You can also pull in the SDL source repository as a submodule and build/link it statically along with your main program via add_subdirectory() and target_link_libraries():

    cmake_minimum_required( VERSION 3.7.0 )
    project( sdl2-demo )
    
    set( SDL_STATIC ON CACHE BOOL "" FORCE )
    set( SDL_SHARED OFF CACHE BOOL "" FORCE )
    add_subdirectory( external/sdl )
    
    add_executable(
        sdl2-demo
        "src/main.cpp"
        )
    target_link_libraries( sdl2-demo SDL2main SDL2-static )
    

    (At least as of the release-2.0.9 tag, possibly earlier.)

提交回复
热议问题