2015-01-27 21:46:39 -08:00
cmake_minimum_required ( VERSION 3.0 )
2020-06-07 17:41:43 -07:00
# Enable CCache early
set ( SRB2_USE_CCACHE OFF CACHE BOOL "Use CCache" )
if ( ${ SRB2_USE_CCACHE } )
find_program ( CCACHE_PROGRAM ccache )
if ( CCACHE_PROGRAM )
message ( STATUS "Found CCache: ${CCACHE_PROGRAM}" )
set_property ( GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}" )
else ( )
message ( WARNING "You have specified to use CCACHE but it was not found. Object files will not be cached." )
endif ( )
endif ( )
2020-07-10 22:20:33 -07:00
file ( STRINGS src/version.h SRB2_VERSION )
string ( REGEX MATCH "[0-9]+\\.[0-9.]+" SRB2_VERSION ${ SRB2_VERSION } )
2018-12-30 12:08:30 -08:00
# DO NOT CHANGE THIS SRB2 STRING! Some variable names depend on this string.
# Version change is fine.
2015-01-27 21:46:39 -08:00
project ( SRB2
2020-07-10 22:20:33 -07:00
V E R S I O N $ { S R B 2 _ V E R S I O N }
2015-01-28 00:09:03 -08:00
L A N G U A G E S C )
2015-01-27 21:46:39 -08:00
2015-03-08 16:47:26 -07:00
if ( ${ PROJECT_SOURCE_DIR } MATCHES ${ PROJECT_BINARY_DIR } )
message ( FATAL_ERROR "In-source builds will bring you a world of pain. Please make a separate directory to invoke CMake from." )
endif ( )
2020-06-07 17:41:43 -07:00
if ( ( ${ SRB2_USE_CCACHE } ) AND ( ${ CMAKE_C_COMPILER } MATCHES "clang" ) )
message ( WARNING "Using clang and CCache: You may want to set environment variable CCACHE_CPP2=yes to prevent include errors during compile." )
endif ( )
2015-01-27 21:46:39 -08:00
# Set up CMAKE path
set ( CMAKE_MODULE_PATH ${ CMAKE_MODULE_PATH } "${CMAKE_SOURCE_DIR}/cmake/Modules/" )
### Useful functions
# Prepend sources with current source directory
function ( prepend_sources SOURCE_FILES )
foreach ( SOURCE_FILE ${ ${SOURCE_FILES } } )
set ( MODIFIED ${ MODIFIED } ${ CMAKE_CURRENT_SOURCE_DIR } / ${ SOURCE_FILE } )
endforeach ( )
set ( ${ SOURCE_FILES } ${ MODIFIED } PARENT_SCOPE )
endfunction ( )
2015-01-27 22:58:30 -08:00
# Macro to add OSX framework
macro ( add_framework fwname appname )
find_library ( FRAMEWORK_ ${ fwname }
2016-02-25 15:28:48 -08:00
N A M E S $ { f w n a m e }
P A T H S $ { C M A K E _ O S X _ S Y S R O O T } / S y s t e m / L i b r a r y
$ { C M A K E _ O S X _ S Y S R O O T } / L i b r a r y
/ S y s t e m / L i b r a r y
/ L i b r a r y
A T H _ S U F F I X E S F r a m e w o r k s
N O _ D E F A U L T _ P A T H )
2015-01-27 22:58:30 -08:00
if ( ${ FRAMEWORK_${fwname } } STREQUAL FRAMEWORK_ ${ fwname } -NOTFOUND )
MESSAGE ( ERROR ": Framework ${fwname} not found" )
else ( )
TARGET_LINK_LIBRARIES ( ${ appname } PRIVATE "${FRAMEWORK_${fwname}}/${fwname}" )
MESSAGE ( STATUS "Framework ${fwname} found at ${FRAMEWORK_${fwname}}" )
endif ( )
endmacro ( )
2015-01-31 20:40:36 -08:00
# Macro to copy Windows DLLs to Debug/Release folder for easy debugging
# Note: this is general purpose, we could copy anything. Just using for DLLs on MSVC though
macro ( copy_files_to_build_dir target dlllist_var )
if ( MSVC )
# http://stackoverflow.com/a/26983405/3064195
foreach ( dlllist_item ${ ${dlllist_var } } )
get_filename_component ( dllname ${ dlllist_item } NAME )
add_custom_command ( TARGET ${ target } POST_BUILD
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t
$ { d l l l i s t _ i t e m }
2015-03-24 17:32:58 -07:00
$ < T A R G E T _ F I L E _ D I R : $ { t a r g e t } > / $ { d l l n a m e }
2015-01-31 20:40:36 -08:00
)
endforeach ( )
endif ( )
endmacro ( )
2019-03-19 06:10:25 -07:00
# bitness check
set ( SRB2_SYSTEM_BITS 0 )
2019-03-18 21:04:14 -07:00
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
2019-03-18 20:58:31 -07:00
message ( STATUS "Target is 64-bit" )
set ( SRB2_SYSTEM_BITS 64 )
2019-03-19 06:10:25 -07:00
endif ( )
if ( CMAKE_SIZEOF_VOID_P EQUAL 4 )
message ( STATUS "Target is 32-bit" )
2019-03-18 20:58:31 -07:00
set ( SRB2_SYSTEM_BITS 32 )
endif ( )
2019-03-19 06:10:25 -07:00
if ( ${ SRB2_SYSTEM_BITS } EQUAL 0 )
message ( STATUS "Target bitness is unknown" )
endif ( )
2019-03-18 20:58:31 -07:00
2015-01-27 21:46:39 -08:00
# OS macros
if ( UNIX )
add_definitions ( -DUNIXCOMMON )
endif ( )
2015-01-27 22:58:30 -08:00
2015-02-01 20:14:52 -08:00
if ( CMAKE_COMPILER_IS_GNUCC )
find_program ( OBJCOPY objcopy )
endif ( )
2015-01-27 21:46:39 -08:00
if ( ${ CMAKE_SYSTEM } MATCHES "Linux" )
add_definitions ( -DLINUX )
2019-03-18 20:58:31 -07:00
if ( ${ SRB2_SYSTEM_BITS } EQUAL 64 )
add_definitions ( -DLINUX64 )
endif ( )
2015-01-27 21:46:39 -08:00
endif ( )
2015-01-27 22:58:30 -08:00
if ( ${ CMAKE_SYSTEM } MATCHES "Darwin" )
add_definitions ( -DMACOSX )
endif ( )
2015-03-04 18:07:51 -08:00
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" )
set ( CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" )
2015-01-28 14:42:05 -08:00
# Set EXE names so the assets CMakeLists can refer to its target
2018-12-30 12:08:30 -08:00
set ( SRB2_SDL2_EXE_NAME srb2 CACHE STRING "Executable binary output name" )
2015-01-27 21:46:39 -08:00
2015-01-28 16:03:41 -08:00
include_directories ( ${ CMAKE_CURRENT_BINARY_DIR } /src )
2015-01-28 14:42:05 -08:00
add_subdirectory ( src )
add_subdirectory ( assets )
2015-01-28 16:03:41 -08:00
## config.h generation
set ( GIT_EXECUTABLE "git" CACHE FILEPATH "Path to git binary" )
include ( GitUtilities )
2018-12-03 12:42:37 -08:00
git_latest_commit ( SRB2_COMP_COMMIT "${CMAKE_SOURCE_DIR}" )
2015-03-04 18:15:57 -08:00
git_current_branch ( SRB2_GIT_BRANCH "${CMAKE_SOURCE_DIR}" )
2016-01-14 07:37:58 -08:00
set ( SRB2_COMP_BRANCH "${SRB2_GIT_BRANCH}" )
2018-12-03 12:42:37 -08:00
set ( SRB2_COMP_REVISION "${SRB2_COMP_COMMIT}" )
2015-01-28 16:03:41 -08:00
configure_file ( ${ CMAKE_CURRENT_SOURCE_DIR } /src/config.h.in ${ CMAKE_CURRENT_BINARY_DIR } /src/config.h )
2015-01-28 14:42:05 -08:00
##### PACKAGE CONFIGURATION #####
2020-06-07 17:27:18 -07:00
set ( SRB2_CPACK_GENERATOR "" CACHE STRING "Generator to use for making a package. E.g., ZIP, TGZ, DragNDrop (OSX only). Leave blank for default generator." )
if ( "${SRB2_CPACK_GENERATOR}" STREQUAL "" )
if ( ${ CMAKE_SYSTEM } MATCHES "Windows" )
set ( SRB2_CPACK_GENERATOR "ZIP" )
elseif ( ${ CMAKE_SYSTEM } MATCHES "Linux" )
set ( SRB2_CPACK_GENERATOR "TGZ" )
elseif ( ${ CMAKE_SYSTEM } MATCHES "Darwin" )
set ( SRB2_CPACK_GENERATOR "TGZ" )
endif ( )
2015-01-28 17:29:16 -08:00
endif ( )
2015-01-28 14:42:05 -08:00
2020-06-07 17:27:18 -07:00
set ( CPACK_GENERATOR ${ SRB2_CPACK_GENERATOR } )
2018-12-30 12:08:30 -08:00
set ( CPACK_PACKAGE_DESCRIPTION_SUMMARY "Sonic Robo Blast 2" CACHE STRING "Program name for display purposes" )
set ( CPACK_PACKAGE_VENDOR "Sonic Team Jr." CACHE STRING "Vendor name for display purposes" )
2015-01-28 14:42:05 -08:00
#set(CPACK_PACKAGE_DESCRIPTION_FILE )
set ( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" )
set ( CPACK_PACKAGE_VERSION_MAJOR ${ SRB2_VERSION_MAJOR } )
set ( CPACK_PACKAGE_VERSION_MINOR ${ SRB2_VERSION_MINOR } )
set ( CPACK_PACKAGE_VERSION_PATCH ${ SRB2_VERSION_PATCH } )
set ( CPACK_PACKAGE_INSTALL_DIRECTORY "CMake ${CMAKE_VERSION_MAJOR}.${CMAKE_VERSION_MINOR}" )
2020-06-07 15:35:33 -07:00
SET ( CPACK_OUTPUT_FILE_PREFIX package )
2015-01-28 14:42:05 -08:00
include ( CPack )