Skip to content

Commit

Permalink
cmake wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Oct 18, 2024
1 parent e9487a1 commit f5739c9
Show file tree
Hide file tree
Showing 7 changed files with 377 additions and 120 deletions.
117 changes: 3 additions & 114 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22)
cmake_minimum_required(VERSION 3.23)

message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}")

Expand Down Expand Up @@ -107,128 +107,15 @@ if (CCACHE_FOUND)
set(ENV{CCACHE_SLOPPINESS} pch_defines,time_macros)
endif ()

if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0 AND NOT PROJECT_PLATFORM_E2K)
message(FATAL_ERROR "Building with a gcc version less than 8.0 is not supported.")
elseif (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0 AND PROJECT_PLATFORM_E2K)
message(FATAL_ERROR "Building with a MCST lcc version less than 1.25 is not supported.")
endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# XXX: Remove -fdelayed-template-parsing
add_compile_options(
-fdelayed-template-parsing
-Wno-unused-command-line-argument
-Wno-inconsistent-missing-override
)
endif()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT XRAY_USE_DEFAULT_CXX_LIB)
if (NOT XRAY_CXX_LIB)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-stdlib=libc++" LIBCPP_AVAILABLE)
CHECK_CXX_COMPILER_FLAG("-stdlib=libstdc++" LIBSTDCPP_AVAILABLE)

if (LIBCPP_AVAILABLE)
set(XRAY_CXX_LIB "libc++" CACHE STRING "" FORCE)
elseif (LIBSTDCPP_AVAILABLE)
set(XRAY_CXX_LIB "libstdc++" CACHE STRING "" FORCE)
else()
message("Neither libstdc++ nor libc++ are available. Hopefully, system has another custom stdlib?")
endif()
endif()

if (XRAY_CXX_LIB STREQUAL "libstdc++")
add_compile_options(-stdlib=libstdc++)
elseif (XRAY_CXX_LIB STREQUAL "libc++")
add_compile_options(-stdlib=libc++)
if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
add_compile_options(-lcxxrt)
else()
add_compile_options(-lc++abi)
endif()
endif()
endif()

add_compile_options(-Wno-attributes)
if (APPLE)
add_compile_options(-Wl,-undefined,error)
else()
add_compile_options(-Wl,--no-undefined)
endif()

# TODO test
option(USE_ADDRESS_SANITIZER "Use AddressSanitizer" OFF)

if (USE_ADDRESS_SANITIZER)
add_compile_options(
-fsanitize=address
-fsanitize=leak
-fsanitize=undefined
-fno-omit-frame-pointer
-fno-optimize-sibling-calls
-fno-sanitize=vptr
)

add_link_options(
$<$<CXX_COMPILER_ID:Clang>:-shared-libasan>
)
endif()

message(STATUS "USE_ADDRESS_SANITIZER: ${USE_ADDRESS_SANITIZER}")

option(USE_LTO "Use Link Time Optimization" ${MASTER_GOLD})
if (USE_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT LTO_SUPPORTED)

if (LTO_SUPPORTED)
# With clang cmake only enables '-flto=thin' but we want full LTO
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-flto=full)
else()
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
endif()
endif()
endif()

message(STATUS "USE_LTO: ${USE_LTO}")

if (PROJECT_PLATFORM_ARM)
add_compile_options(-mfpu=neon)
elseif (PROJECT_PLATFORM_ARM64)
#add_compile_options()
elseif (PROJECT_PLATFORM_E2K)
add_compile_options(-Wno-unknown-pragmas)
elseif (PROJECT_PLATFORM_PPC)
add_compile_options(
-maltivec
-mabi=altivec
)
add_compile_definitions(NO_WARN_X86_INTRINSICS)
else()
add_compile_options(
-mfpmath=sse
-msse3
)
endif()

if (XRAY_LINKER)
add_link_options(-fuse-ld=${XRAY_LINKER})
endif()

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_definitions(
DEBUG
MIXED
)
add_compile_options(-Og)
endif()

add_compile_definitions(
_MT
_CPPUNWIND
)

if (NOT WIN32)
find_package(SDL2 2.0.18 REQUIRED)
# Fix to support older SDL2
Expand Down Expand Up @@ -266,6 +153,8 @@ message("Using ${MEMORY_ALLOCATOR} memory allocator")

option(XRAY_USE_LUAJIT "Use LuaJIT" ON)

include(compiler)

add_subdirectory(Externals)

