Skip to content

Commit

Permalink
Refactored the configuration and build pipelines to be all CMake-based.
Browse files Browse the repository at this point in the history
Remove obsolete setup and build scripts.
  • Loading branch information
zhangdoa committed Jan 15, 2025
1 parent 4813478 commit 03123e0
Show file tree
Hide file tree
Showing 49 changed files with 494 additions and 678 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

# Third-party headers and libraries
/Source/External/Include
/Source/External/Lib
/Source/External/DLL
/Source/External/Tools

# For macOS
\.DS_Store
Expand Down
10 changes: 5 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"name": "(Windows) Launch Main",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/Bin/Debug/Main.exe",
"program": "${workspaceFolder}/Bin/RelWithDebInfo/Main.exe",
"args": [
"-mode 0",
"-renderer 2",
"-loglevel 1"
"-loglevel 0"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/Bin",
Expand All @@ -20,7 +20,7 @@
"name": "(Windows) Launch Test",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/Bin/Debug/Test.exe",
"program": "${workspaceFolder}/Bin/RelWithDebInfo/Test.exe",
"stopAtEntry": false,
"cwd": "${workspaceFolder}/Bin",
"environment": [],
Expand All @@ -30,7 +30,7 @@
"name": "(Windows) Launch Baker",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/Bin/Debug/Baker.exe",
"program": "${workspaceFolder}/Bin/RelWithDebInfo/Baker.exe",
"args": [
"-mode 0",
"-renderer 2",
Expand All @@ -45,7 +45,7 @@
"name": "(Windows) Launch Reflector",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/Bin/Debug/Reflector.exe",
"program": "${workspaceFolder}/Bin/RelWithDebInfo/Reflector.exe",
"args": [
"../Source/Engine/Common/GPUDataStructure.h"
],
Expand Down
46 changes: 40 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"cmake.sourceDirectory": "${workspaceFolder}/Source",
"cmake.setBuildTypeOnMultiConfig": true,
"cmake.sourceDirectory": "${workspaceFolder}",
"cmake.configureSettings": {
"BUILD_GAME": "ON",
"CMAKE_BUILD_TYPE": "Debug"
"PREPARE_ENV": true,
"BUILD_THIRD_PARTY": true,
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
},
"cmake.generator": "Visual Studio 17",
"files.associations": {
"\"*.list\"": "\".json\"",
"vector": "cpp",
"cmath": "cpp",
"algorithm": "cpp",
Expand Down Expand Up @@ -96,6 +98,38 @@
"xutility": "cpp",
"complex": "cpp",
"*.refl": "cpp",
"stack": "cpp"
}
"stack": "cpp",
"barrier": "cpp",
"cfenv": "cpp",
"cinttypes": "cpp",
"csetjmp": "cpp",
"csignal": "cpp",
"cuchar": "cpp",
"cwctype": "cpp",
"execution": "cpp",
"expected": "cpp",
"latch": "cpp",
"memory_resource": "cpp",
"numbers": "cpp",
"regex": "cpp",
"scoped_allocator": "cpp",
"semaphore": "cpp",
"source_location": "cpp",
"strstream": "cpp",
"typeindex": "cpp",
"variant": "cpp",
"__bit_reference": "cpp",
"__config": "cpp",
"__debug": "cpp",
"__errc": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__node_handle": "cpp",
"__split_buffer": "cpp",
"__threading_support": "cpp",
"__tree": "cpp",
"__verbose_abort": "cpp",
"propagate_const": "cpp",
"string_view": "cpp"
},
}
164 changes: 164 additions & 0 deletions CMake/BuildThirdPartyLibs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
function(build_third_party name src_dir cmake_args)
# Convert name to uppercase for variable names
string(TOUPPER ${name} UPPER_NAME)

# Use a single global configuration
set(CONFIG ${CMAKE_BUILD_TYPE})
if (NOT CONFIG)
message(FATAL_ERROR "CMAKE_BUILD_TYPE is not set. Please set it to Debug, Release, etc.")
endif()

# Dynamically set build directories
set(BUILD_DIR ${CMAKE_BINARY_DIR}/ThirdParty/${name}/${CONFIG})
set(${UPPER_NAME}_LIBRARY_DIR "${BUILD_DIR}/lib/${CONFIG}" PARENT_SCOPE)
set(${UPPER_NAME}_INCLUDE_DIR "${BUILD_DIR}/include" PARENT_SCOPE)

if (BUILD_THIRD_PARTY)
# Create build directory
file(MAKE_DIRECTORY ${BUILD_DIR})

