Skip to content

Commit

Permalink
Merge pull request #199 from brycehutchings/build_more_projects_for_uwp
Browse files Browse the repository at this point in the history
Clean up WIN32/WindowsStore in CMake projects.
  • Loading branch information
rpavlik authored Aug 6, 2020
2 parents 2cf2faa + 896d965 commit 73c4051
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 28 deletions.
1 change: 1 addition & 0 deletions changes/sdk/pr.199.gh.OpenXR-SDK-Source.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support for building more projects when targeting UWP, and support for all architectures when targeting Win32.
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
18 changes: 8 additions & 10 deletions src/tests/list/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,32 @@
# Author:
#

add_executable(runtime_list
add_executable(openxr_runtime_list
list.cpp
)
add_dependencies(runtime_list
add_dependencies(openxr_runtime_list
generate_openxr_header
)
target_include_directories(runtime_list
target_include_directories(openxr_runtime_list
PRIVATE ${PROJECT_SOURCE_DIR}/src
PRIVATE ${PROJECT_SOURCE_DIR}/src/common
PRIVATE ${PROJECT_BINARY_DIR}/include
PRIVATE ${PROJECT_SOURCE_DIR}/external/include
)
if(VulkanHeaders_FOUND)
target_include_directories(runtime_list
target_include_directories(openxr_runtime_list
PRIVATE ${VulkanHeaders_INCLUDE_DIRS}
)
endif()

target_link_libraries(runtime_list openxr_loader)
target_link_libraries(openxr_runtime_list openxr_loader)
if(MSVC)
target_compile_options(runtime_list PRIVATE /Zc:wchar_t /Zc:forScope /W4 /WX)
target_compile_options(openxr_runtime_list PRIVATE /Zc:wchar_t /Zc:forScope /W4 /WX)
endif()

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


install(TARGETS runtime_list
install(TARGETS openxr_runtime_list
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
if(NOT WIN32)
install(FILES openxr_runtime_list.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1/ COMPONENT ManPages)
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 73c4051

Please sign in to comment.