Skip to content

Commit

Permalink
Update resources script/metadata for windows dlls builds
Browse files Browse the repository at this point in the history
  • Loading branch information
1runeberg committed Jul 13, 2024
1 parent cba7ef4 commit 51872a8
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 10 deletions.
23 changes: 14 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ set(CMAKE_SUPPRESS_REGENERATION true)

# Set project variables
set(XRLIB "xrlib")
project("${XRLIB}" VERSION 1.0.0)
project("${XRLIB}" VERSION 1.0.0.0)

# Set project directories
set(XRLIB_ROOT "${CMAKE_CURRENT_SOURCE_DIR}")
Expand All @@ -22,6 +22,7 @@ set(XRLIB_INCLUDE "${XRLIB_ROOT}/include")
set(XRLIB_BIN_OUT "${XRLIB_ROOT}/bin")
set(XRLIB_LIB_OUT "${XRLIB_ROOT}/lib")
set(THIRD_PARTY "${XRLIB_ROOT}/third_party")
set(OPENXR_INCLUDE "${THIRD_PARTY}/openxr/include")

set(XRVK_INCLUDE "${XRLIB_INCLUDE}/xrvk")
set(XRVK_SRC "${XRLIB_SRC}/xrvk")
Expand All @@ -30,6 +31,14 @@ set(XRVK_SRC "${XRLIB_SRC}/xrvk")
set(XRLIB_CONFIG_IN "${XRLIB_ROOT}/project_config.h.in")
set(XRLIB_CONFIG_OUT "${XRLIB_INCLUDE}/project_config.h")

# For windows, we need to override openxr's resource script, so define the rc files here which will be used during binary pre-build
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(SRC_RC "${CMAKE_CURRENT_SOURCE_DIR}/win_dll_metadata.rc")
set(DST_RC "${CMAKE_CURRENT_SOURCE_DIR}/third_party/openxr/src/loader/loader.rc")

execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${SRC_RC} ${DST_RC})
endif()