add_compile_options(
Expand Down
247 changes: 247 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
{
"version": 4,
"cmakeMinimumRequired":
{
"major": 3,
"minor": 23,
"patch": 0
},
"configurePresets":
[
{
"name": "Base",
"hidden": true
},
{
"name": "Debug",
"hidden": true,
"inherits": "Base"
},
{
"name": "Mixed",
"hidden": true,
"inherits": "Base"
},
{
"name": "Release",
"hidden": true,
"inherits": "Base"
},
{
"name": "Release Master Gold",
"hidden": true,
"inherits": "Base"
},
{
"name": "Debug x86",
"inherits": "Debug",
"architecture":
{
"value": "x86"
}
},
{
"name": "Debug x64",
"inherits": "Debug",
"architecture":
{
"value": "x64"
}
},
{
"name": "Debug ARM",
"inherits": "Debug",
"architecture":
{
"value": "ARM"
}
},
{
"name": "Debug ARM64",
"inherits": "Debug",
"architecture":
{
"value": "ARM64"
}
},
{
"name": "Mixed x86",
"inherits": "Mixed",
"architecture":
{
"value": "x86"
}
},
{
"name": "Mixed x64",
"inherits": "Mixed",
"architecture":
{
"value": "x64"
}
},
{
"name": "Mixed ARM",
"inherits": "Mixed",
"architecture":
{
"value": "ARM"
}
},
{
"name": "Mixed ARM64",
"inherits": "Mixed",
"architecture":
{
"value": "ARM64"
}
},
{
"name": "Release x86",
"inherits": "Release",
"architecture":
{
"value": "x86"
}
},
{
"name": "Release x64",
"inherits": "Release",
"architecture":
{
"value": "x64"
}
},
{
"name": "Release ARM",
"inherits": "Release",
"architecture":
{
"value": "ARM"
}
},
{
"name": "Release ARM64",
"inherits": "Release",
"architecture":
{
"value": "ARM64"
}
},
{
"name": "Release Master Gold x86",
"inherits": "Release Master Gold",
"architecture":
{
"value": "x86"
}
},
{
"name": "Release Master Gold x64",
"inherits": "Release Master Gold",
"architecture":
{
"value": "x64"
}
},
{
"name": "Release Master Gold ARM",
"inherits": "Release Master Gold",
"architecture":
{
"value": "ARM"
}
},
{
"name": "Release Master Gold ARM64",
"inherits": "Release Master Gold",
"architecture":
{
"value": "ARM64"
}
}
],
"buildPresets":
[
{
"name": "Debug x86",
"configurePreset": "Debug x86",
"configuration": "Debug"
},
{
"name": "Debug x64",
"configurePreset": "Debug x64",
"configuration": "Debug"
},
{
"name": "Debug ARM",
"configurePreset": "Debug ARM",
"configuration": "Debug"
},
{
"name": "Debug ARM64",
"configurePreset": "Debug ARM64",
"configuration": "Debug"
},
{
"name": "Mixed x86",
"configurePreset": "Mixed x86",
"configuration": "Debug"
},
{
"name": "Mixed x64",
"configurePreset": "Mixed x64",
"configuration": "Debug"
},
{
"name": "Mixed ARM",
"configurePreset": "Mixed ARM",
"configuration": "Debug"
},
{
"name": "Mixed ARM64",
"configurePreset": "Mixed ARM64",
"configuration": "Debug"
},
{
"name": "Release x86",
"configurePreset": "Release x86",
"configuration": "RelWithDebInfo"
},
{
"name": "Release x64",
"configurePreset": "Release x64",
"configuration": "RelWithDebInfo"
},
{
"name": "Release ARM",
"configurePreset": "Release ARM",
"configuration": "RelWithDebInfo"
},
{
"name": "Release ARM64",
"configurePreset": "Release ARM64",
"configuration": "RelWithDebInfo"
},
{
"name": "Release Master Gold x86",
"configurePreset": "Release Master Gold x86",
"configuration": "Release"
},
{
"name": "Release Master Gold x64",
"configurePreset": "Release Master Gold x64",
"configuration": "Release"
},
{
"name": "Release Master Gold ARM",
"configurePreset": "Release Master Gold ARM",
"configuration": "Release"
},
{
"name": "Release Master Gold ARM64",
"configurePreset": "Release Master Gold ARM64",
"configuration": "Release"
}
]
}
Loading

0 comments on commit f5739c9

Please sign in to comment.