Skip to content

Instantly share code, notes, and snippets.

@dghost
Last active January 29, 2019 03:45
Show Gist options
  • Select an option

  • Save dghost/f80e58e93c1f5a67254e to your computer and use it in GitHub Desktop.

Select an option

Save dghost/f80e58e93c1f5a67254e to your computer and use it in GitHub Desktop.
FindSteamworks.cmake - quick and dirty CMake support for the Steamworks SDK
# Locate Steamworks library
# This module defines
# STEAMWORKS_LIBRARY, the name of the library to link against
# STEAMWORKS_INCLUDE_DIR, the directory containing steam/steam_api.h
# STEAMWORKS_FOUND, if false, do not try to link to Steamworks
#
# If a path is set in the SteamworksDIR environment variable it will check there
#
# This has been tested on OS X
# This may or may not with Linux - it should, but i think it could be broken easily
#
SET(STEAMWORKS_SEARCH_PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
)
SET (STEAMWORKS_SEARCH_PREFIXES
lib
lib64
)
IF (APPLE)
SET (STEAMWORKS_SEARCH_PREFIXES ${STEAMWORKS_SEARCH_PREFIXES}
redistributable_bin/osx32/
)
ELSEIF (UNIX)
IF( CMAKE_SYSTEM_PROCESSOR MATCHES "i.86" )
SET( BUILD_ARCH "32" )
ELSEIF( CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
SET( BUILD_ARCH "64" )
ENDIF()
SET (STEAMWORKS_SEARCH_PREFIXES ${STEAMWORKS_SEARCH_PREFIXES} redistributable_bin/linux${BUILD_ARCH}/ )
ENDIF()
FIND_PATH(STEAMWORKS_INCLUDE_DIR steam/steam_api.h
HINTS
$ENV{SteamworksDIR}
PATH_SUFFIXES public/ include/ Include/
PATHS ${STEAMWORKS_SEARCH_PATHS}
)
FIND_LIBRARY(STEAMWORKS_LIBRARY_TEMP
NAMES steam_api
HINTS
$ENV{SteamworksDIR}
PATH_SUFFIXES ${STEAMWORKS_SEARCH_PREFIXES}
PATHS ${STEAMWORKS_SEARCH_PATHS}
)
IF(STEAMWORKS_LIBRARY_TEMP)
# Set the final string here so the GUI reflects the final state.
SET(STEAMWORKS_LIBRARY ${STEAMWORKS_LIBRARY_TEMP} CACHE STRING "Where the Steamworks Library can be found")
# Set the temp variable to INTERNAL so it is not seen in the CMake GUI
SET(STEAMWORKS_LIBRARY_TEMP "${STEAMWORKS_LIBRARY_TEMP}" CACHE INTERNAL "")
ENDIF(STEAMWORKS_LIBRARY_TEMP)
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Steamworks REQUIRED_VARS STEAMWORKS_LIBRARY STEAMWORKS_INCLUDE_DIR)
@tsteinholz
Copy link

Hey, Im still relativly new to working with CMake, I was wondering how I would implement this file. At the moment I put the file under

cmake/Modules/FindSteamworks.cmake

in the project root and then put this code in the main CMakeLists.txt

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

I don't know what I am missing, here is where I link libraries and I do not call any other Steamworks code from anywhere other than here

 include(FindPkgConfig)
 include(FindSteamworks)

 pkg_search_module(SDL2 REQUIRED sdl2)
 pkg_search_module(SDL2IMAGE REQUIRED SDL2_image>=2.0.0)
 pkg_search_module(SDL2NET REQUIRED SDL2_net>=2.0.0)
 pkg_search_module(SDL2MIXER REQUIRED SDL2_mixer>=2.0.0)
 pkg_search_module(SDL2TTF REQUIRED SDL2_ttf>=2.0.0)

 include_directories(
     Somnia
     Include
 )

 target_link_libraries(Somnia
     ${SDL2_LIBRARIES}
     ${SDL2IMAGE_LIBRARIES}
     ${SDL2NET_LIBRARIES}
     ${SDL2MIXER_LIBRARIES}
     ${SDL2TTF_LIBRARIES}
     ${STEAMWORKS_LIBRARY}
 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment