Skip to content

Commit 69ef3b5

Browse files
committed
🚚 Clean up boilerplate for executables
- separate cmake file for each target - add cmake options for each target - loader queries are now a separate executable, rather than special arguments for each executable - this is both cleaner, and opens the path to supporting loader queries for 32-bit too
1 parent 576b44d commit 69ef3b5

17 files changed

+329
-359
lines changed

‎src/CMakeLists.txt‎

Lines changed: 15 additions & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Copyright 2023 Fred Emmott <[email protected]>
22
# SPDX-License-Identifier: ISC
33

4-
find_package(imgui CONFIG REQUIRED)
54
find_package(nlohmann_json CONFIG REQUIRED)
5+
find_package(imgui CONFIG REQUIRED)
66
find_package(OpenXR CONFIG REQUIRED)
77
# Using fmt instead of fmt::format until MacOS/libc++ catch up
88
find_package(fmt CONFIG REQUIRED)
@@ -25,198 +25,22 @@ configure_file(
2525
"${CODEGEN_BUILD_DIR}/Config.hpp"
2626
@ONLY
2727
)
28+
add_library(config-hpp INTERFACE "${CODEGEN_BUILD_DIR}/Config.hpp")
29+
target_include_directories(config-hpp INTERFACE "${CODEGEN_BUILD_DIR}")
2830

29-
add_library(
30-
lib
31-
STATIC
32-
APILayerDetails.cpp
33-
APILayerSignature.hpp
34-
ConstexprString.hpp
35-
GUI.cpp
36-
LoaderData.cpp LoaderData.hpp
37-
SaveReport.cpp
38-
Platform.cpp Platform.hpp
39-
StringTemplateParameter.hpp
40-
)
41-
42-
# Using an OBJECT library instead of `STATIC`, because otherwise
43-
# Microsoft's linker gets rid of the static initializers used to register linters :(
44-
add_library(
45-
linters
46-
OBJECT
47-
Linter.cpp
48-
LayerRules.cpp
49-
linters/BadInstallationLinter.cpp
50-
linters/DuplicatesLinter.cpp
51-
linters/OrderingLinter.cpp
52-
linters/DisabledByEnvironmentLinter.cpp
53-
linters/SkippedByLoaderLinter.cpp
54-
)
55-
target_link_libraries(linters PUBLIC lib)
56-
target_include_directories(
57-
lib
58-
PUBLIC
59-
"${CODEGEN_BUILD_DIR}"
60-
"${CMAKE_CURRENT_SOURCE_DIR}"
61-
)
62-
63-
target_link_libraries(
64-
lib
65-
PUBLIC
66-
nlohmann_json::nlohmann_json
67-
fmt::fmt-header-only
68-
imgui::imgui
69-
OpenXR::headers OpenXR::openxr_loader
70-
)
71-
72-
add_executable(
73-
gui
74-
WIN32
75-
"${CMAKE_SOURCE_DIR}/icon/icon.rc"
76-
)
77-
78-
# Used by version.in.rc
79-
set(OUTPUT_NAME "OpenXR-API-Layers-GUI")
80-
set_target_properties(
81-
gui
82-
PROPERTIES
83-
OUTPUT_NAME "${OUTPUT_NAME}"
84-
)
85-
target_link_libraries(gui PRIVATE lib linters)
86-
87-
set(PLATFORM_APILAYERS_CPP "stubs/APILayerStore.cpp")
88-
set(PLATFORM_MAIN_CPP "main.cpp")
89-
set(PLATFORM_GUI_CPP "stubs/PlatformGUI.cpp")
90-
set(PLATFORM_REPORT_MAIN_CPP "SaveReport_main.cpp")
91-
92-
if (WIN32)
93-
set(PLATFORM_APILAYERS_CPP "windows/WindowsAPILayerStore.cpp")
94-
set(PLATFORM_GUI_CPP "windows/WindowsPlatform.cpp")
95-
set(PLATFORM_MAIN_CPP "windows/wWinMain.cpp")
96-
set(PLATFORM_REPORT_MAIN_CPP "windows/SaveReport_wWinMain.cpp")
97-
98-
configure_file(
99-
"${CMAKE_CURRENT_SOURCE_DIR}/version.in.rc"
100-
"${CODEGEN_BUILD_DIR}/gui-version.rc"
101-
@ONLY
102-
)
103-
104-
target_sources(
105-
lib
106-
PRIVATE
107-
windows/CheckForUpdates.cpp
108-
windows/WindowsPlatform.hpp
109-
)
110-
111-
target_sources(
112-
linters
113-
PRIVATE
114-
linters/windows/NotADWORDLinter.cpp
115-
linters/windows/OpenXRToolkitLinter.cpp
116-
linters/windows/OutdatedOpenKneeboardLinter.cpp
117-
linters/windows/ProgramFilesLinter.cpp
118-
linters/windows/UnsignedDllLinter.cpp
119-
linters/windows/XRNeckSaferLinter.cpp
120-
)
121-
122-
target_sources(
123-
gui
124-
PRIVATE
125-
"${CODEGEN_BUILD_DIR}/gui-version.rc"
126-
manifest.xml
127-
)
128-
129-
target_compile_definitions(
130-
lib
131-
PUBLIC
132-
"WIN32_LEAN_AND_MEAN"
133-
"NOMINMAX"
134-
"UNICODE"
135-
"_UNICODE"
136-
)
137-
138-
target_compile_options(
139-
lib
140-
PUBLIC
141-
"/EHsc"
142-
"/diagnostics:caret"
143-
"/utf-8"
144-
)
145-
146-
target_link_libraries(
147-
lib
148-
PUBLIC
149-
WIL::WIL
150-
)
151-
set(
152-
WINDOWS_SDK_LIBRARIES
153-
Comctl32
154-
D3d11
155-
DwmApi
156-
Dxgi
157-
RuntimeObject
158-
Crypt32
159-
WinTrust
160-
)
161-
foreach (NAME IN LISTS WINDOWS_SDK_LIBRARIES)
162-
set(LIB_PATH_VAR "${NAME}_PATH}")
163-
find_library("${LIB_PATH_VAR}" NAMES "${NAME}" REQUIRED)
164-
target_link_libraries(lib PUBLIC "${${LIB_PATH_VAR}}")
165-
endforeach ()
166-
167-
target_link_options(
168-
gui
169-
PRIVATE
170-
"/MANIFESTUAC:level='requireAdministrator'"
171-
)
31+
option(BUILD_EXECUTABLES "Build executables" ON)
17232

