Skip to content

Instantly share code, notes, and snippets.

@feresr
Created April 18, 2020 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save feresr/5e9c1d2d5a7e0aef46523746e3b93be8 to your computer and use it in GitHub Desktop.
Save feresr/5e9c1d2d5a7e0aef46523746e3b93be8 to your computer and use it in GitHub Desktop.
Link SDL statically
cmake_minimum_required(VERSION 3.16)
project(smb)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
add_executable(smb src/main.cpp)
target_link_libraries(smb ${SDL2} ${SDL2_IMAGE})
#file inside /cmake folder
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(VC_LIB_PATH_SUFFIX lib/x64)
else()
set(VC_LIB_PATH_SUFFIX lib/x86)
endif()
# find_package finds and runs /usr/local/Cellar/sdl2/2.0.12_1/lib/cmake/SDL2/sdl2-config.cmake
find_package(SDL2 PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX})
set(SDL2 SDL2::SDL2-static)
# File inside /cmake folder
# This module defines:
#
# SDL2_IMAGE_LIBRARIES, the name of the library to link against
# SDL2_IMAGE_INCLUDE_DIRS, where to find the headers
# SDL2_IMAGE_FOUND, if false, do not try to link against
# Find path to the include (header) files #########
find_path(SDL2_IMAGE_INCLUDE_DIR SDL_image.h PATH_SUFFIXES SDL2 include/SDL2 include)
set(SDL2_IMAGE_INCLUDE_DIRS ${SDL2_IMAGE_INCLUDE_DIR})
# Find path to the library (static) ###############
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(VC_LIB_PATH_SUFFIX lib/x64)
else()
set(VC_LIB_PATH_SUFFIX lib/x86)
endif()
IF(MSVC) # WIN32: True on windows systems, including win64.
# Prefer static .lib in Windows (MSVC)
SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
ELSE(MSVC)
# Prefer static .a in everything else (Linux, MacOS, MinGW)
SET(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
ENDIF(MSVC)
find_library(SDL2_IMAGE_LIBRARY NAMES SDL2_image PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX})
set(SDL2_IMAGE ${SDL2_IMAGE_LIBRARY})
include_directories(${SDL2_IMAGE_INCLUDE_DIRS})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment