Skip to content

Commit

Permalink
replace fetch scripts to cpm
Browse files Browse the repository at this point in the history
  • Loading branch information
K1ngst0m committed Jan 28, 2024
1 parent 0c13665 commit 0c0a797
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 181 deletions.
43 changes: 40 additions & 3 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ on:
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
CCACHE_VERSION: 4.6
CCACHE_BASEDIR: ${GITHUB_WORKSPACE}
CCACHE_DIR: ${GITHUB_WORKSPACE}/.ccache
CCACHE_COMPRESS: true
CCACHE_COMPRESSLEVEL: 6
CCACHE_MAXSIZE: 400M

jobs:
build:
Expand All @@ -22,14 +28,45 @@ jobs:

- name: install dependencies
run: sudo apt-get install libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libvulkan-dev mesa-common-dev libdwarf-dev libdw-dev
- name: Download ccache
id: ccache
shell: cmake -P {0}
run: |
set(ccache_url "https://github.com/cristianadam/ccache/releases/download/v$ENV{CCACHE_VERSION}/${ { runner.os } }.tar.xz")
file(DOWNLOAD "${ccache_url}" ./ccache.tar.xz SHOW_PROGRESS)
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvf ./ccache.tar.xz)
- name: Add ccache to PATH
run: echo "$(pwd)" >> $GITHUB_PATH

- name: Run fetch_external.py
run: python3 scripts/fetch_external_sources.py
- name: Prepare ccache timestamp
id: ccache_cache_timestamp
shell: cmake -P {0}
run: |
string(TIMESTAMP current_date "%Y-%m-%d-%H;%M;%S" UTC)
message("::set-output name=timestamp::${current_date}")

- name: ccache cache files
id: ccache_cache
uses: actions/cache@v2
with:
path: .ccache
key: ${ { matrix.config.name } }-ccache-${ { steps.ccache_cache_timestamp.outputs.timestamp } }
restore-keys: |
${ { matrix.config.name } }-ccache-
- name: Set up cache
id: cache-cpm
uses: actions/cache@v2
with:
path: ~/cpm-cache
key: ${{ runner.os }}-cpm-${{ hashFiles('**/') }}
restore-keys: |
${{ runner.os }}-cpm-
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DAPH_ENABLE_TESTING=On
run: cmake -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCPM_SOURCE_CACHE=~/cpm-cache -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DAPH_ENABLE_TESTING=On

- name: Build
# Build your program with the given configuration
Expand Down
34 changes: 0 additions & 34 deletions CHANGES

This file was deleted.

93 changes: 59 additions & 34 deletions cmake/AphExternal.cmake
Original file line number Diff line number Diff line change
@@ -1,46 +1,62 @@
# spirv-headers
option(SPIRV_HEADERS_SKIP_INSTALL "" ON)
option(SPIRV_HEADERS_SKIP_EXAMPLES "" ON)
include(CPM)

# spirv-tools
option(SKIP_SPIRV_TOOLS_INSTALL "" ON)
CPMAddPackage(
NAME tinygltf
GITHUB_REPOSITORY syoyo/tinygltf
VERSION 2.8.18
DOWNLOAD_ONLY True
)

# spirv-cross
option(SPIRV_CROSS_CLI "" OFF)
option(SPIRV_CROSS_ENABLE_TESTS "" OFF)
CPMAddPackage(
NAME tracy
GITHUB_REPOSITORY wolfpld/tracy
VERSION 0.10
)

# glslang
option(ENABLE_GLSLANG_INSTALL "" OFF)
option(ENABLE_GLSLANG_BINARIES "" OFF)
option(SKIP_GLSLANG_INSTALL "" ON)
CPMAddPackage(
NAME glm
GITHUB_REPOSITORY g-truc/glm
GIT_TAG 0.9.9.8
OPTIONS
"GLM_TEST_ENABLE OFF"
)

# mimalloc
option(MI_BUILD_SHARED "" OFF)
option(MI_BUILD_OBJECT "" OFF)
option(MI_BUILD_STATIC "" ON)
option(MI_OVERRIDE "" ON)
CPMAddPackage(
NAME unordered_dense
GITHUB_REPOSITORY martinus/unordered_dense
VERSION 4.1.2
)