# Set config files
file(GLOB XRLIB_CONFIG
"${XRLIB_ROOT}/.clang-format"
Expand Down Expand Up @@ -188,6 +197,7 @@ target_include_directories(${XRLIB} PUBLIC "${XRLIB_SRC}"
"${XRLIB_INCLUDE}"
"${XRLIB_ROOT}"
"${THIRD_PARTY}"
"${OPENXR_INCLUDE}"
"${Vulkan_INCLUDE_DIRS}"
)
# For Android, add the native app glue NDK directory
Expand Down Expand Up @@ -224,17 +234,13 @@ if(ANDROID)

find_library(ANDROID_LIBRARY NAMES android)
find_library(ANDROID_LOG_LIBRARY NAMES log)
target_link_libraries(
${XRLIB} PUBLIC
openxr_loader
target_link_libraries(${XRLIB} PUBLIC
${Vulkan_LIBRARY}
${ANDROID_LIBRARY}
${ANDROID_LOG_LIBRARY}
)
else()
target_link_libraries(
${XRLIB} PUBLIC
openxr_loader
target_link_libraries(${XRLIB} PUBLIC
${Vulkan_LIBRARY}
)
endif()
Expand Down Expand Up @@ -262,8 +268,7 @@ message(STATUS "[${XRLIB}] Project libraries will be built in: ${XRLIB_LIB_OUT}"
message(STATUS "[${XRLIB}] Project binaries will be built in: ${XRLIB_BIN_OUT}")

# Post-Build
add_custom_command(
TARGET ${XRLIB} POST_BUILD
add_custom_command(TARGET ${XRLIB} POST_BUILD

# Create output directories
COMMAND ${CMAKE_COMMAND} -E make_directory "${XRLIB_LIB_OUT}"
Expand Down
3 changes: 3 additions & 0 deletions include/project_config.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#define XRLIB_NAME "xrlib"

#define XRLIB_VERSION_MAJOR 1
#define XRLIB_VERSION_MINOR 0
#define XRLIB_VERSION_PATCH 0
#define XRLIB_VERSION_TWEAK 0
#define XRLIB_VERSION XRLIB_VERSION_MAJOR "." XRLIB_VERSION_MINOR "." XRLIB_VERSION_PATCH "." XRLIB_VERSION_TWEAK

#ifdef XR_USE_PLATFORM_ANDROID
#define XRLIB_ASSETS_FOLDER ""
Expand Down
1 change: 0 additions & 1 deletion include/xrlib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@

#include <xrlib/session.hpp>
#include <xrlib/vulkan.hpp>

2 changes: 2 additions & 0 deletions project_config.h.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#define XRLIB_NAME "xrlib"

#define XRLIB_VERSION_MAJOR @xrlib_VERSION_MAJOR@
#define XRLIB_VERSION_MINOR @xrlib_VERSION_MINOR@
#define XRLIB_VERSION_PATCH @xrlib_VERSION_PATCH@
#define XRLIB_VERSION_TWEAK @xrlib_VERSION_TWEAK@

#ifdef XR_USE_PLATFORM_ANDROID
#define XRLIB_ASSETS_FOLDER ""
Expand Down
76 changes: 76 additions & 0 deletions win_dll_metadata.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* xrlib:
* Copyright (c) 2024 Rune Berg (http://runeberg.io | https://github.com/1runeberg)
* Licensed under Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0)
* SPDX-License-Identifier: Apache-2.0
*
* openxr_loader:
* Copyright (c) 2017-2024, The Khronos Group Inc.
* Copyright (c) 2017 Valve Corporation
* Copyright (c) 2017 LunarG, Inc.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
* Initial Author: Mark Young <[email protected]>
*
* =============================================================================
* THIS WINDOWS RESOURCE FILE REPLACES OPENXR'S LOADER RC DURING XRLIB CMAKE RUN
* =============================================================================
*/

#ifdef __MINGW32__
#include "winresrc.h" // For GCC/GNU toolchain
#else
#include "winres.h" // MSVC toolchain
#endif

#define XRLIB_NAME "xrlib"
#define XRLIB_VERSION_MAJOR 1
#define XRLIB_VERSION_MINOR 0
#define XRLIB_VERSION_PATCH 0
#define XRLIB_VERSION_TWEAK 0

#define XRLIB_VERSION XRLIB_VERSION_MAJOR "." XRLIB_VERSION_MINOR "." XRLIB_VERSION_PATCH "." XRLIB_VERSION_TWEAK
#define OPENXR_VERSION "1.1.38"
#define XRLIB_PRODUCT_NAME "xrlib 1.0.0.0 | openxr_loader 1.1.38"

#define XRLIB_COMPANY_NAME "https://github.com/1runeberg/xrlib"
#define XRLIB_FILE_DESC "xrlib - OpenXR wrapper library for modern C++"
#define XRLIB_FILENAME XRLIB_NAME ".dll"
#define XRLIB_COPYRIGHT "xrlib (c) 2024 Rune Berg | openxr_loader (c) 2017-24 The Khronos Group Inc."

VS_VERSION_INFO VERSIONINFO
FILEVERSION XRLIB_VERSION_MAJOR,XRLIB_VERSION_MINOR,XRLIB_VERSION_PATCH,XRLIB_VERSION_TWEAK // Define the file version using macros from version.h
PRODUCTVERSION XRLIB_VERSION_MAJOR,XRLIB_VERSION_MINOR,XRLIB_VERSION_PATCH,XRLIB_VERSION_TWEAK // Define the product version using macros from version.h
FILEFLAGSMASK 0x3fL // Specify which flags in FILEFLAGS are valid (0x3fL means all six defined flags can be used)

#ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG // If this is a debug build, set the debug flag
#else
FILEFLAGS 0x0L // Otherwise, no special flags are set
#endif

FILEOS VOS_NT_WINDOWS32 // Targeting Windows NT-based OS (both 32-bit and 64-bit)
FILETYPE VFT_DLL // Identify as a shared library (dll)
FILESUBTYPE VFT2_UNKNOWN // No specific subtype

BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0" // Language and code page: 0x0409 is U.S. English, 0x04B0 is Unicode
BEGIN
VALUE "CompanyName", XRLIB_COMPANY_NAME
VALUE "FileDescription", XRLIB_FILE_DESC
VALUE "FileVersion", XRLIB_VERSION
VALUE "InternalName", XRLIB_NAME
VALUE "OriginalFilename", XRLIB_FILENAME
VALUE "ProductName", XRLIB_PRODUCT_NAME
VALUE "ProductVersion", XRLIB_VERSION
VALUE "Copyright", XRLIB_COPYRIGHT
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x1409, 0x04B0 // Language: 0x0409 (U.S. English), Code page: 0x04B0 (Unicode)
END
END

0 comments on commit 51872a8

Please sign in to comment.