33+
option(BUILD_GUI "Build the GUI" "${BUILD_EXECUTABLES}")
34+
if (BUILD_GUI)
35+
include(gui.cmake)
17336
endif ()
17437

175-
target_sources(
176-
lib
177-
PRIVATE
178-
"${PLATFORM_APILAYERS_CPP}"
179-
"${PLATFORM_GUI_CPP}"
180-
)
181-
target_sources(
182-
gui
183-
PRIVATE
184-
"${PLATFORM_MAIN_CPP}"
185-
)
186-
187-
set(OUTPUT_NAME "OpenXR-API-Layers-Create-Report")
188-
configure_file(
189-
"${CMAKE_CURRENT_SOURCE_DIR}/version.in.rc"
190-
"${CODEGEN_BUILD_DIR}/create-report-version.rc"
191-
@ONLY
192-
)
193-
add_executable(
194-
create-report
195-
WIN32
196-
"${PLATFORM_REPORT_MAIN_CPP}"
197-
"${CMAKE_SOURCE_DIR}/icon/icon.rc"
198-
"${CODEGEN_BUILD_DIR}/create-report-version.rc"
199-
)
200-
target_link_libraries(
201-
create-report
202-
PRIVATE
203-
lib
204-
linters
205-
)
206-
set_target_properties(
207-
create-report
208-
PROPERTIES
209-
OUTPUT_NAME "${OUTPUT_NAME}"
210-
)
211-
212-
if (WIN32)
213-
set(UPDATER_FILENAME "fredemmott_OpenXR-API-Layers-GUI_Updater.exe")
214-
add_custom_command(
215-
TARGET gui POST_BUILD
216-
COMMAND
217-
"${CMAKE_COMMAND}" -E copy_if_different
218-
"${UPDATER_EXE}"
219-
"$<TARGET_FILE_DIR:gui>/${UPDATER_FILENAME}"
220-
VERBATIM
221-
)
38+
option(BUILD_CREATE_REPORT "Build the Create-Report executable" "${BUILD_EXECUTABLES}")
39+
if (BUILD_CREATE_REPORT)
40+
include(create-report.cmake)
22241
endif ()
42+
43+
option(BUILD_LOADER_DATA "Build the loader-data executable" "${BUILD_EXECUTABLES}")
44+
if (BUILD_LOADER_DATA)
45+
include(loader-data.cmake)
46+
endif ()

‎src/LoaderData.cpp‎

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,6 @@
1414