# Generate and build the third-party project
execute_process(
COMMAND ${CMAKE_COMMAND}
-S ${src_dir}
-B ${BUILD_DIR}
${cmake_args}
-DCMAKE_BUILD_TYPE=${CONFIG} # Pass the build type
WORKING_DIRECTORY ${BUILD_DIR}
)

execute_process(
COMMAND ${CMAKE_COMMAND} --build ${BUILD_DIR} --config ${CONFIG} -- -j
)
else()
message(STATUS "Skipping build for ${name} (${CONFIG})")
endif()

# Copy runtime files (e.g., .dll) to runtime output directory
file(GLOB DLL_FILES "${BUILD_DIR}/bin/${CONFIG}/*.dll")
if (DLL_FILES)
foreach(DLL_FILE ${DLL_FILES})
file(COPY ${DLL_FILE} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CONFIG})
endforeach()
message(STATUS "Copied DLLs for ${name} (${CONFIG}) to runtime output directory.")
else()
message(WARNING "No DLL files found for ${name} (${CONFIG}) in ${BUILD_DIR}/bin/${CONFIG}.")
endif()

# Dynamically locate all library files
file(GLOB LIBS "${BUILD_DIR}/lib/${CONFIG}/*.lib" "${BUILD_DIR}/lib/${CONFIG}/*.a" "${BUILD_DIR}/lib/*.so" "${BUILD_DIR}/lib/*.dylib")

if (LIBS)
# Save all library files as a list
set(${UPPER_NAME}_LIBS ${LIBS} PARENT_SCOPE)
message(STATUS "Found libraries for ${name} (${CONFIG}): ${LIBS}")
else()
message(WARNING "No library files found for ${name} in ${BUILD_DIR}/lib/${CONFIG}")
endif()

# Update CMAKE_PREFIX_PATH to include the build directory
list(APPEND CMAKE_PREFIX_PATH ${BUILD_DIR})
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} PARENT_SCOPE)
endfunction()


function(build_physx)
set(PHYSX_NAME "PhysX")
set(PHYSX_DIR ${INNO_GITSUBMODULE_DIRECTORIES}/PhysX/physx)

# Use a single global configuration
set(CONFIG ${CMAKE_BUILD_TYPE})
if (NOT CONFIG)
message(FATAL_ERROR "CMAKE_BUILD_TYPE is not set. Please set it to Debug, Release, etc.")
endif()

if (CONFIG STREQUAL "RelWithDebInfo")
set(CONFIG "Release") # TODO: Use the Profile configuration
endif()

set(BUILD_DIR ${CMAKE_BINARY_DIR}/ThirdParty/${PHYSX_NAME}/${CONFIG})

if (BUILD_THIRD_PARTY)
# Pre-build patch (specific to PhysX)
set(PHYSX_PRESET_FILE ${PHYSX_DIR}/buildtools/presets/public/vc17win64.xml)
file(READ ${PHYSX_PRESET_FILE} CONTENTS)
string(REPLACE "\"NV_USE_STATIC_WINCRT\" value=\"True\"" "\"NV_USE_STATIC_WINCRT\" value=\"False\"" CONTENTS "${CONTENTS}")
file(WRITE ${PHYSX_PRESET_FILE} "${CONTENTS}")
message(STATUS "Patched PhysX configuration for ${CONFIG}")

# Generate projects
message(STATUS "Generating PhysX projects (${CONFIG})")
execute_process(
COMMAND ${PHYSX_DIR}/generate_projects.bat vc17win64
WORKING_DIRECTORY ${PHYSX_DIR}
)

# Build the projects
message(STATUS "Building PhysX (${CONFIG})")
execute_process(
COMMAND ${CMAKE_COMMAND} --build ${PHYSX_DIR}/compiler/vc17win64/
--config ${CONFIG} -j # multi-thread
WORKING_DIRECTORY ${PHYSX_DIR}/compiler/vc17win64
)
else()
message(STATUS "Skipping PhysX build (${CONFIG})")
endif()

string(TOLOWER "${CONFIG}" CONFIG_LOWER)
file(GLOB PHYSX_OUTPUT_DIR "${PHYSX_DIR}/bin/win.x86_64.vc143.md/${CONFIG_LOWER}")
if (NOT PHYSX_OUTPUT_DIR)
message(FATAL_ERROR "Failed to find PhysX output directory for configuration: ${CONFIG}")
endif()

# Collect library paths strictly for the current configuration
file(GLOB CONFIG_LIB_FILES "${PHYSX_OUTPUT_DIR}/*.lib")

if (CONFIG_LIB_FILES)
list(APPEND PHYSX_LIBS ${CONFIG_LIB_FILES})
message(STATUS "Collected PhysX libraries for ${CONFIG}: ${CONFIG_LIB_FILES}")
else()
message(WARNING "No PhysX libraries found for ${CONFIG} in ${PHYSX_OUTPUT_DIR}")
endif()

