Skip to content

Commit

Permalink
Update CMakeLists.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
larziwau authored Dec 19, 2024
1 parent 50d183d commit 1cb6012
Showing 1 changed file with 20 additions and 87 deletions.
107 changes: 20 additions & 87 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,79 +1,56 @@
cmake_minimum_required(VERSION 3.21)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

project(globed2 VERSION 1.0.1)
project(globed2 VERSION 1.0.0)

# set ios archs
if (${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
message(STATUS "building for ios")
unset(CMAKE_OSX_ARCHITECTURES)
set(CMAKE_OSX_ARCHITECTURES "arm64")
set(CMAKE_OSX_DEPLOYMENT_TARGET "14.0")
set(CMAKE_SYSTEM_NAME "iOS")
else()
message(STATUS "building for mac")
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
endif()

option(GLOBED_OSS_BUILD "Open source build that does not require closed-source dependencies" OFF)
option(GLOBED_NATIVE_ARCH "Native architecture build" OFF)

# on windows use precompiled, on other platforms compile libsodium
if (WIN32)
option(GLOBED_COMPILE_LIBS "Don't use precompiled libraries and compile manually" OFF)
else()
option(GLOBED_COMPILE_LIBS "Don't use precompiled libraries and compile manually" ON)
endif()

# check if compiler is clang
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(GLOBED_IS_CLANG ON)
else()
set(GLOBED_IS_CLANG OFF)
endif()

# check if it's clang-cl or clang
if (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
set(GLOBED_IS_CLANG_CL OFF)
else()
set(GLOBED_IS_CLANG_CL ON)
endif()


# Check for debug build
option(ENABLE_DEBUG "Debug mode" OFF)
option(GLOBED_RELEASE "Release build" OFF)

if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR "${CMAKE_BUILD_TYPE}asdf" STREQUAL "asdf" OR ENABLE_DEBUG)
set(GLOBED_IS_DEBUG ON)
endif()

# Debug/Release options
if (GLOBED_IS_DEBUG)
add_compile_definitions(GLOBED_DEBUG=1)
add_compile_definitions(GEODE_DEBUG=1)
add_compile_definitions(ASP_ENABLE_DEBUG=1)

# # turn on asan
# if (GLOBED_IS_CLANG)
# if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/libs/stl_asan.lib")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
# set(GLOBED_LINK_TO_ASAN ON)
# endif()

# # no omit frame pointer
# if (NOT GLOBED_IS_CLANG_CL)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer")
# endif()
# endif()
elseif (GLOBED_RELEASE)
# Enable LTO in release (2.5x less binary size, costs only a few extra seconds of build time)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()

# add thingies depending on the current system
if (ANDROID)
file(GLOB_RECURSE OS_SOURCES "src/platform/os/android/*.cpp" "src/platform/arch/arm/*.cpp")
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
Expand All @@ -86,27 +63,25 @@ else()
message(FATAL_ERROR "Unsupported operating system")
endif()

# source files
file(GLOB_RECURSE SOURCES
src/audio/*.cpp
src/crypto/*.cpp
src/data/*.cpp
src/audio/*.cpp
src/crypto/*.cpp
src/data/*.cpp
src/globed/*.cpp
src/game/*.cpp
src/hooks/*.cpp
src/managers/*.cpp
src/net/*.cpp
src/ui/*.cpp
src/util/*.cpp
src/main.cpp
src/game/*.cpp
src/hooks/*.cpp
src/managers/*.cpp
src/net/*.cpp
src/ui/*.cpp
src/util/*.cpp
src/main.cpp
${OS_SOURCES}
)

add_library(${PROJECT_NAME} SHARED ${SOURCES})

# Windows - do stuff
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_compile_definitions(WIN32_LEAN_AND_MEAN=1) # geode moment
add_compile_definitions(WIN32_LEAN_AND_MEAN=1)
if (NOT MSVC)
set(GLOBED_WINDOWS_CLANG ON)
endif()
Expand All @@ -116,7 +91,6 @@ if (GLOBED_RELEASE)
target_compile_definitions(${PROJECT_NAME} PRIVATE GLOBED_RELEASE=1)
endif()

# export some symbols
target_compile_definitions(${PROJECT_NAME} PRIVATE GLOBED_EXPORTING)

if (CMAKE_HOST_SYSTEM MATCHES "Linux" AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
Expand All @@ -131,29 +105,24 @@ endif()

add_subdirectory($ENV{GEODE_SDK} ${CMAKE_CURRENT_BINARY_DIR}/geode)

# done so you can include root files with <file.hpp>
target_include_directories(${PROJECT_NAME} PRIVATE src/)
target_include_directories(${PROJECT_NAME} PRIVATE libs/)

# our favorite libraries
CPMAddPackage("gh:dankmeme01/uibuilder#c30755a")
CPMAddPackage("gh:camila314/uibuilder#3d10e3d")
CPMAddPackage(
NAME Boost
VERSION 1.86.0
URL https://github.com/boostorg/boost/releases/download/boost-1.86.0/boost-1.86.0-cmake.7z
URL_HASH SHA256=ee6e0793b5ec7d13e7181ec05d3b1aaa23615947295080e4b9930324488e078f
OPTIONS "BOOST_ENABLE_CMAKE ON" "BOOST_INCLUDE_LIBRARIES describe\\\;stacktrace\\\;thread" # escape with \\\;
VERSION 1.87.0
URL https://github.com/boostorg/boost/releases/download/boost-1.87.0/boost-1.87.0-cmake.7z
URL_HASH SHA256=61d61a3f33283bab8f3736745a4e47c37141f07e413986cd05d1f942c69d529a
OPTIONS "BOOST_ENABLE_CMAKE ON" "BOOST_INCLUDE_LIBRARIES describe\\;stacktrace\\;thread"
)
CPMAddPackage("gh:dankmeme01/asp2#2378a82")

# asp defines
if (WIN32)
if (GLOBED_IS_DEBUG)
# debug
target_compile_definitions(asp PRIVATE _HAS_ITERATOR_DEBUGGING=0)
endif()

# thingy
target_compile_definitions(asp PRIVATE ASP_ENABLE_FORMAT=1)
target_compile_definitions(${PROJECT_NAME} PRIVATE ASP_ENABLE_FORMAT=1)
endif()
Expand All @@ -165,30 +134,15 @@ include(cmake/baked_resources_gen.cmake)
generate_baked_resources_header("${CMAKE_CURRENT_SOURCE_DIR}/embedded-resources.json" "${CMAKE_CURRENT_BINARY_DIR}/globed-codegen/embedded_resources.hpp")

if (GLOBED_NATIVE_ARCH)
# Apply native architecture
add_compile_options("-march=native")
endif()

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(${PROJECT_NAME} PRIVATE "-Wno-deprecated-declarations")
# target_compile_options(${PROJECT_NAME} PRIVATE "-ftime-trace")
# target_compile_options(asp PRIVATE "-ftime-trace")
# if (WIN32)
# target_compile_options(${PROJECT_NAME} PRIVATE "-Wno-vla-cxx-extension")
# endif()
endif()

target_link_libraries(${PROJECT_NAME} UIBuilder Boost::describe Boost::thread asp)

# if (GLOBED_LINK_TO_ASAN)
# target_link_libraries(
# ${PROJECT_NAME}
# "${CMAKE_CURRENT_SOURCE_DIR}/libs/stl_asan.lib"
# "${CMAKE_CURRENT_SOURCE_DIR}/libs/clang_rt.asan_dynamic-x86_64.lib"
# "${CMAKE_CURRENT_SOURCE_DIR}/libs/clang_rt.asan_dynamic_runtime_thunk-x86_64.lib"
# )
# endif()

if (GLOBED_IS_DEBUG)
target_link_libraries(${PROJECT_NAME} Boost::stacktrace)
endif()
Expand All @@ -197,14 +151,12 @@ if (GLOBED_COMPILE_LIBS)
CPMAddPackage("gh:dankmeme01/libsodium-cmake#226abba")
CPMAddPackage("gh:xiph/opus#v1.5.2")

# disable some warnings
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(sodium PRIVATE "-Wno-inaccessible-base" "-Wno-pointer-sign" "-Wno-user-defined-warnings")
endif()

target_link_libraries(${PROJECT_NAME} sodium opus)
else()
# download headers (binaries based off of 1.0.20 too)
CPMAddPackage(
NAME sodium
GIT_REPOSITORY "https://github.com/jedisct1/libsodium.git"
Expand All @@ -229,40 +181,26 @@ else()

set(SODIUM_VERSION_IN "${CMAKE_CURRENT_SOURCE_DIR}/libs/sodium/version.h")
set(SODIUM_VERSION_OUT "${sodium_SOURCE_DIR}/src/libsodium/include/sodium/")

if (NOT EXISTS "${SODIUM_VERSION_OUT}/version.h")
message(STATUS "Copied version.h to ${SODIUM_VERSION_OUT}")
file(COPY "${SODIUM_VERSION_IN}" DESTINATION "${SODIUM_VERSION_OUT}")
else()
file(READ "${SODIUM_VERSION_IN}" CONTENT_IN)
file(READ "${SODIUM_VERSION_OUT}/version.h" CONTENT_OUT)

if (NOT "${CONTENT_IN}" STREQUAL "${CONTENT_OUT}")
message(STATUS "Copied version.h to ${SODIUM_VERSION_OUT}")
file(COPY "${SODIUM_VERSION_IN}" DESTINATION "${SODIUM_VERSION_OUT}")
endif()
endif()

target_link_libraries(${PROJECT_NAME} sodium opus)
target_link_libraries(${PROJECT_NAME} sodium opus)
endif()

# Windows - link to winsock and wmi
if (WIN32)
target_link_libraries(${PROJECT_NAME} ws2_32)
endif()

# Apple - link to iokit
if (APPLE)
find_library(IOKIT_LIBRARY IOKit)
target_link_libraries(${PROJECT_NAME} ${IOKIT_LIBRARY})
endif()

# link to libcurl

CPMAddPackage(
NAME curl
GIT_REPOSITORY "https://github.com/curl/curl.git"
GIT_TAG "curl-8_11_0"
GIT_TAG "curl-8.11.1_1"
DOWNLOAD_ONLY YES
)

Expand All @@ -282,7 +220,6 @@ endif()

target_compile_definitions(${PROJECT_NAME} PRIVATE CURL_STATICLIB=1)

# we are kinda leeching off of geode but we can always snatch those libraries in the future
if (WIN32)
set_target_properties(curl PROPERTIES IMPORTED_LOCATION "$ENV{GEODE_SDK}/loader/include/link/${LIB_PLATFORM}/libcurl.lib")
else()
Expand All @@ -293,18 +230,14 @@ target_include_directories(${PROJECT_NAME} PRIVATE "${curl_SOURCE_DIR}/include")

target_link_libraries(${PROJECT_NAME} curl)

# mac needs this for curl
if (APPLE)
target_link_libraries(${PROJECT_NAME} z)
elseif (WIN32)
# windows needs this ig?
target_link_libraries(${PROJECT_NAME} crypt32)
elseif (ANDROID)
target_link_libraries(${PROJECT_NAME} android)
endif()


# link to bb
if (GLOBED_OSS_BUILD)
message(STATUS "Building open-source version, not linking to bb")
target_compile_definitions(${PROJECT_NAME} PRIVATE GLOBED_OSS_BUILD=1)
Expand Down

0 comments on commit 1cb6012

Please sign in to comment.