Compiling SDL with cmake


#1

Hello, I want to add SDL as part of my cmake build:

cmake_minimum_required(VERSION 3.14)
project(example)

set(SRC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../src")
set(LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../lib")

add_subdirectory("${LIB_PATH}/SDL2-2.0.10" "sdl_build")

add_executable(example "${SRC_PATH}/main.c")
target_link_libraries(example SDL2)

install(TARGETS example)

Structure:

example/
  src/
    main.c
  lib/
    SDL2-2.0.10/
  cmake/
    CMakeLists.txt
build/
  libSDL2.dylib (symlink, after build)
  sdl_build/
    libSDL2-2.0.dylib (after build)
install_dir/

Build:

cd build && cmake -DCMAKE_INSTALL_PREFIX:PATH=../install_dir ../example/util && cmake --build . --target install --config Release

But it fails with:

file INSTALL cannot find "build/sdl_build/libSDL2.dylib"

Is it problem with SDL cmake or am I doing something wrong?