# Copy runtime files (e.g., .dll) to runtime output directory
file(GLOB DLL_FILES "${PHYSX_OUTPUT_DIR}/*.dll")
if (DLL_FILES)
foreach(DLL_FILE ${DLL_FILES})
file(COPY ${DLL_FILE} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_BUILD_TYPE})
endforeach()
message(STATUS "Copied DLLs for PhysX (${CONFIG}) to runtime output directory.")
else()
message(WARNING "No DLL files found for PhysX (${CONFIG}) in ${PHYSX_OUTPUT_DIR}.")
endif()

# Export variables to parent scope
set(PHYSX_LIBS ${PHYSX_LIBS} PARENT_SCOPE)
set(PHYSX_INCLUDE_DIR "${PHYSX_DIR}/physx/include" PARENT_SCOPE)
endfunction()

function(build_glad)
# Path to glad directory
set(GLAD_SOURCES_DIR "${INNO_GITSUBMODULE_DIRECTORIES}/GLAD")

# Install the dependencies
execute_process(
COMMAND ${Python_EXECUTABLE} -m pip install -r ${GLAD_SOURCES_DIR}/requirements.txt
)

# Path to glad cmake files
add_subdirectory("${GLAD_SOURCES_DIR}/cmake" glad_cmake)

# Specify glad settings
set(GLAD_HEADER_LIB_NAME "glad_gl_core_46")
glad_add_library(${GLAD_HEADER_LIB_NAME} REPRODUCIBLE API gl:core=4.6)
endfunction()

build_third_party(
assimp
${INNO_GITSUBMODULE_DIRECTORIES}/assimp
"-DASSIMP_BUILD_ASSIMP_TOOLS=OFF -DASSIMP_BUILD_TESTS=OFF"
)

build_physx()

build_glad()
55 changes: 55 additions & 0 deletions CMake/DownloadDXC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Define directories
set(DXC_DIR ${CMAKE_BINARY_DIR}/Tools/dxc)
set(DXC_ZIP ${CMAKE_BINARY_DIR}/dxc_latest.zip)

# GitHub API URL for latest DXC release
set(DXC_RELEASE_API "https://api.github.com/repos/microsoft/DirectXShaderCompiler/releases/latest")

# Step 1: Fetch latest release metadata
set(DXC_JSON ${CMAKE_BINARY_DIR}/dxc_release.json)
if (NOT EXISTS ${DXC_JSON})
message(STATUS "Fetching latest DXC release metadata...")
file(DOWNLOAD ${DXC_RELEASE_API} ${DXC_JSON} SHOW_PROGRESS)
endif()

# Step 2: Parse JSON to find the download URL for the DXC ZIP
# Read the JSON content
file(READ ${CMAKE_BINARY_DIR}/dxc_release.json DXC_JSON_CONTENT)

# Extract the assets array
string(JSON DXC_ASSETS GET ${DXC_JSON_CONTENT} "assets")

# Iterate over the array to find the matching asset
set(DXC_DOWNLOAD_URL "")
math(EXPR NUM_ASSETS "0")
string(JSON NUM_ASSETS LENGTH ${DXC_ASSETS})
foreach(INDEX RANGE ${NUM_ASSETS})
string(JSON ASSET_NAME GET ${DXC_ASSETS} ${INDEX} "name")
string(JSON ASSET_URL GET ${DXC_ASSETS} ${INDEX} "browser_download_url")
if (ASSET_NAME MATCHES "^dxc_.*\\.zip$")
set(DXC_DOWNLOAD_URL ${ASSET_URL})
break()
endif()
endforeach()

# Verify the download URL was found
if (NOT DEFINED DXC_DOWNLOAD_URL OR DXC_DOWNLOAD_URL STREQUAL "")
message(FATAL_ERROR "Could not find DXC ZIP download URL in release metadata.")
endif()

message(STATUS "Latest DXC download URL: ${DXC_DOWNLOAD_URL}")


# Step 3: Download the DXC ZIP file
if (NOT EXISTS ${DXC_ZIP})
message(STATUS "Downloading latest DXC binaries...")
file(DOWNLOAD ${DXC_DOWNLOAD_URL} ${DXC_ZIP} SHOW_PROGRESS)
endif()

# Step 4: Extract the DXC ZIP file
if (NOT EXISTS ${DXC_DIR})
message(STATUS "Extracting DXC binaries with PowerShell...")
execute_process(
COMMAND powershell -Command "Expand-Archive -Path '${DXC_ZIP}' -DestinationPath '${DXC_DIR}' -Force"
)
endif()
Loading

0 comments on commit 03123e0

Please sign in to comment.