2015-01-28 05:46:39 +00:00
|
|
|
cmake_minimum_required(VERSION 3.0)
|
|
|
|
project(SRB2
|
2015-01-28 08:09:03 +00:00
|
|
|
VERSION 2.1.14
|
|
|
|
LANGUAGES C)
|
2015-01-28 05:46:39 +00:00
|
|
|
|
2015-03-08 23:47:26 +00: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()
|
|
|
|
|
2015-01-28 05:46:39 +00: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-28 06:58:30 +00:00
|
|
|
# Macro to add OSX framework
|
|
|
|
macro(add_framework fwname appname)
|
|
|
|
find_library(FRAMEWORK_${fwname}
|
2016-02-25 23:28:48 +00:00
|
|
|
NAMES ${fwname}
|
|
|
|
PATHS ${CMAKE_OSX_SYSROOT}/System/Library
|
|
|
|
${CMAKE_OSX_SYSROOT}/Library
|
|
|
|
/System/Library
|
|
|
|
/Library
|
|
|
|
ATH_SUFFIXES Frameworks
|
|
|
|
NO_DEFAULT_PATH)
|
2015-01-28 06:58:30 +00: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-02-01 04:40:36 +00: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
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
|
|
${dlllist_item}
|
2015-03-25 00:32:58 +00:00
|
|
|
$<TARGET_FILE_DIR:${target}>/${dllname}
|
2015-02-01 04:40:36 +00:00
|
|
|
)
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2015-01-28 05:46:39 +00:00
|
|
|
# 64-bit check
|
|
|
|
if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
|
|
|
|
message(STATUS "Target is 64-bit")
|
|
|
|
set(SRB2_SYSTEM_BITS 64)
|
|
|
|
else()
|
|
|
|
set(SRB2_SYSTEM_BITS 32)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# OS macros
|
|
|
|
if (UNIX)
|
|
|
|
add_definitions(-DUNIXCOMMON)
|
|
|
|
endif()
|
2015-01-28 06:58:30 +00:00
|
|
|
|
2015-02-02 04:14:52 +00:00
|
|
|
if(CMAKE_COMPILER_IS_GNUCC)
|
|
|
|
find_program(OBJCOPY objcopy)
|
|
|
|
endif()
|
|
|
|
|
2015-01-28 05:46:39 +00:00
|
|
|
if(${CMAKE_SYSTEM} MATCHES "Linux")
|
|
|
|
add_definitions(-DLINUX)
|
|
|
|
if(${SRB2_SYSTEM_BITS} EQUAL 64)
|
|
|
|
add_definitions(-DLINUX64)
|
|
|
|
endif()
|
|
|
|
endif()
|
2015-01-28 06:58:30 +00:00
|
|
|
|
|
|
|
if(${CMAKE_SYSTEM} MATCHES "Darwin")
|
|
|
|
add_definitions(-DMACOSX)
|
2016-02-08 02:45:16 +00:00
|
|
|
endif()
|
2015-01-28 06:58:30 +00:00
|
|
|
|
2015-03-05 02:07:51 +00:00
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
|
|
|
set(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
|
|
|
|
2015-01-28 22:42:05 +00:00
|
|
|
# Set EXE names so the assets CMakeLists can refer to its target
|
|
|
|
set(SRB2_SDL2_EXE_NAME srb2)
|
|
|
|
set(SRB2_WIN_EXE_NAME srb2dd)
|
2015-01-28 05:46:39 +00:00
|
|
|
|
2015-01-29 00:03:41 +00:00
|
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/src)
|
|
|
|
|
2015-01-28 22:42:05 +00:00
|
|
|
add_subdirectory(src)
|
|
|
|
add_subdirectory(assets)
|
|
|
|
|
|
|
|
|
2015-01-29 00:03:41 +00:00
|
|
|
## config.h generation
|
|
|
|
set(GIT_EXECUTABLE "git" CACHE FILEPATH "Path to git binary")
|
|
|
|
include(GitUtilities)
|
2015-03-05 02:15:57 +00:00
|
|
|
git_describe(SRB2_GIT_DESCRIBE "${CMAKE_SOURCE_DIR}")
|
|
|
|
git_current_branch(SRB2_GIT_BRANCH "${CMAKE_SOURCE_DIR}")
|
|
|
|
set(SRB2_COMP_REVISION "${SRB2_GIT_DESCRIBE}-<${SRB2_GIT_BRANCH}>")
|
2015-01-29 00:03:41 +00:00
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/src/config.h)
|
|
|
|
|
2015-01-28 22:42:05 +00:00
|
|
|
##### PACKAGE CONFIGURATION #####
|
|
|
|
|
|
|
|
if(${CMAKE_SYSTEM} MATCHES "Windows")
|
|
|
|
set(CPACK_GENERATOR "ZIP")
|
|
|
|
endif()
|
2015-01-29 01:29:16 +00:00
|
|
|
if(${CMAKE_SYSTEM} MATCHES "Linux")
|
|
|
|
set(CPACK_GENERATOR "TGZ")
|
|
|
|
endif()
|
|
|
|
if(${CMAKE_SYSTEM} MATCHES "Darwin")
|
|
|
|
set(CPACK_GENERATOR "DragNDrop")
|
|
|
|
endif()
|
2015-01-28 22:42:05 +00:00
|
|
|
|
|
|
|
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Sonic Robo Blast 2")
|
|
|
|
set(CPACK_PACKAGE_VENDOR "Sonic Team Jr.")
|
|
|
|
#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}")
|
|
|
|
include(CPack)
|