# glfw
option(GLFW_BUILD_DOCS "" OFF)
option(GLFW_BUILD_TESTS "" OFF)
option(GLFW_BUILD_EXAMPLES "" OFF)
option(BUILD_SHARED_LIBS "" OFF)
CPMAddPackage(
NAME vma
GITHUB_REPOSITORY GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator
GIT_TAG master
)

CPMAddPackage(
NAME mimalloc
GITHUB_REPOSITORY microsoft/mimalloc
VERSION 2.1.2
OPTIONS
"MI_BUILD_SHARED OFF"
"MI_BUILD_OBJECT OFF"
"MI_BUILD_STATIC ON"
"MI_OVERRIDE ON"
)

CPMAddPackage(
NAME spirv-cross
GITHUB_REPOSITORY KhronosGroup/SPIRV-Cross
GIT_TAG vulkan-sdk-1.3.268
OPTIONS
"SPIRV_CROSS_CLI OFF"
"SPIRV_CROSS_ENABLE_TESTS ON"
)

add_subdirectory(${APH_EXTERNAL_DIR})
add_subdirectory(${APH_EXTERNAL_DIR}/mimalloc EXCLUDE_FROM_ALL)
add_subdirectory(${APH_EXTERNAL_DIR}/vma EXCLUDE_FROM_ALL)
add_subdirectory(${APH_EXTERNAL_DIR}/volk EXCLUDE_FROM_ALL)
add_subdirectory(${APH_EXTERNAL_DIR}/spirv-cross EXCLUDE_FROM_ALL)
add_subdirectory(${APH_EXTERNAL_DIR}/imgui EXCLUDE_FROM_ALL)
add_subdirectory(${APH_EXTERNAL_DIR}/slang EXCLUDE_FROM_ALL)
add_subdirectory(${APH_EXTERNAL_DIR}/tinygltf EXCLUDE_FROM_ALL)
add_subdirectory(${APH_EXTERNAL_DIR}/glm EXCLUDE_FROM_ALL)
add_subdirectory(${APH_EXTERNAL_DIR}/tracy EXCLUDE_FROM_ALL)
add_subdirectory(${APH_EXTERNAL_DIR}/unordered_dense EXCLUDE_FROM_ALL)

find_package(PkgConfig REQUIRED)
pkg_check_modules(xcb REQUIRED IMPORTED_TARGET xcb)

# wsi backend
set(VALID_WSI_BACKENDS Auto GLFW SDL2)
Expand All @@ -49,8 +65,17 @@ if(NOT (APH_WSI_BACKEND IN_LIST VALID_WSI_BACKENDS))
endif()

if(APH_WSI_BACKEND STREQUAL "Auto" OR APH_WSI_BACKEND STREQUAL "GLFW")
find_package(GLFW3)
if(NOT GLFW3_FOUND)
CPMAddPackage(
NAME GLFW
GITHUB_REPOSITORY glfw/glfw
GIT_TAG 3.3.9
OPTIONS
"GLFW_BUILD_TESTS OFF"
"GLFW_BUILD_EXAMPLES OFF"
"GLFW_BULID_DOCS OFF"
"GLFW_INSTALL OFF"
)
if(NOT GLFW_ADDED)
message(FATAL_ERROR "GLFW3 library not found!")
endif()
elseif(APH_WSI_BACKEND STREQUAL "SDL2")
Expand Down
24 changes: 24 additions & 0 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-License-Identifier: MIT
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors

set(CPM_DOWNLOAD_VERSION 0.38.7)
set(CPM_HASH_SUM "83e5eb71b2bbb8b1f2ad38f1950287a057624e385c238f6087f94cdfc44af9c5")

if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)

file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
)