1515
namespace FredEmmott::OpenXRLayers {
1616

17-
LoaderData QueryLoaderDataInCurrentProcess() {
18-
LoaderData ret {
19-
.mEnvironmentVariablesBeforeLoader
20-
= Platform::Get().GetEnvironmentVariableNames(),
21-
};
22-
23-
// We don't care about the extensions, but enumerating them can load the
24-
// runtime DLL, which can call `setenv()` and change the rest
25-
uint32_t propertyCount {};
26-
ret.mQueryExtensionsResult = xrEnumerateInstanceExtensionProperties(
27-
nullptr, 0, &propertyCount, nullptr);
28-
29-
uint32_t layerCount {};
30-
ret.mQueryLayersResult
31-
= xrEnumerateApiLayerProperties(0, &layerCount, nullptr);
32-
ret.mEnvironmentVariablesAfterLoader
33-
= Platform::Get().GetEnvironmentVariableNames();
34-
if (XR_FAILED(ret.mQueryLayersResult)) {
35-
return ret;
36-
}
37-
38-
std::vector<XrApiLayerProperties> layers(
39-
layerCount, {XR_TYPE_API_LAYER_PROPERTIES});
40-
ret.mQueryLayersResult
41-
= xrEnumerateApiLayerProperties(layerCount, &layerCount, layers.data());
42-
43-
for (auto&& layer: layers) {
44-
ret.mEnabledLayerNames.emplace(layer.layerName);
45-
}
46-
47-
return ret;
48-
}
49-
5017
void to_json(nlohmann::json& j, const LoaderData& data) {
5118
j.update(
5219
nlohmann::json {
@@ -74,11 +41,4 @@ void from_json(const nlohmann::json& j, LoaderData& data) {
7441
.get_to(data.mEnvironmentVariablesAfterLoader);
7542
}
7643

77-
void LoaderMain() {
78-
const auto data = QueryLoaderDataInCurrentProcess();
79-
const nlohmann::json json(data);
80-
81-
std::cout << std::setw(2) << json << std::endl;
82-
}
83-
8444
}// namespace FredEmmott::OpenXRLayers

‎src/LoaderData.hpp‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,4 @@ struct LoaderData {
5252
void from_json(const nlohmann::json&, LoaderData&);
5353
void to_json(nlohmann::json&, const LoaderData&);
5454

55-
void LoaderMain();
56-
5755
}// namespace FredEmmott::OpenXRLayers

‎src/LoaderDataMain.cpp‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2025 Fred Emmott <[email protected]>
2+
// SPDX-License-Identifier: MIT
3+
#include "LoaderDataMain.hpp"
4+
5+
#include <nlohmann/json.hpp>
6+
7+
#include <iostream>
8+
9+
#include "LoaderData.hpp"
10+
#include "Platform.hpp"
11+
12+
namespace FredEmmott::OpenXRLayers {
13+
14+
static LoaderData QueryLoaderDataInCurrentProcess() {
15+
LoaderData ret {
16+
.mEnvironmentVariablesBeforeLoader
17+
= Platform::Get().GetEnvironmentVariableNames(),
18+
};
19+
20+
// We don't care about the extensions, but enumerating them can load the
21+
// runtime DLL, which can call `setenv()` and change the rest
22+
uint32_t propertyCount {};
23+
ret.mQueryExtensionsResult = xrEnumerateInstanceExtensionProperties(
24+
nullptr, 0, &propertyCount, nullptr);
25+
26+
uint32_t layerCount {};
27+
ret.mQueryLayersResult
28+
= xrEnumerateApiLayerProperties(0, &layerCount, nullptr);
29+
ret.mEnvironmentVariablesAfterLoader
30+
= Platform::Get().GetEnvironmentVariableNames();
31+
if (XR_FAILED(ret.mQueryLayersResult)) {
32+
return ret;
33+
}
34+
35+
std::vector<XrApiLayerProperties> layers(
36+
layerCount, {XR_TYPE_API_LAYER_PROPERTIES});
37+
ret.mQueryLayersResult
38+
= xrEnumerateApiLayerProperties(layerCount, &layerCount, layers.data());
39+
40+
for (auto&& layer: layers) {
41+
ret.mEnabledLayerNames.emplace(layer.layerName);
42+
}
43+
44+
return ret;
45+
}
46+
47+
void LoaderDataMain() {
48+
const auto data = QueryLoaderDataInCurrentProcess();
49+
const nlohmann::json json(data);
50+
51+
std::cout << std::setw(2) << json << std::endl;
52+
}
53+
54+
}// namespace FredEmmott::OpenXRLayers

‎src/LoaderDataMain.hpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2025 Fred Emmott <[email protected]>
2+
// SPDX-License-Identifier: MIT
3+
#pragma once
4+
5+
namespace FredEmmott::OpenXRLayers {
6+
void LoaderDataMain();
7+
}

‎src/create-report.cmake‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
include(lib.cmake)
2+
3+
add_executable(create-report WIN32)
4+
5+
target_link_libraries(
6+
create-report
7+
PRIVATE
8+
lib
9+
linters
10+
)
11+
12+
set(OUTPUT_NAME "OpenXR-API-Layers-Create-Report")
13+
set_target_properties(
14+
create-report
15+
PROPERTIES
16+
OUTPUT_NAME "${OUTPUT_NAME}"
17+
)
18+
configure_file(
19+
"${CMAKE_CURRENT_SOURCE_DIR}/version.in.rc"
20+
"${CODEGEN_BUILD_DIR}/create-report-version.rc"
21+
@ONLY
22+
)
23+
24+
if (WIN32)
25+
target_sources(
26+
create-report
27+
PRIVATE
28+
"${CMAKE_SOURCE_DIR}/icon/icon.rc"
29+
windows/wWinMain-create-report.cpp
30+
"${CODEGEN_BUILD_DIR}/create-report-version.rc"
31+
)
32+
endif ()

0 commit comments

Comments
 (0)