2020-06-13 21:26:28 +00:00
|
|
|
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
|
2021-03-31 02:12:45 +00:00
|
|
|
cmake_policy(VERSION 3.15...3.20)
|
2017-12-19 03:05:50 +00:00
|
|
|
|
2021-04-05 19:20:36 +00:00
|
|
|
if (NOT CMAKE_BUILD_TYPE)
|
|
|
|
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
|
|
|
|
"Build type options: Debug Release RelWithDebInfo MinSizeRel" FORCE)
|
|
|
|
endif ()
|
|
|
|
|
2021-03-28 18:07:38 +00:00
|
|
|
# obtain revision info from git
|
|
|
|
find_package(Git)
|
|
|
|
if (GIT_FOUND)
|
|
|
|
# make sure version information gets re-run when the current Git HEAD changes
|
|
|
|
execute_process(WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} rev-parse --git-path HEAD
|
2021-04-06 22:58:11 +00:00
|
|
|
OUTPUT_VARIABLE metaforce_git_head_filename
|
2021-03-28 18:07:38 +00:00
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
2021-04-06 22:58:11 +00:00
|
|
|
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${metaforce_git_head_filename}")
|
2021-03-28 18:07:38 +00:00
|
|
|
|
|
|
|
execute_process(WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} rev-parse --symbolic-full-name HEAD
|
2021-04-06 22:58:11 +00:00
|
|
|
OUTPUT_VARIABLE metaforce_git_head_symbolic
|
2021-03-28 18:07:38 +00:00
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
execute_process(WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
2021-04-06 22:58:11 +00:00
|
|
|
COMMAND ${GIT_EXECUTABLE} rev-parse --git-path ${metaforce_git_head_symbolic}
|
|
|
|
OUTPUT_VARIABLE metaforce_git_head_symbolic_filename
|
2021-03-28 18:07:38 +00:00
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
2021-04-06 22:58:11 +00:00
|
|
|
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${metaforce_git_head_symbolic_filename}")
|
2021-03-28 18:07:38 +00:00
|
|
|
|
2021-04-06 22:58:11 +00:00
|
|
|
# defines METAFORCE_WC_REVISION
|
2021-03-28 18:07:38 +00:00
|
|
|
execute_process(WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
|
2021-04-06 22:58:11 +00:00
|
|
|
OUTPUT_VARIABLE METAFORCE_WC_REVISION
|
2021-03-28 18:07:38 +00:00
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
2021-04-06 22:58:11 +00:00
|
|
|
# defines METAFORCE_WC_DESCRIBE
|
2021-03-28 18:07:38 +00:00
|
|
|
execute_process(WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} describe --tag --long --dirty
|
2021-04-06 22:58:11 +00:00
|
|
|
OUTPUT_VARIABLE METAFORCE_WC_DESCRIBE
|
2021-03-28 18:07:38 +00:00
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
|
|
|
|
# remove hash (and trailing "-0" if needed) from description
|
2021-04-06 22:58:11 +00:00
|
|
|
string(REGEX REPLACE "(-0)?-[^-]+((-dirty)?)$" "\\2" METAFORCE_WC_DESCRIBE "${METAFORCE_WC_DESCRIBE}")
|
2021-03-28 18:07:38 +00:00
|
|
|
|
2021-04-06 22:58:11 +00:00
|
|
|
# defines METAFORCE_WC_BRANCH
|
2021-03-28 18:07:38 +00:00
|
|
|
execute_process(WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
|
2021-04-06 22:58:11 +00:00
|
|
|
OUTPUT_VARIABLE METAFORCE_WC_BRANCH
|
2021-03-28 18:07:38 +00:00
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
2021-04-06 22:58:11 +00:00
|
|
|
# defines METAFORCE_WC_DATE
|
2021-03-28 18:07:38 +00:00
|
|
|
execute_process(WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} log -1 --format=%ad
|
2021-04-06 22:58:11 +00:00
|
|
|
OUTPUT_VARIABLE METAFORCE_WC_DATE
|
2021-03-28 18:07:38 +00:00
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
else ()
|
|
|
|
message(STATUS "Unable to find git, commit information will not be available")
|
|
|
|
endif ()
|
|
|
|
|
2021-04-06 22:58:11 +00:00
|
|
|
if (METAFORCE_WC_DESCRIBE)
|
|
|
|
string(REGEX REPLACE "v([0-9]+)\.([0-9]+)\.([0-9]+)\-([0-9]+).*" "\\1.\\2.\\3.\\4" METAFORCE_VERSION_STRING "${METAFORCE_WC_DESCRIBE}")
|
2022-05-27 19:52:16 +00:00
|
|
|
string(REGEX REPLACE "v([0-9]+)\.([0-9]+)\.([0-9]+).*" "\\1.\\2.\\3" METAFORCE_SHORT_VERSION_STRING "${METAFORCE_WC_DESCRIBE}")
|
2021-03-28 18:07:38 +00:00
|
|
|
else ()
|
2021-04-06 22:58:11 +00:00
|
|
|
set(METAFORCE_WC_DESCRIBE "UNKNOWN-VERSION")
|
|
|
|
set(METAFORCE_VERSION_STRING "0.0.0")
|
2021-03-28 18:07:38 +00:00
|
|
|
endif ()
|
|
|
|
|
|
|
|
string(TIMESTAMP CURRENT_YEAR "%Y")
|
|
|
|
|
|
|
|
# Add version information to CI environment variables
|
|
|
|
if(DEFINED ENV{GITHUB_ENV})
|
2021-05-02 22:43:26 +00:00
|
|
|
file(APPEND "$ENV{GITHUB_ENV}" "METAFORCE_VERSION=${METAFORCE_WC_DESCRIBE}\n")
|
2021-03-28 18:07:38 +00:00
|
|
|
endif()
|
2021-04-06 22:58:11 +00:00
|
|
|
message(STATUS "Metaforce version set to ${METAFORCE_WC_DESCRIBE}")
|
2021-06-12 04:45:14 +00:00
|
|
|
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
|
2022-02-08 08:42:59 +00:00
|
|
|
if(APPLE)
|
|
|
|
set(EXTRA_LANGUAGES OBJC)
|
|
|
|
endif()
|
|
|
|
project(metaforce LANGUAGES C CXX ASM ${EXTRA_LANGUAGES} VERSION ${METAFORCE_VERSION_STRING})
|
2022-05-27 19:52:16 +00:00
|
|
|
if (APPLE AND NOT TVOS AND CMAKE_SYSTEM_NAME STREQUAL tvOS)
|
|
|
|
# ios.toolchain.cmake hack for SDL
|
|
|
|
set(TVOS ON)
|
|
|
|
set(IOS OFF)
|
|
|
|
endif ()
|
2021-03-28 18:07:38 +00:00
|
|
|
|
2021-04-13 14:42:01 +00:00
|
|
|
string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" ATHENA_ARCH)
|
|
|
|
string(TOLOWER "${CMAKE_HOST_SYSTEM_PROCESSOR}" ATHENA_HOST_ARCH)
|
2022-05-27 19:52:16 +00:00
|
|
|
string(TOLOWER "${CMAKE_HOST_SYSTEM_NAME}" HOST_PLATFORM_NAME)
|
|
|
|
string(TOLOWER "${CMAKE_SYSTEM_NAME}" PLATFORM_NAME)
|
2021-04-13 14:42:01 +00:00
|
|
|
set(ATHENA_EXTENSION "tar.gz")
|
2022-05-27 19:52:16 +00:00
|
|
|
if (CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin)
|
|
|
|
set(HOST_PLATFORM_NAME macos)
|
2021-04-13 14:42:01 +00:00
|
|
|
set(ATHENA_ARCH universal)
|
|
|
|
set(ATHENA_HOST_ARCH universal)
|
2022-05-27 19:52:16 +00:00
|
|
|
elseif (CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
|
|
|
|
set(HOST_PLATFORM_NAME win32)
|
|
|
|
set(ATHENA_EXTENSION ".7z")
|
|
|
|
endif ()
|
|
|
|
if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
|
|
|
set(PLATFORM_NAME macos)
|
2021-04-13 14:42:01 +00:00
|
|
|
elseif (CMAKE_SYSTEM_NAME STREQUAL Windows)
|
2021-03-28 18:07:38 +00:00
|
|
|
set(PLATFORM_NAME win32)
|
|
|
|
endif ()
|
|
|
|
|
2018-05-10 22:00:03 +00:00
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Binaries)
|
|
|
|
|
2017-12-19 03:05:50 +00:00
|
|
|
if(APPLE AND NOT CMAKE_OSX_SYSROOT)
|
|
|
|
# If the Xcode SDK is lagging behind system version, CMake needs this done first
|
2018-01-04 04:17:44 +00:00
|
|
|
execute_process(COMMAND xcrun --sdk macosx --show-sdk-path
|
2017-12-19 03:05:50 +00:00
|
|
|
OUTPUT_VARIABLE CMAKE_OSX_SYSROOT
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
endif()
|
|
|
|
|
2020-04-07 11:28:43 +00:00
|
|
|
# MSVC has a "latest" flag, which always uses the newest standard
|
|
|
|
# when available. GCC and Clang posess no such flag, and must be
|
|
|
|
# manually enforced. CMake, curiously, also doesn't have a "latest"
|
|
|
|
# standard flag either.
|
2020-04-11 05:05:55 +00:00
|
|
|
if (NOT MSVC)
|
|
|
|
set(CMAKE_CXX_STANDARD 20)
|
2020-04-07 11:28:43 +00:00
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
endif()
|
|
|
|
|
2017-07-03 04:48:19 +00:00
|
|
|
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Force shared libs off" FORCE)
|
|
|
|
set(BUILD_STATIC_LIBS ON CACHE BOOL "Force static libs on" FORCE)
|
2017-06-18 02:53:39 +00:00
|
|
|
|
2021-03-10 20:01:51 +00:00
|
|
|
if (CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL AMD64)
|
2021-04-06 22:58:11 +00:00
|
|
|
set(METAFORCE_VECTOR_ISA "sse41" CACHE STRING "Vector ISA to build for (sse2, sse3, sse41, avx, avx2)")
|
2021-03-02 02:36:10 +00:00
|
|
|
endif ()
|
2017-12-12 02:06:19 +00:00
|
|
|
|
2015-08-17 22:05:00 +00:00
|
|
|
if(MSVC)
|
2021-04-06 22:58:11 +00:00
|
|
|
if(${METAFORCE_VECTOR_ISA} STREQUAL "avx2")
|
2019-06-12 02:05:17 +00:00
|
|
|
add_compile_options(/arch:AVX2)
|
2019-06-12 02:14:39 +00:00
|
|
|
add_compile_definitions(__SSE4_1__=1)
|
2017-12-27 22:23:21 +00:00
|
|
|
message(STATUS "Building with AVX2 Vector ISA")
|
2021-04-06 22:58:11 +00:00
|
|
|
elseif(${METAFORCE_VECTOR_ISA} STREQUAL "avx")
|
2019-06-12 02:05:17 +00:00
|
|
|
add_compile_options(/arch:AVX)
|
2019-06-12 02:14:39 +00:00
|
|
|
add_compile_definitions(__SSE4_1__=1)
|
2017-12-27 22:23:21 +00:00
|
|
|
message(STATUS "Building with AVX Vector ISA")
|
2021-04-06 22:58:11 +00:00
|
|
|
elseif(${METAFORCE_VECTOR_ISA} STREQUAL "sse41")
|
2019-06-12 02:14:39 +00:00
|
|
|
add_compile_definitions(__SSE4_1__=1)
|
2021-03-02 02:36:10 +00:00
|
|
|
# clang-cl 10 requires -msse4.1, may be fixed in newer versions?
|
|
|
|
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL Clang)
|
2021-04-05 16:23:52 +00:00
|
|
|
add_compile_options($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-msse4.1>)
|
2021-03-02 02:36:10 +00:00
|
|
|
endif()
|
2017-12-27 22:23:21 +00:00
|
|
|
message(STATUS "Building with SSE4.1 Vector ISA")
|
|
|
|
else()
|
|
|
|
message(STATUS "Building with SSE2 Vector ISA")
|
2017-12-12 02:06:19 +00:00
|
|
|
endif()
|
|
|
|
|
2016-03-05 03:34:27 +00:00
|
|
|
if(${CMAKE_GENERATOR} MATCHES "Visual Studio*")
|
2019-06-12 02:14:39 +00:00
|
|
|
set(VS_OPTIONS "/MP")
|
2021-04-06 22:58:11 +00:00
|
|
|
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT metaforce)
|
2016-03-05 03:34:27 +00:00
|
|
|
endif()
|
|
|
|
|
2015-08-17 22:05:00 +00:00
|
|
|
# Shaddup MSVC
|
2019-06-12 02:14:39 +00:00
|
|
|
add_compile_definitions(UNICODE=1 _UNICODE=1 __SSE__=1
|
|
|
|
_CRT_SECURE_NO_WARNINGS=1 D_SCL_SECURE_NO_WARNINGS=1
|
|
|
|
_SCL_SECURE_NO_DEPRECATE=1 _CRT_NONSTDC_NO_WARNINGS=1
|
2020-02-16 08:10:08 +00:00
|
|
|
_ENABLE_EXTENDED_ALIGNED_STORAGE=1 NOMINMAX=1)
|
2021-04-05 16:23:52 +00:00
|
|
|
add_compile_options(/IGNORE:4221
|
2021-04-05 19:56:58 +00:00
|
|
|
$<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:/wd4018>
|
|
|
|
$<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:/wd4800>
|
|
|
|
$<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:/wd4005>
|
|
|
|
$<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:/wd4311>
|
|
|
|
$<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:/wd4068>
|
|
|
|
$<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:/wd4267>
|
|
|
|
$<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:/wd4244>
|
|
|
|
$<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:/wd4200>
|
|
|
|
$<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:/wd4305>
|
|
|
|
$<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:/wd4067>
|
|
|
|
$<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:/wd4146>
|
|
|
|
$<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:/wd4309>
|
|
|
|
$<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:/wd4805>
|
2021-04-05 16:23:52 +00:00
|
|
|
${VS_OPTIONS})
|
2017-10-24 03:12:10 +00:00
|
|
|
|
2021-04-06 21:59:52 +00:00
|
|
|
string(REPLACE "/GR " "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
|
|
|
string(REPLACE " /EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
2020-04-11 05:05:55 +00:00
|
|
|
add_compile_options(
|
|
|
|
# Disable exceptions
|
2020-04-17 20:40:46 +00:00
|
|
|
$<$<COMPILE_LANGUAGE:CXX>:/EHsc->
|
|
|
|
|
|
|
|
# Disable RTTI
|
|
|
|
$<$<COMPILE_LANGUAGE:CXX>:/GR->
|
2020-04-11 05:05:55 +00:00
|
|
|
|
|
|
|
# Enforce various standards compliant behavior.
|
|
|
|
$<$<COMPILE_LANGUAGE:CXX>:/permissive->
|
|
|
|
|
|
|
|
# Enable standard volatile semantics.
|
|
|
|
$<$<COMPILE_LANGUAGE:CXX>:/volatile:iso>
|
2016-01-15 05:44:42 +00:00
|
|
|
|
2020-04-11 05:05:55 +00:00
|
|
|
# Reports the proper value for the __cplusplus preprocessor macro.
|
|
|
|
$<$<COMPILE_LANGUAGE:CXX>:/Zc:__cplusplus>
|
|
|
|
|
|
|
|
# Use latest C++ standard.
|
|
|
|
$<$<COMPILE_LANGUAGE:CXX>:/std:c++latest>
|
|
|
|
)
|
2017-03-10 18:00:40 +00:00
|
|
|
|
2018-05-29 03:41:28 +00:00
|
|
|
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
2020-04-11 05:05:55 +00:00
|
|
|
# Flags for MSVC (not clang-cl)
|
2020-04-01 00:52:20 +00:00
|
|
|
add_compile_options(
|
2020-04-11 05:05:55 +00:00
|
|
|
# Allow constexpr variables to have explicit external linkage.
|
|
|
|
$<$<COMPILE_LANGUAGE:CXX>:/Zc:externConstexpr>
|
|
|
|
|
|
|
|
# Assume that new throws exceptions, allowing better code generation.
|
|
|
|
$<$<COMPILE_LANGUAGE:CXX>:/Zc:throwingNew>
|
|
|
|
|
|
|
|
# Link-time Code Generation for Release builds
|
2021-04-05 19:20:36 +00:00
|
|
|
$<$<CONFIG:Release>:/GL>
|
2020-04-01 00:52:20 +00:00
|
|
|
)
|
|
|
|
|
2020-04-11 05:05:55 +00:00
|
|
|
# Link-time Code Generation for Release builds
|
2018-05-25 06:39:38 +00:00
|
|
|
set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "/LTCG")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO")
|
2021-04-05 19:20:36 +00:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/DEBUG /RELEASE /OPT:REF /OPT:ICF /INCREMENTAL:NO /DEBUGTYPE:cv,fixup")
|
2018-05-25 06:39:38 +00:00
|
|
|
endif()
|
2016-01-15 05:44:42 +00:00
|
|
|
|
2015-08-17 22:05:00 +00:00
|
|
|
else()
|
2021-01-07 01:47:25 +00:00
|
|
|
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL x86_64)
|
2021-04-06 22:58:11 +00:00
|
|
|
if(${METAFORCE_VECTOR_ISA} STREQUAL "native")
|
2019-12-01 04:37:47 +00:00
|
|
|
add_compile_options(-march=native)
|
|
|
|
message(STATUS "Building with native ISA")
|
2021-04-06 22:58:11 +00:00
|
|
|
elseif(${METAFORCE_VECTOR_ISA} STREQUAL "avx2")
|
2019-06-12 02:05:17 +00:00
|
|
|
add_compile_options(-mavx2)
|
2017-12-27 22:23:21 +00:00
|
|
|
message(STATUS "Building with AVX2 Vector ISA")
|
2021-04-06 22:58:11 +00:00
|
|
|
elseif(${METAFORCE_VECTOR_ISA} STREQUAL "avx")
|
2019-06-12 02:05:17 +00:00
|
|
|
add_compile_options(-mavx)
|
2017-12-27 22:23:21 +00:00
|
|
|
message(STATUS "Building with AVX Vector ISA")
|
2021-04-06 22:58:11 +00:00
|
|
|
elseif(${METAFORCE_VECTOR_ISA} STREQUAL "sse41")
|
2019-06-12 02:05:17 +00:00
|
|
|
add_compile_options(-msse4.1)
|
2017-12-27 22:23:21 +00:00
|
|
|
message(STATUS "Building with SSE4.1 Vector ISA")
|
2021-04-06 22:58:11 +00:00
|
|
|
elseif(${METAFORCE_VECTOR_ISA} STREQUAL "sse3")
|
2019-06-12 02:05:17 +00:00
|
|
|
add_compile_options(-msse3)
|
2017-12-27 22:23:21 +00:00
|
|
|
message(STATUS "Building with SSE3 Vector ISA")
|
2021-04-06 22:58:11 +00:00
|
|
|
elseif(${METAFORCE_VECTOR_ISA} STREQUAL "sse2")
|
2019-06-12 02:05:17 +00:00
|
|
|
add_compile_options(-msse2)
|
2017-12-27 22:23:21 +00:00
|
|
|
message(STATUS "Building with SSE2 Vector ISA")
|
|
|
|
else()
|
|
|
|
message(STATUS "Building with x87 Vector ISA")
|
2017-12-12 02:06:19 +00:00
|
|
|
endif()
|
2021-01-07 01:47:25 +00:00
|
|
|
endif()
|
2017-12-12 02:06:19 +00:00
|
|
|
|
2019-05-08 03:50:21 +00:00
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
check_cxx_compiler_flag(-fno-plt HAS_NO_PLT)
|
|
|
|
if (HAS_NO_PLT)
|
2019-06-12 02:05:17 +00:00
|
|
|
add_compile_options(-fno-plt)
|
2019-05-08 03:50:21 +00:00
|
|
|
endif()
|
2020-03-02 06:59:31 +00:00
|
|
|
check_cxx_compiler_flag(-fno-asynchronous-unwind-tables HAS_NO_ASYNC_UNWIND_TABLES)
|
2020-12-18 11:09:45 +00:00
|
|
|
if (HAS_NO_ASYNC_UNWIND_TABLES AND ${CMAKE_BUILD_TYPE} STREQUAL Release)
|
2020-03-02 06:59:31 +00:00
|
|
|
# Binary size reduction
|
|
|
|
add_compile_options(-fno-asynchronous-unwind-tables)
|
|
|
|
endif()
|
2019-05-08 03:50:21 +00:00
|
|
|
|
2022-05-12 17:23:45 +00:00
|
|
|
if (METAFORCE_ASAN)
|
|
|
|
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-stdlib=libc++> -fsanitize=address
|
|
|
|
-fsanitize-address-use-after-scope)
|
|
|
|
add_link_options($<$<COMPILE_LANGUAGE:CXX>:-stdlib=libc++> -fsanitize=address
|
|
|
|
-fsanitize-address-use-after-scope)
|
|
|
|
elseif(METAFORCE_MSAN)
|
2020-04-11 05:05:55 +00:00
|
|
|
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-stdlib=libc++> -fsanitize=memory
|
|
|
|
-fsanitize-memory-track-origins -fsanitize-recover=all)
|
2019-04-07 05:14:48 +00:00
|
|
|
endif()
|
2020-04-11 05:05:55 +00:00
|
|
|
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>
|
|
|
|
$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
|
2022-06-01 00:44:53 +00:00
|
|
|
-Wall -Wno-multichar
|
2021-11-23 07:52:13 +00:00
|
|
|
-Wno-unused-variable -Wno-unused-result -Wno-unused-but-set-variable
|
2022-06-01 00:44:53 +00:00
|
|
|
-Wno-unused-function -Wno-sign-compare -Wno-unknown-pragmas)
|
2020-05-31 04:21:35 +00:00
|
|
|
# doesn't work with generator expression in add_compile_options?
|
2020-06-01 06:51:31 +00:00
|
|
|
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
|
2020-05-31 04:21:35 +00:00
|
|
|
add_compile_options(-Wno-unknown-warning-option -Wno-unused-private-field)
|
|
|
|
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
2021-03-02 02:36:10 +00:00
|
|
|
add_compile_options(-Wno-lto-type-mismatch -Wno-maybe-uninitialized)
|
2020-05-31 04:21:35 +00:00
|
|
|
endif()
|
2016-01-15 05:44:42 +00:00
|
|
|
|
2016-01-16 06:11:57 +00:00
|
|
|
if(APPLE)
|
2020-04-11 05:05:55 +00:00
|
|
|
add_compile_options(-Wno-error=deprecated-declarations
|
2021-04-05 19:20:36 +00:00
|
|
|
$<$<CONFIG:Release>:-flto=thin>)
|
2016-01-16 06:11:57 +00:00
|
|
|
endif()
|
|
|
|
|
2015-07-07 03:22:44 +00:00
|
|
|
endif()
|
2015-08-17 22:05:00 +00:00
|
|
|
|
2015-09-27 05:29:31 +00:00
|
|
|
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
|
2019-06-12 02:05:17 +00:00
|
|
|
include_directories(/usr/local/include)
|
|
|
|
link_directories(/usr/local/lib)
|
2015-09-13 03:43:22 +00:00
|
|
|
endif()
|
|
|
|
|
2019-12-01 04:01:38 +00:00
|
|
|
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
|
|
|
|
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
2020-12-18 11:09:45 +00:00
|
|
|
if(${CMAKE_BUILD_TYPE} STREQUAL Debug OR ${CMAKE_BUILD_TYPE} STREQUAL RelWithDebInfo)
|
2019-12-12 06:58:55 +00:00
|
|
|
# This is required to summarize std::string
|
2020-12-18 11:09:45 +00:00
|
|
|
add_compile_options(-fno-limit-debug-info -fno-omit-frame-pointer)
|
2019-12-12 06:58:55 +00:00
|
|
|
endif()
|
2019-12-01 04:01:38 +00:00
|
|
|
option(USE_LD_LLD "Link with LLD" ON)
|
|
|
|
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
|
|
|
option(USE_LD_GOLD "Link with GNU Gold" ON)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
include(CheckIPOSupported)
|
|
|
|
check_ipo_supported(RESULT LTO_SUPPORTED)
|
|
|
|
if(LTO_SUPPORTED AND ("${CMAKE_BUILD_TYPE}" STREQUAL "Release" OR "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo"))
|
|
|
|
option(USE_LTO "Enable LTO" ON)
|
|
|
|
else()
|
|
|
|
option(USE_LTO "Enable LTO" OFF)
|
|
|
|
endif()
|
2021-05-20 06:04:30 +00:00
|
|
|
# FIXME GCC 11.1 -flto is completely broken
|
|
|
|
if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 11.1.0)
|
|
|
|
message(NOTICE "Working around GCC 11.1 bug; disabling LTO")
|
|
|
|
set(USE_LTO OFF)
|
|
|
|
endif()
|
2015-12-23 04:16:54 +00:00
|
|
|
else()
|
2019-12-01 04:01:38 +00:00
|
|
|
option(USE_LD_LLD "Link with LLD" OFF)
|
|
|
|
option(USE_LD_GOLD "Link with GNU Gold" OFF)
|
|
|
|
option(USE_LTO "Enable LTO" OFF)
|
2015-12-23 04:16:54 +00:00
|
|
|
endif()
|
2019-12-01 04:01:38 +00:00
|
|
|
if(USE_LD_LLD)
|
|
|
|
execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=lld -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
|
|
|
|
if("${LD_VERSION}" MATCHES "LLD")
|
2020-03-02 06:59:31 +00:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld -Wl,--build-id=uuid")
|
2019-12-01 04:01:38 +00:00
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld")
|
|
|
|
if(USE_LTO)
|
|
|
|
add_compile_options(-flto=thin)
|
|
|
|
add_link_options(-flto=thin)
|
|
|
|
message(STATUS "LLD linker enabled with LTO.")
|
2015-12-23 04:16:54 +00:00
|
|
|
else()
|
2019-12-01 04:01:38 +00:00
|
|
|
message(STATUS "LLD linker enabled.")
|
2015-12-23 04:16:54 +00:00
|
|
|
endif()
|
2019-12-01 04:01:38 +00:00
|
|
|
set(USE_LD_GOLD OFF)
|
|
|
|
else()
|
|
|
|
message(WARNING "LLD linker isn't available, using the default system linker.")
|
|
|
|
set(USE_LD_LLD OFF)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
if(USE_LD_GOLD)
|
|
|
|
execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
|
|
|
|
if("${LD_VERSION}" MATCHES "GNU gold")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold -Wl,--disable-new-dtags")
|
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold -Wl,--disable-new-dtags")
|
2021-04-05 17:31:31 +00:00
|
|
|
if (USE_SPLIT_DWARF)
|
|
|
|
add_compile_options(-gsplit-dwarf -Wl,--gdb-index)
|
|
|
|
add_link_options(-gsplit-dwarf -Wl,--gdb-index)
|
|
|
|
message(STATUS "GNU gold linker enabled with split DWARF.")
|
|
|
|
elseif (USE_LTO)
|
2020-05-27 17:35:40 +00:00
|
|
|
add_compile_options(-flto)
|
|
|
|
add_link_options(-flto)
|
2019-12-01 04:01:38 +00:00
|
|
|
message(STATUS "GNU gold linker enabled with LTO.")
|
|
|
|
else()
|
|
|
|
message(STATUS "GNU gold linker enabled.")
|
|
|
|
endif()
|
|
|
|
set(USE_LD_LLD OFF)
|
|
|
|
else()
|
|
|
|
message(WARNING "GNU gold linker isn't available, using the default system linker.")
|
|
|
|
set(USE_LD_GOLD OFF)
|
|
|
|
endif()
|
2015-12-23 04:16:54 +00:00
|
|
|
endif()
|
|
|
|
|
2022-03-14 23:48:08 +00:00
|
|
|
find_package(ZLIB REQUIRED)
|
|
|
|
set(ZLIB_LIBRARIES ZLIB::ZLIB CACHE STRING "zlib libraries" FORCE)
|
2018-01-16 06:42:28 +00:00
|
|
|
|
2022-03-09 05:06:26 +00:00
|
|
|
include(ExternalProject)
|
|
|
|
ExternalProject_Add(bintoc
|
|
|
|
SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/bintoc"
|
|
|
|
CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
|
|
|
|
INSTALL_COMMAND ${CMAKE_COMMAND} --build . --config Release --target install)
|
|
|
|
include(${CMAKE_CURRENT_LIST_DIR}/bintoc/bintocHelpers.cmake)
|
2021-04-13 14:42:01 +00:00
|
|
|
|
2022-02-23 05:28:21 +00:00
|
|
|
add_subdirectory(extern)
|
2021-05-24 21:25:31 +00:00
|
|
|
add_subdirectory(imgui)
|
2016-12-08 04:55:44 +00:00
|
|
|
|
|
|
|
if(NOT TARGET atdna)
|
2017-12-07 04:13:12 +00:00
|
|
|
# Import native atdna if cross-compiling
|
|
|
|
find_package(atdna REQUIRED)
|
|
|
|
if(NOT TARGET atdna)
|
2021-04-10 13:37:03 +00:00
|
|
|
message(FATAL_ERROR "atdna required for building Metaforce; please verify LLVM installation")
|
2017-12-07 04:13:12 +00:00
|
|
|
endif()
|
2016-12-08 04:55:44 +00:00
|
|
|
endif()
|
|
|
|
|
2021-04-13 14:42:01 +00:00
|
|
|
add_subdirectory(NESEmulator EXCLUDE_FROM_ALL)
|
2022-02-16 05:21:24 +00:00
|
|
|
add_subdirectory(aurora)
|
2015-07-11 22:41:10 +00:00
|
|
|
add_subdirectory(Runtime)
|
2021-04-13 14:42:01 +00:00
|
|
|
add_subdirectory(gbalink EXCLUDE_FROM_ALL)
|
2018-05-26 21:30:19 +00:00
|
|
|
|
2019-06-12 02:05:17 +00:00
|
|
|
configure_file(${CMAKE_SOURCE_DIR}/version.h.in ${CMAKE_BINARY_DIR}/version.h)
|
2021-04-13 14:42:01 +00:00
|
|
|
|
|
|
|
# Packaging logic
|
2022-06-13 21:05:28 +00:00
|
|
|
function(get_target_output_name target result_var)
|
|
|
|
get_target_property(output_name ${target} OUTPUT_NAME)
|
|
|
|
if (output_name STREQUAL "output_name-NOTFOUND")
|
|
|
|
set(${result_var} "${target}" PARENT_SCOPE)
|
|
|
|
else ()
|
|
|
|
set(${result_var} "${output_name}" PARENT_SCOPE)
|
|
|
|
endif ()
|
|
|
|
endfunction()
|
|
|
|
function(get_target_prefix target result_var)
|
|
|
|
set(${result_var} "" PARENT_SCOPE)
|
|
|
|
if (APPLE)
|
|
|
|
# Have to recreate some bundle logic here, since CMake can't tell us
|
|
|
|
get_target_property(is_bundle ${target} MACOSX_BUNDLE)
|
|
|
|
if (is_bundle)
|
|
|
|
get_target_output_name(${target} output_name)
|
|
|
|
if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
|
|
|
set(${result_var} "${output_name}.app/Contents/MacOS/" PARENT_SCOPE)
|
|
|
|
else ()
|
|
|
|
set(${result_var} "${output_name}.app/" PARENT_SCOPE)
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
endfunction()
|
2022-03-09 05:06:26 +00:00
|
|
|
list(APPEND BINARY_TARGETS metaforce)
|
2022-06-13 07:55:12 +00:00
|
|
|
set(EXTRA_TARGETS "")
|
2021-04-13 14:42:01 +00:00
|
|
|
if (TARGET crashpad_handler)
|
2022-06-13 07:55:12 +00:00
|
|
|
list(APPEND EXTRA_TARGETS crashpad_handler)
|
2021-04-13 14:42:01 +00:00
|
|
|
endif ()
|
|
|
|
set(BIN_PREFIX "${CMAKE_INSTALL_PREFIX}")
|
2022-06-13 07:55:12 +00:00
|
|
|
install(TARGETS ${BINARY_TARGETS} ${EXTRA_TARGETS} DESTINATION ${BIN_PREFIX})
|
2021-04-13 14:42:01 +00:00
|
|
|
if (CMAKE_BUILD_TYPE STREQUAL Debug OR CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo)
|
2022-06-13 21:05:28 +00:00
|
|
|
set(DEBUG_FILES_LIST "")
|
|
|
|
foreach (target IN LISTS BINARY_TARGETS EXTRA_TARGETS)
|
|
|
|
get_target_output_name(${target} output_name)
|
2021-04-13 14:42:01 +00:00
|
|
|
if (WIN32)
|
|
|
|
install(FILES $<TARGET_PDB_FILE:${target}> DESTINATION ${BIN_PREFIX} OPTIONAL)
|
|
|
|
elseif (APPLE)
|
2022-06-13 21:05:28 +00:00
|
|
|
get_target_prefix(${target} target_prefix)
|
2022-06-13 07:55:12 +00:00
|
|
|
install(CODE "execute_process(WORKING_DIRECTORY \"${BIN_PREFIX}\" COMMAND rm -fr \"$<TARGET_FILE_NAME:${target}>.dSYM\")")
|
2022-06-13 21:05:28 +00:00
|
|
|
install(CODE "execute_process(WORKING_DIRECTORY \"${BIN_PREFIX}\" COMMAND dsymutil \"${target_prefix}$<TARGET_FILE_NAME:${target}>\")")
|
|
|
|
install(CODE "execute_process(WORKING_DIRECTORY \"${BIN_PREFIX}\" COMMAND strip -S \"${target_prefix}$<TARGET_FILE_NAME:${target}>\")")
|
|
|
|
if (NOT target_prefix STREQUAL "")
|
|
|
|
install(CODE "execute_process(WORKING_DIRECTORY \"${BIN_PREFIX}\" COMMAND mv \"${target_prefix}$<TARGET_FILE_NAME:${target}>.dSYM\" .)")
|
|
|
|
endif ()
|
2021-06-12 04:13:57 +00:00
|
|
|
elseif (UNIX)
|
2022-06-13 21:05:28 +00:00
|
|
|
get_target_prefix(${target} target_prefix)
|
|
|
|
install(CODE "execute_process(WORKING_DIRECTORY \"${BIN_PREFIX}\" COMMAND objcopy --only-keep-debug \"${target_prefix}$<TARGET_FILE_NAME:${target}>\" \"${target_prefix}$<TARGET_FILE_NAME:${target}>.dbg\")")
|
|
|
|
install(CODE "execute_process(WORKING_DIRECTORY \"${BIN_PREFIX}\" COMMAND objcopy --strip-debug --add-gnu-debuglink=$<TARGET_FILE_NAME:${target}>.dbg \"${target_prefix}$<TARGET_FILE_NAME:${target}>\")")
|
2021-04-13 14:42:01 +00:00
|
|
|
endif ()
|
2022-06-13 21:05:28 +00:00
|
|
|
list(APPEND DEBUG_FILES_LIST "${output_name}")
|
2021-04-13 14:42:01 +00:00
|
|
|
endforeach ()
|
2021-06-12 04:13:57 +00:00
|
|
|
if (WIN32)
|
|
|
|
list(TRANSFORM DEBUG_FILES_LIST APPEND ".pdb")
|
|
|
|
list(JOIN DEBUG_FILES_LIST " " DEBUG_FILES)
|
|
|
|
install(CODE "execute_process(WORKING_DIRECTORY \"${BIN_PREFIX}\" COMMAND 7z a -t7z \"${CMAKE_INSTALL_PREFIX}/debug.7z\" ${DEBUG_FILES})")
|
|
|
|
elseif (APPLE)
|
|
|
|
list(TRANSFORM DEBUG_FILES_LIST APPEND ".dSYM")
|
|
|
|
list(JOIN DEBUG_FILES_LIST " " DEBUG_FILES)
|
|
|
|
install(CODE "execute_process(WORKING_DIRECTORY \"${BIN_PREFIX}\" COMMAND tar acfv \"${CMAKE_INSTALL_PREFIX}/debug.tar.xz\" ${DEBUG_FILES})")
|
|
|
|
elseif (UNIX)
|
|
|
|
list(TRANSFORM DEBUG_FILES_LIST APPEND ".dbg")
|
|
|
|
list(JOIN DEBUG_FILES_LIST " " DEBUG_FILES)
|
|
|
|
install(CODE "execute_process(WORKING_DIRECTORY \"${BIN_PREFIX}\" COMMAND tar -I \"xz -9 -T0\" -cvf \"${CMAKE_INSTALL_PREFIX}/debug.tar.xz\" ${DEBUG_FILES})")
|
|
|
|
endif ()
|
2021-04-13 14:42:01 +00:00
|
|
|
endif ()
|
2022-06-13 21:05:28 +00:00
|
|
|
foreach (target IN LISTS BINARY_TARGETS)
|
|
|
|
get_target_prefix(${target} target_prefix)
|
|
|
|
foreach (extra_target IN LISTS EXTRA_TARGETS)
|
|
|
|
get_target_prefix(${extra_target} extra_prefix)
|
|
|
|
if (NOT "${target_prefix}" STREQUAL "${extra_prefix}")
|
|
|
|
# Copy extra target to target prefix
|
|
|
|
install(CODE "execute_process(WORKING_DIRECTORY \"${BIN_PREFIX}\" COMMAND cp \"${extra_prefix}$<TARGET_FILE_NAME:${extra_target}>\" \"${target_prefix}$<TARGET_FILE_NAME:${extra_target}>\")")
|
|
|
|
endif ()
|
|
|
|
endforeach ()
|
|
|
|
endforeach ()
|