Skip to content

Commit

Permalink
updates on cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
spiroskou committed Aug 16, 2024
1 parent 917f21c commit 44d3ea6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ project ("OpenChess")

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")

find_package(SDL2 REQUIRED)
find_package(SDL2 REQUIRED CONFIG)
find_package(SDL2_image REQUIRED)

# Print the variables to see their values
Expand All @@ -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::SDL2 SDL2_image::SDL2_image)
target_link_libraries(OpenChess ${SDL2_LIBRARIES} SDL2_image::SDL2_image)

if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET OpenChess PROPERTY CXX_STANDARD 20)
Expand Down
13 changes: 7 additions & 6 deletions cmake/modules/FindSDL2.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
# FindSDL2.cmake
# Attempt to find the SDL2 library

# 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
Expand All @@ -16,10 +11,16 @@ include(FindPackageHandleStandardArgs)
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)
add_library(SDL2::SDL2 SHARED IMPORTED)
set_target_properties(SDL2::SDL2 PROPERTIES
IMPORTED_LOCATION "${SDL2_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}")
endif()

if(EXISTS "${SDL2_LIBRARY}" AND EXISTS "${SDL2_INCLUDE_DIR}")
set(SDL2_SDL2_FOUND TRUE)
else()
set(SDL2_SDL2_FOUND FALSE)
endif()

mark_as_advanced(SDL2_INCLUDE_DIR SDL2_LIBRARY)

0 comments on commit 44d3ea6

Please sign in to comment.