Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions 3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,17 @@ set(VOLK_PULL_IN_VULKAN OFF CACHE INTERNAL "" FORCE) # Needed to make sure vulka

if (WIN32)
set(VOLK_STATIC_DEFINES VK_USE_PLATFORM_WIN32_KHR)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(VOLK_STATIC_DEFINES VK_USE_PLATFORM_XCB_KHR)
endif()
add_subdirectory(volk volk EXCLUDE_FROM_ALL)

target_include_directories(volk PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/Vulkan-Headers/include")
# vulkaninfo (C++) defines the same global `vkXxx` function pointers volk.c declares as C tentative definitions,
# MSVC merges them as common symbols, GCC>=10 and Clang>=11 default to -fno-common and the link fails on duplicates
if(NOT MSVC)
target_compile_options(volk PRIVATE -fcommon)
endif()
target_include_directories(volk_headers INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/Vulkan-Headers/include")

if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
Expand Down Expand Up @@ -119,6 +126,10 @@ if(NOT NBL_IS_MULTI_CONFIG)
list(APPEND NBL_JPEG_CMAKE_OPTIONS "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
endif()

if(CMAKE_POSITION_INDEPENDENT_CODE)
list(APPEND NBL_JPEG_CMAKE_OPTIONS "-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON")
endif()

if(NOT CMAKE_GENERATOR MATCHES "Ninja*")
list(APPEND NBL_JPEG_CMAKE_OPTIONS -Ax64)
endif()
Expand All @@ -144,13 +155,28 @@ if(NOT "${JPEG_CMAKE_RESULT}" STREQUAL "0")
message(FATAL_ERROR "${JPEG_CMAKE_STREAM_PIPE}")
endif()

set(JPEG_LIB_OUTPUT "${THIRD_PARTY_BINARY_DIR}/libjpeg-turbo/$<CONFIG>/jpeg-static${CMAKE_STATIC_LIBRARY_SUFFIX}")
add_custom_command(OUTPUT ${JPEG_LIB_OUTPUT}
# libjpeg-turbo only names the archive `jpeg-static` for MSVC-like compilers (`libjpeg.a` otherwise)
# and single-config generators don't put outputs in a per-config subdirectory
if(MSVC)
set(_NBL_JPEG_LIB_NAME_ "jpeg-static${CMAKE_STATIC_LIBRARY_SUFFIX}")
else()
set(_NBL_JPEG_LIB_NAME_ "${CMAKE_STATIC_LIBRARY_PREFIX}jpeg${CMAKE_STATIC_LIBRARY_SUFFIX}")
endif()
if(NBL_IS_MULTI_CONFIG)
set(JPEG_LIB_OUTPUT "${THIRD_PARTY_BINARY_DIR}/libjpeg-turbo/$<CONFIG>/${_NBL_JPEG_LIB_NAME_}")
else()
set(JPEG_LIB_OUTPUT "${THIRD_PARTY_BINARY_DIR}/libjpeg-turbo/${_NBL_JPEG_LIB_NAME_}")
endif()
# always step into the child build (a no-op when it's up to date), its own dependency tracking then picks up
# source and flag changes (e.g. PIC) which a custom command OUTPUT without DEPENDS never would
add_custom_target(jpeg-static-build
COMMAND "${CMAKE_COMMAND}" --build "${THIRD_PARTY_BINARY_DIR}/libjpeg-turbo" -t jpeg-static --config $<CONFIG>
BYPRODUCTS "${JPEG_LIB_OUTPUT}"
COMMENT "Building libjpeg-turbo static library"
VERBATIM USES_TERMINAL
)
add_library(jpeg-static INTERFACE ${JPEG_LIB_OUTPUT})
add_library(jpeg-static INTERFACE)
add_dependencies(jpeg-static jpeg-static-build)
target_include_directories(jpeg-static INTERFACE
"${THIRD_PARTY_SOURCE_DIR}/libjpeg-turbo/src"
"${THIRD_PARTY_BINARY_DIR}/libjpeg-turbo"
Expand Down
54 changes: 54 additions & 0 deletions 3rdparty/dxc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,60 @@ if(CMAKE_TOOLCHAIN_FILE)
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")
endif()

# the DXC configure below is a separate CMake invocation, it inherits nothing from this
# cache - forward the toolchain choices explicitly so DXC is built the same way as Nabla
if(NOT MSVC)
list(APPEND NBL_DXC_CMAKE_OPTIONS
"-DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}"
"-DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}"
)
if(CMAKE_LINKER_TYPE)
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DCMAKE_LINKER_TYPE:STRING=${CMAKE_LINKER_TYPE}")
endif()
# TODO: fix in the DXC fork, lib/DxcSupport/dxcmem.cpp calls the Win32-only CoGetMalloc
# instead of the DxcCoGetMalloc adapter (which maps to CoGetMalloc on Windows anyway)
if(NOT WIN32)
# injected as a compile definition after DXC's project() so CMAKE_CXX_FLAGS/CXXFLAGS keep their usual meaning
set(_NBL_DXC_PROJECT_INCLUDE_ "${CMAKE_CURRENT_BINARY_DIR}/nbl-dxc-project-include.cmake")
file(CONFIGURE OUTPUT "${_NBL_DXC_PROJECT_INCLUDE_}" CONTENT "add_compile_definitions(CoGetMalloc=DxcCoGetMalloc)\n")
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DCMAKE_PROJECT_INCLUDE:FILEPATH=${_NBL_DXC_PROJECT_INCLUDE_}")

# TODO: fix in the DXC fork, its merge of upstream main bumped external/DirectX-Headers past the
# commit upstream DXC pins, the newer wsl/stubs/basetsd.h redefines the WinAdapter.h typedefs.
# Until then export the upstream-pinned headers (an ancestor of the fork's pin) and use those.
set(NBL_DXC_DIRECTX_HEADERS_REF 980971e835876dc0cde415e8f9bc646e64667bf7 CACHE STRING "DirectX-Headers commit DXC is built against on non-Windows hosts, empty = the submodule checkout")
if(NBL_DXC_DIRECTX_HEADERS_REF)
find_package(Git REQUIRED)
set(_NBL_DXC_DX_HEADERS_SRC_ "${CMAKE_CURRENT_SOURCE_DIR}/dxc/external/DirectX-Headers")
set(_NBL_DXC_DX_HEADERS_DIR_ "${CMAKE_CURRENT_BINARY_DIR}/DirectX-Headers-${NBL_DXC_DIRECTX_HEADERS_REF}")
if(NOT EXISTS "${_NBL_DXC_DX_HEADERS_DIR_}/include/directx/d3d12.h")
file(MAKE_DIRECTORY "${_NBL_DXC_DX_HEADERS_DIR_}")
execute_process(COMMAND "${GIT_EXECUTABLE}" -C "${_NBL_DXC_DX_HEADERS_SRC_}" archive --format=tar -o "${_NBL_DXC_DX_HEADERS_DIR_}.tar" "${NBL_DXC_DIRECTX_HEADERS_REF}" include
RESULT_VARIABLE _NBL_RES_ ERROR_VARIABLE _NBL_ERR_
)
if(NOT _NBL_RES_ EQUAL 0)
message(FATAL_ERROR "Could not export DirectX-Headers @ ${NBL_DXC_DIRECTX_HEADERS_REF} (shallow submodule?): ${_NBL_ERR_}")
endif()
file(ARCHIVE_EXTRACT INPUT "${_NBL_DXC_DX_HEADERS_DIR_}.tar" DESTINATION "${_NBL_DXC_DX_HEADERS_DIR_}")
file(REMOVE "${_NBL_DXC_DX_HEADERS_DIR_}.tar")
endif()
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DDIRECTX_HEADER_INCLUDE_DIR:PATH=${_NBL_DXC_DX_HEADERS_DIR_}/include")
endif()
endif()
if(USE_CCACHE)
list(APPEND NBL_DXC_CMAKE_OPTIONS
"-DCMAKE_C_COMPILER_LAUNCHER:STRING=${CCACHE_FOUND}"
"-DCMAKE_CXX_COMPILER_LAUNCHER:STRING=${CCACHE_FOUND}"
)
endif()
endif()

# LLVM links are the memory peak of the whole build, by default allow one at a time
set(NBL_DXC_PARALLEL_LINK_JOBS 1 CACHE STRING "LLVM_PARALLEL_LINK_JOBS for the DXC build (Ninja only, empty = unlimited)")
if(CMAKE_GENERATOR MATCHES "Ninja" AND NBL_DXC_PARALLEL_LINK_JOBS)
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DLLVM_PARALLEL_LINK_JOBS:STRING=${NBL_DXC_PARALLEL_LINK_JOBS}")
endif()

# TODO: add_subdirectory but don't modify dxc target compile options
execute_process(COMMAND "${CMAKE_COMMAND}" -C "${CMAKE_CURRENT_SOURCE_DIR}/dxc/cmake/caches/PredefinedParams.cmake" -S "${CMAKE_CURRENT_SOURCE_DIR}/dxc" -B "${DXC_BUILD_DIR}" -G "${CMAKE_GENERATOR}" ${NBL_DXC_CMAKE_OPTIONS}
RESULT_VARIABLE DXC_CMAKE_RESULT
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ else()
if(NOT NBL_COMPILER_DYNAMIC_RUNTIME)
message(FATAL_ERROR "Turn NBL_COMPILER_DYNAMIC_RUNTIME on! For dynamic Nabla builds dynamic runtime is mandatory!")
endif()
# static 3rdparty archives get linked into the Nabla shared object, ELF needs them position independent (no-op for PE/COFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

find_package(Vulkan)
Expand Down
35 changes: 30 additions & 5 deletions cmake/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ macro(nbl_create_executable_project _EXTRA_SOURCES _EXTRA_OPTIONS _EXTRA_INCLUDE
nbl_adjust_flags(TARGET ${EXECUTABLE_NAME} MAP_RELEASE Release MAP_RELWITHDEBINFO RelWithDebInfo MAP_DEBUG Debug)
nbl_adjust_definitions()

# executables reuse PCHs of static libraries (e.g. the examples API), which are built -fPIC in a shared
# build, and Clang rejects a -fPIC PCH in an -fPIE translation unit; after nbl_adjust_flags, it resets the options
if(NOT WIN32 AND NOT ANDROID AND CMAKE_POSITION_INDEPENDENT_CODE)
set_target_properties(${EXECUTABLE_NAME} PROPERTIES POSITION_INDEPENDENT_CODE OFF)
target_compile_options(${EXECUTABLE_NAME} PRIVATE -fPIC)
endif()

add_compile_options(${_EXTRA_OPTIONS})
add_definitions(-D_NBL_PCH_IGNORE_PRIVATE_HEADERS) # TODO: wipe when we finally make Nabla PCH work as its supposed to
set_target_properties(${EXECUTABLE_NAME} PROPERTIES
Expand Down Expand Up @@ -195,6 +202,13 @@ macro(nbl_create_executable_project _EXTRA_SOURCES _EXTRA_OPTIONS _EXTRA_INCLUDE
PRIVATE "-DNBL_CPACK_PACKAGE_NABLA_DLL_DIR=\"${_NBL_NABLA_PACKAGE_RUNTIME_DLL_DIR_PATH_REL_TO_TARGET_}\""
PRIVATE "-DNBL_CPACK_PACKAGE_DXC_DLL_DIR=\"${_NBL_DXC_PACKAGE_RUNTIME_DLL_DIR_PATH_REL_TO_TARGET_}\""
)
# ELF has no delay loading, the installed executable finds Nabla and DXC through its RUNPATH
if(UNIX AND NOT APPLE AND NOT ANDROID)
set_property(TARGET ${EXECUTABLE_NAME} APPEND PROPERTY INSTALL_RPATH
"$ORIGIN/${_NBL_NABLA_PACKAGE_RUNTIME_DLL_DIR_PATH_REL_TO_TARGET_}"
"$ORIGIN/${_NBL_DXC_PACKAGE_RUNTIME_DLL_DIR_PATH_REL_TO_TARGET_}"
)
endif()
endif()

nbl_project_process_test_module()
Expand Down Expand Up @@ -297,11 +311,20 @@ function(nbl_install_program_spec _TRGT _RELATIVE_DESTINATION)
set(_DEST_GE_ "${_NBL_CPACK_PACKAGE_RELATIVE_ENTRY_}/runtime/${_RELATIVE_DESTINATION}")

if (TARGET ${_TRGT})
get_target_property(_TYPE_ ${_TRGT} TYPE)
foreach(_CONFIGURATION_ IN LISTS CMAKE_CONFIGURATION_TYPES)
install(PROGRAMS $<TARGET_FILE:${_TRGT}> DESTINATION ${_DEST_GE_} CONFIGURATIONS ${_CONFIGURATION_} COMPONENT Runtimes)
# a plain file copy keeps the build RPATH (absolute build tree paths) of an ELF/Mach-O shared object,
# install(TARGETS) swaps it for INSTALL_RPATH
if(NOT WIN32 AND _TYPE_ MATCHES "^(SHARED|MODULE)_LIBRARY$")
install(TARGETS ${_TRGT} LIBRARY DESTINATION ${_DEST_GE_} CONFIGURATIONS ${_CONFIGURATION_} COMPONENT Runtimes)
else()
install(PROGRAMS $<TARGET_FILE:${_TRGT}> DESTINATION ${_DEST_GE_} CONFIGURATIONS ${_CONFIGURATION_} COMPONENT Runtimes)
endif()
endforeach()

install(PROGRAMS $<TARGET_PDB_FILE:${_TRGT}> DESTINATION debug/runtime/${_RELATIVE_DESTINATION} CONFIGURATIONS Debug COMPONENT Runtimes) # TODO: write cmake script with GE to detect if target in configuration has PDB files generated then add install rule
if(MSVC) # PDBs only exist with MSVC-style linkers, $<TARGET_PDB_FILE> is an error elsewhere
install(PROGRAMS $<TARGET_PDB_FILE:${_TRGT}> DESTINATION debug/runtime/${_RELATIVE_DESTINATION} CONFIGURATIONS Debug COMPONENT Runtimes) # TODO: write cmake script with GE to detect if target in configuration has PDB files generated then add install rule
endif()

get_property(_DEFINED_PROPERTY_
TARGET ${_TRGT}
Expand Down Expand Up @@ -362,9 +385,11 @@ function(nbl_install_exe_spec _TARGETS _RELATIVE_DESTINATION)

install(TARGETS ${_TARGETS} ${_EXPORT_ARGS} RUNTIME DESTINATION ${_DEST_GE_} COMPONENT ${_COMPONENT})

foreach(_TRGT IN LISTS _TARGETS)
install(PROGRAMS $<TARGET_PDB_FILE:${_TRGT}> DESTINATION debug/exe/${_RELATIVE_DESTINATION} CONFIGURATIONS Debug COMPONENT ${_COMPONENT})
endforeach()
if(MSVC) # PDBs only exist with MSVC-style linkers
foreach(_TRGT IN LISTS _TARGETS)
install(PROGRAMS $<TARGET_PDB_FILE:${_TRGT}> DESTINATION debug/exe/${_RELATIVE_DESTINATION} CONFIGURATIONS Debug COMPONENT ${_COMPONENT})
endforeach()
endif()

foreach(_TRGT IN LISTS _TARGETS)
get_property(_DEFINED_PROPERTY_
Expand Down
2 changes: 2 additions & 0 deletions docs/build/LINUX.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Linux build

> For the up-to-date Linux build guide, toolchain setup, and validation steps, see [docs/linux-build.md](../linux-build.md).

## Supported toolsets

- **[GCC](https://gcc.gnu.org/)**
Expand Down
Loading