diff --git a/CMakeLists.txt b/CMakeLists.txt index 30ab3ab..8a7a529 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ include_directories(Board Pieces) # Add source to this project's executable. add_executable (OpenChess "main.cpp" "Pieces/Piece.h" "Pieces/King.h" "Pieces/King.cpp" "Pieces/Rook.h" "Pieces/Rook.cpp" "Pieces/Queen.h" "Pieces/Queen.cpp" "Pieces/Pawn.h" "Pieces/Pawn.cpp" "Pieces/Bishop.h" "Pieces/Bishop.cpp" "Pieces/Knight.h" "Pieces/Knight.cpp" "Board/Board.cpp" "Board/Board.h" "ChessSDL.cpp" "ChessSDL.h" "Pieces/Piece.cpp") -target_link_libraries(OpenChess ${SDL2_LIBRARIES} SDL2_image::SDL2_image) +target_link_libraries(OpenChess SDL2::SDL2 SDL2_image::SDL2_image) if (CMAKE_VERSION VERSION_GREATER 3.12) set_property(TARGET OpenChess PROPERTY CXX_STANDARD 20) diff --git a/cmake/modules/FindSDL2.cmake b/cmake/modules/FindSDL2.cmake index ce14ab6..67ea2e9 100644 --- a/cmake/modules/FindSDL2.cmake +++ b/cmake/modules/FindSDL2.cmake @@ -1,10 +1,19 @@ -# Locate SDL2 library and include directories -find_path(SDL2_INCLUDE_DIR NAME SDL.h HINTS ENV SDL2DIR PATH_SUFFIXES include/SDL2 include) +# FindSDL2.cmake +# Attempt to find the SDL2 library -find_library(SDL2_LIBRARY NAME SDL2 HINTS ENV SDL2DIR PATH_SUFFIXES lib lib/x64 lib/x86) +# Look for the header file. +find_path(SDL2_INCLUDE_DIR NAME SDL.h + HINTS $ENV{SDL2DIR} + PATH_SUFFIXES SDL2 include/SDL2 include) + +# Look for the library. +find_library(SDL2_LIBRARY NAME SDL2 + HINTS $ENV{SDL2DIR} + PATH_SUFFIXES lib64 lib32 lib + PATHS ${SDL2_PATH}) include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(SDL2 DEFAULT_MSG SDL2_LIBRARY SDL2_INCLUDE_DIR) +find_package_handle_standard_args(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR) if(SDL2_FOUND AND NOT TARGET SDL2::SDL2) add_library(SDL2::SDL2 UNKNOWN IMPORTED) @@ -14,4 +23,3 @@ if(SDL2_FOUND AND NOT TARGET SDL2::SDL2) endif() mark_as_advanced(SDL2_INCLUDE_DIR SDL2_LIBRARY) -