Skip to content

Commit

Permalink
Clean up WIN32/WindowsStore in CMake projects.
Browse files Browse the repository at this point in the history
This simplifies things in most places by removing WindowsStore-specific
code or fixing areas that assume "Windows" system when they should
assume WIN32 (which includes WindowsStore). As a consequence, more
projects can be built for UWP. Finally, this fixes build issues when
building ARM/ARM64 for Win32 related to bad OpenGL and Vulkan
detection in CMake.
  • Loading branch information
brycehutchings committed Aug 4, 2020
1 parent af531e9 commit 7fd2486
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 20 deletions.
20 changes: 12 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ include(StdFilesystemFlags)

### Dependencies

# Skip detection of OpenGL/Vulkan for UWP "WindowsStore" build, otherwise the OpenGL package will be found for UWP
# apps but gl.h isn't compatible. Similarly, there is no ARM/ARM64 support in the Windows Vulkan SDK.
if(NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
# CMake will detect OpenGL/Vulkan which are not compatible with UWP and ARM/ARM64 on Windows so skip it in these cases.
string(TOUPPER "${CMAKE_GENERATOR_PLATFORM}" CMAKE_GENERATOR_PLATFORM_UPPER)
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" OR (WIN32 AND CMAKE_GENERATOR_PLATFORM_UPPER MATCHES "ARM.*"))
set(OPENGL_INCOMPATIBLE TRUE)
set(VULKAN_INCOMPATIBLE TRUE)
message(STATUS "OpenGL/Vulkan disabled due to incompatibility")
endif()

if(NOT OPENGL_INCOMPATIBLE)
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL)

Expand All @@ -43,7 +49,9 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
elseif(BUILD_ALL_EXTENSIONS)
message(FATAL_ERROR "OpenGL not found")
endif()
endif()

if(NOT VULKAN_INCOMPATIBLE)
if(NOT CMAKE_VERSION VERSION_LESS 3.7.0)
# Find the Vulkan headers
find_package(VulkanHeaders)
Expand Down Expand Up @@ -77,7 +85,7 @@ endif()
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/api_layers/CMakeLists.txt")
option(BUILD_API_LAYERS "Build API layers" ON)
endif()
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/CMakeLists.txt" AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/CMakeLists.txt")
option(BUILD_TESTS "Build tests" ON)
endif()
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/conformance/CMakeLists.txt")
Expand Down Expand Up @@ -127,10 +135,6 @@ endif()
# Several files use these compile-time platform switches
if(WIN32)
add_definitions(-DXR_USE_PLATFORM_WIN32)
# TODO remove once work is done to get more stuff building for UWP.
if (CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
set(BUILD_TESTS OFF)
endif()
elseif(PRESENTATION_BACKEND MATCHES "xlib")
add_definitions(-DXR_USE_PLATFORM_XLIB)
elseif(PRESENTATION_BACKEND MATCHES "xcb")
Expand Down
4 changes: 0 additions & 4 deletions src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
#

add_subdirectory(list)
if(OPENGL_FOUND AND NOT TARGET openxr-gfxwrapper)
return()
endif()

add_subdirectory(hello_xr)
if(BUILD_LOADER)
add_subdirectory(loader_test)
Expand Down
2 changes: 1 addition & 1 deletion src/tests/hello_xr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ target_link_libraries(hello_xr openxr_loader)
if(TARGET openxr-gfxwrapper)
target_link_libraries(hello_xr openxr-gfxwrapper)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
if(WIN32)
if(MSVC)
target_compile_definitions(hello_xr PRIVATE _CRT_SECURE_NO_WARNINGS)
target_compile_options(hello_xr PRIVATE /Zc:wchar_t /Zc:forScope /W4 /WX)
Expand Down
2 changes: 0 additions & 2 deletions src/tests/list/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ if(MSVC)
endif()

set_target_properties(runtime_list PROPERTIES FOLDER ${TESTS_FOLDER})
set_target_properties(runtime_list PROPERTIES OUTPUT_NAME openxr_runtime_list)


install(TARGETS runtime_list
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
Expand Down
2 changes: 1 addition & 1 deletion src/tests/loader_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ if(VulkanHeaders_FOUND)
)
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
if(WIN32)
if(MSVC)
target_compile_definitions(loader_test PRIVATE _CRT_SECURE_NO_WARNINGS)
target_compile_options(loader_test PRIVATE /Zc:wchar_t /Zc:forScope /W4 /WX)
Expand Down
6 changes: 3 additions & 3 deletions src/tests/loader_test/loader_test_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
#if defined(XR_OS_WINDOWS)

bool LoaderTestSetEnvironmentVariable(const std::string &variable, const std::string &value) {
return TRUE == SetEnvironmentVariable(variable.c_str(), value.c_str());
return TRUE == SetEnvironmentVariableA(variable.c_str(), value.c_str());
}

bool LoaderTestGetEnvironmentVariable(const std::string &variable, std::string &value) {
char buf_data[4096];
uint32_t num_chars = GetEnvironmentVariable(variable.c_str(), buf_data, 4095);
uint32_t num_chars = GetEnvironmentVariableA(variable.c_str(), buf_data, 4095);
if (0 == num_chars) {
return false;
}
Expand All @@ -49,7 +49,7 @@ bool LoaderTestGetEnvironmentVariable(const std::string &variable, std::string &
}

bool LoaderTestUnsetEnvironmentVariable(const std::string &variable) {
return TRUE == SetEnvironmentVariable(variable.c_str(), "");
return TRUE == SetEnvironmentVariableA(variable.c_str(), "");
}

#elif defined(XR_OS_LINUX)
Expand Down
2 changes: 1 addition & 1 deletion src/tests/loader_test/test_runtimes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ macro(gen_xr_runtime_json filename libfile)
)
endmacro()

if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
if(WIN32)
target_compile_definitions(test_runtime PRIVATE _CRT_SECURE_NO_WARNINGS)
# Turn off transitional "changed behavior" warning message for Visual Studio versions prior to 2015.
# The changed behavior is that constructor initializers are now fixed to clear the struct members.
Expand Down

0 comments on commit 7fd2486

Please sign in to comment.