- 1 year ago
How to tell cmake to find SDL library where I want in project?
To tell CMake to find the SDL library in a specific location within your project, you can use the find_library
command with the PATHS
option.
Here's an example CMakeLists.txt file that shows how to specify the path to the SDL library:
bashcmake_minimum_required(VERSION 3.0)
project(my_project)
# Set the path to the SDL library
set(SDL_LIBRARY_PATH ${CMAKE_CURRENT_SOURCE_DIR}/path/to/sdl/lib)
# Find the SDL library using the specified path
find_library(SDL2_LIBRARY SDL2 PATHS ${SDL_LIBRARY_PATH})
# Add your project executable and link it with SDL library
add_executable(my_executable main.cpp)
target_link_libraries(my_executable ${SDL2_LIBRARY})
In this example, we first set the SDL_LIBRARY_PATH
variable to the path where the SDL library is located within our project.
We then use the find_library
command with the SDL2
library name and the PATHS
option to tell CMake to search for the SDL library in the specified path.
Finally, we link our project executable with the SDL library using the target_link_libraries
command.
Note that the find_library
command may have different syntax or options depending on the platform and the specific library you're looking for. You can refer to the CMake documentation for more information.