include(${CPM_DOWNLOAD_LOCATION})
2 changes: 1 addition & 1 deletion engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ target_include_directories(aph_engine INTERFACE
${APH_ENGINE_DIR}
SYSTEM INTERFACE
${APH_EXTERNAL_DIR}/volk
${APH_EXTERNAL_DIR}/unordered_dense/include
${unordered_dense_SOURCE_DIR}/include
)
target_link_libraries(aph_engine INTERFACE
common
Expand Down
4 changes: 2 additions & 2 deletions engine/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ add_library(api STATIC ${API_VULKAN_SRC})
aph_compiler_options(api)
target_include_directories(api PRIVATE
${APH_ENGINE_DIR}
${APH_EXTERNAL_DIR}/spirv-cross
${APH_EXTERNAL_DIR}/vulkan
${APH_EXTERNAL_DIR}/vma/include
${spirv-cross_SOURCE_DIR}
${vma_SOURCE_DIR}/include

PUBLIC
${APH_EXTERNAL_DIR}/volk
Expand Down
2 changes: 1 addition & 1 deletion engine/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ add_library(cli STATIC ${API_CLI_SRC})
aph_compiler_options(cli)
target_include_directories(cli PRIVATE
${APH_ENGINE_DIR}
${APH_EXTERNAL_DIR}/unordered_dense/include
${unordered_dense_SOURCE_DIR}/include
)
2 changes: 1 addition & 1 deletion engine/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ add_library(common STATIC ${APH_COMMON_SRC})
aph_compiler_options(common)
target_include_directories(common PUBLIC
${APH_ENGINE_DIR}
${APH_EXTERNAL_DIR}/unordered_dense/include
${unordered_dense_SOURCE_DIR}/include

PRIVATE
${APH_EXTERNAL_DIR}/backward-cpp/include
Expand Down
2 changes: 1 addition & 1 deletion engine/event/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ add_library(aph_event STATIC ${APH_EVENT_SRC})
aph_compiler_options(aph_event)
target_include_directories(aph_event PRIVATE
${APH_ENGINE_DIR}
${APH_EXTERNAL_DIR}/unordered_dense/include
${unordered_dense_SOURCE_DIR}/include
)
2 changes: 1 addition & 1 deletion engine/math/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
file(GLOB APH_MATH_SRC ${APH_ENGINE_MATH_DIR}/*.cpp)
add_library(aph_math STATIC ${APH_MATH_SRC})
aph_compiler_options(aph_math)
target_include_directories(aph_math PUBLIC ${APH_EXTERNAL_DIR}/glm)
target_include_directories(aph_math PUBLIC ${glm_SOURCE_DIR})
2 changes: 1 addition & 1 deletion engine/resource/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ target_include_directories(resource PRIVATE
${APH_EXTERNAL_DIR}/slang
${APH_EXTERNAL_DIR}/tinyktx
${APH_EXTERNAL_DIR}/stb/include
${APH_EXTERNAL_DIR}/tinygltf
${tinygltf_SOURCE_DIR}
)

target_link_libraries(resource PRIVATE slang aph_filesystem common api)
2 changes: 1 addition & 1 deletion engine/threads/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ add_library(threads STATIC ${API_THREADS_SRC})
aph_compiler_options(threads)
target_include_directories(threads PRIVATE
${APH_ENGINE_DIR}
${APH_EXTERNAL_DIR}/unordered_dense/include
${unordered_dense_SOURCE_DIR}/include
)
target_link_libraries(threads PRIVATE common aph_allocator)
4 changes: 2 additions & 2 deletions engine/wsi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ if(APH_WSI_BACKEND STREQUAL "Auto" OR APH_WSI_BACKEND STREQUAL "GLFW")
${APH_ENGINE_WSI_DIR}/wsi_glfw.cpp
${APH_ENGINE_WSI_DIR}/imgui_impl_glfw.cpp
)
target_include_directories(wsi PRIVATE ${GLFW3_INCLUDE_DIR})
target_link_libraries(wsi PRIVATE ${GLFW3_LIBRARY})
target_include_directories(wsi PRIVATE ${GLFW_SOURCE_DIR}/include)
target_link_libraries(wsi PRIVATE glfw)
elseif(APH_WSI_BACKEND STREQUAL "SDL2")
if(NOT SDL2_FOUND)
message(FATAL_ERROR "SDL2 library not found!")
Expand Down
Loading

0 comments on commit 0c0a797

Please sign in to comment.