diff --git a/src/loader/CMakeLists.txt b/src/loader/CMakeLists.txt index 794659c79..2e56c8276 100644 --- a/src/loader/CMakeLists.txt +++ b/src/loader/CMakeLists.txt @@ -15,22 +15,8 @@ # Author: # -#set (CMAKE_VERBOSE_MAKEFILE 1) - include(GNUInstallDirs) -# Use this feature for Windows to automatically generate an exports file for the DLL. -# See https://blog.kitware.com/create-dlls-on-windows-without-declspec-using-new-cmake-export-all-feature/ -include(GenerateExportHeader) -set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS false) - - -if(CMAKE_SYSTEM_NAME STREQUAL "Linux") - set(FALLBACK_CONFIG_DIRS "/etc/xdg" CACHE STRING - "Search path to use when XDG_CONFIG_DIRS is unset or empty or the current process is SUID/SGID. Default is freedesktop compliant.") - set(FALLBACK_DATA_DIRS "/usr/local/share:/usr/share" CACHE STRING - "Search path to use when XDG_DATA_DIRS is unset or empty or the current process is SUID/SGID. Default is freedesktop compliant.") -endif() if(WIN32) set(openxr_loader_RESOURCE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/loader.rc) endif() @@ -42,9 +28,7 @@ endif() # List of all files externally generated outside of the loader that the loader # needs to build with. -SET(LOADER_EXTERNAL_GEN_FILES - ${COMMON_GENERATED_OUTPUT} -) +set(LOADER_EXTERNAL_GEN_FILES ${COMMON_GENERATED_OUTPUT}) run_xr_xml_generate(loader_source_generator.py xr_generated_loader.hpp) run_xr_xml_generate(loader_source_generator.py xr_generated_loader.cpp) @@ -86,51 +70,45 @@ add_library(openxr_loader ${LIBRARY_TYPE} if(BUILD_WITH_SYSTEM_JSONCPP) target_link_libraries(openxr_loader PRIVATE JsonCpp::JsonCpp) else() - target_sources(openxr_loader PRIVATE + target_sources(openxr_loader + PRIVATE ${PROJECT_SOURCE_DIR}/src/external/jsoncpp/src/lib_json/json_reader.cpp ${PROJECT_SOURCE_DIR}/src/external/jsoncpp/src/lib_json/json_value.cpp - ${PROJECT_SOURCE_DIR}/src/external/jsoncpp/src/lib_json/json_writer.cpp) + ${PROJECT_SOURCE_DIR}/src/external/jsoncpp/src/lib_json/json_writer.cpp + ) target_include_directories(openxr_loader PRIVATE - # For jsoncpp - ${PROJECT_SOURCE_DIR}/src/external/jsoncpp/include) + ${PROJECT_SOURCE_DIR}/src/external/jsoncpp/include + ) endif() set_target_properties(openxr_loader PROPERTIES FOLDER ${LOADER_FOLDER}) -set_source_files_properties( - ${LOADER_EXTERNAL_GEN_FILES} - PROPERTIES GENERATED TRUE -) -add_dependencies(openxr_loader - generate_openxr_header - xr_global_generated_files -) -target_include_directories(openxr_loader - PRIVATE - ${PROJECT_SOURCE_DIR}/src/common +set_source_files_properties(${LOADER_EXTERNAL_GEN_FILES} PROPERTIES GENERATED TRUE) +add_dependencies(openxr_loader generate_openxr_header xr_global_generated_files) +target_include_directories( + openxr_loader + PRIVATE ${PROJECT_SOURCE_DIR}/src/common - # for OpenXR headers - ${PROJECT_SOURCE_DIR}/include - ${PROJECT_BINARY_DIR}/include + # for OpenXR headers + ${PROJECT_SOURCE_DIR}/include + ${PROJECT_BINARY_DIR}/include - # for generated dispatch table, common_config.h - ${CMAKE_CURRENT_SOURCE_DIR}/.. - ${CMAKE_CURRENT_BINARY_DIR}/.. + # for generated dispatch table, common_config.h + ${CMAKE_CURRENT_SOURCE_DIR}/.. + ${CMAKE_CURRENT_BINARY_DIR}/.. - # for target-specific generated files - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_BINARY_DIR} + # for target-specific generated files + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} ) + if(VulkanHeaders_FOUND) - target_include_directories(openxr_loader - PRIVATE ${Vulkan_INCLUDE_DIRS} - ) + target_include_directories(openxr_loader PRIVATE ${Vulkan_INCLUDE_DIRS}) endif() if(NOT BUILD_LOADER_WITH_EXCEPTION_HANDLING) - target_compile_definitions(openxr_loader - PRIVATE XRLOADER_DISABLE_EXCEPTION_HANDLING - ) + target_compile_definitions(openxr_loader PRIVATE XRLOADER_DISABLE_EXCEPTION_HANDLING) endif() + target_link_libraries( openxr_loader PRIVATE openxr-all-supported ${CMAKE_DL_LIBS} @@ -138,13 +116,28 @@ target_link_libraries( ) target_compile_definitions(openxr_loader PRIVATE API_NAME="OpenXR") + if(CMAKE_SYSTEM_NAME STREQUAL "Linux") - target_compile_definitions(openxr_loader - PRIVATE FALLBACK_CONFIG_DIRS="${FALLBACK_CONFIG_DIRS}" - PRIVATE FALLBACK_DATA_DIRS="${FALLBACK_DATA_DIRS}" - PRIVATE SYSCONFDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}" + set(FALLBACK_CONFIG_DIRS + "/etc/xdg" + CACHE + STRING + "Search path to use when XDG_CONFIG_DIRS is unset or empty or the current process is SUID/SGID. Default is freedesktop compliant." + ) + set(FALLBACK_DATA_DIRS + "/usr/local/share:/usr/share" + CACHE + STRING + "Search path to use when XDG_DATA_DIRS is unset or empty or the current process is SUID/SGID. Default is freedesktop compliant." + ) + target_compile_definitions( + openxr_loader + PRIVATE + FALLBACK_CONFIG_DIRS="${FALLBACK_CONFIG_DIRS}" + FALLBACK_DATA_DIRS="${FALLBACK_DATA_DIRS}" + SYSCONFDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}" ) - if(NOT(CMAKE_INSTALL_FULL_SYSCONFDIR STREQUAL "/etc")) + if(NOT (CMAKE_INSTALL_FULL_SYSCONFDIR STREQUAL "/etc")) target_compile_definitions(openxr_loader PRIVATE EXTRASYSCONFDIR="/etc") endif() @@ -155,16 +148,19 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux") PUBLIC m ) - add_custom_target(libopenxr_loader.so.${MAJOR}.${MINOR} ALL - COMMAND ${CMAKE_COMMAND} -E create_symlink libopenxr_loader.so.${MAJOR}.${MINOR}.${PATCH} libopenxr_loader.so.${MAJOR}.${MINOR}) + add_custom_target( + libopenxr_loader.so.${MAJOR}.${MINOR} ALL + COMMAND ${CMAKE_COMMAND} -E create_symlink libopenxr_loader.so.${MAJOR}.${MINOR}.${PATCH} + libopenxr_loader.so.${MAJOR}.${MINOR} + ) set(XR_API_VERSION "${MAJOR}.${MINOR}") set(EXTRA_LIBS ${CMAKE_THREAD_LIBS_INIT}) - configure_file("openxr.pc.in" "openxr.pc" @ONLY) + configure_file(openxr.pc.in openxr.pc @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/openxr.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") elseif(WIN32) # WindowsStore (UWP) apps must be compiled with dynamic CRT linkage (default) - if (NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore") + if(NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore") foreach(configuration in CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO @@ -173,11 +169,11 @@ elseif(WIN32) CMAKE_CXX_FLAGS_RELWITHDEBINFO) # If building DLLs, force static CRT linkage if(DYNAMIC_LOADER) - if (${configuration} MATCHES "/MD") + if(${configuration} MATCHES "/MD") string(REGEX REPLACE "/MD" "/MT" ${configuration} "${${configuration}}") endif() - else() # Otherwise for static libs, link the CRT dynamically - if (${configuration} MATCHES "/MT") + else() # Otherwise for static libs, link the CRT dynamically + if(${configuration} MATCHES "/MT") string(REGEX REPLACE "/MT" "/MD" ${configuration} "${${configuration}}") endif() endif() @@ -192,13 +188,20 @@ elseif(WIN32) # set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS false) # Need to copy DLL to client directories so clients can easily load it. - if( (DYNAMIC_LOADER) AND (CMAKE_GENERATOR MATCHES "^Visual Studio.*") ) - file( TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/$/openxr_loader.dll COPY_DLL_SRC_PATH ) - file( TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/$/openxr_loader.pdb COPY_PDB_SRC_PATH ) - file( TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/../tests/hello_xr/$/ COPY_DST_HELLO_XR_PATH ) - file( TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/../tests/loader_test/$/ COPY_DST_LOADER_TEST_PATH ) - file( TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/../conformance/conformance_test/$/ COPY_DST_CONFORMANCE_TEST_PATH ) - add_custom_command( TARGET openxr_loader POST_BUILD + if(DYNAMIC_LOADER AND (CMAKE_GENERATOR MATCHES "^Visual Studio.*")) + file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/$/openxr_loader.dll COPY_DLL_SRC_PATH) + file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/$/openxr_loader.pdb COPY_PDB_SRC_PATH) + file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/../tests/hello_xr/$/ + COPY_DST_HELLO_XR_PATH + ) + file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/../tests/loader_test/$/ + COPY_DST_LOADER_TEST_PATH + ) + file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/../conformance/conformance_test/$/ + COPY_DST_CONFORMANCE_TEST_PATH + ) + add_custom_command( + TARGET openxr_loader POST_BUILD COMMAND xcopy /Y /I ${COPY_DLL_SRC_PATH} ${COPY_DST_HELLO_XR_PATH} COMMAND xcopy /Y /I ${COPY_PDB_SRC_PATH} ${COPY_DST_HELLO_XR_PATH} COMMAND xcopy /Y /I ${COPY_DLL_SRC_PATH} ${COPY_DST_LOADER_TEST_PATH} @@ -210,19 +213,29 @@ elseif(WIN32) endif() if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") - target_compile_options(openxr_loader - PRIVATE -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wpointer-arith - PRIVATE -fno-strict-aliasing -fno-builtin-memcmp "$<$:-fno-rtti>" - -ffunction-sections -fdata-sections + target_compile_options( + openxr_loader + PRIVATE -Wall + -Wextra + -Wno-unused-parameter + -Wno-missing-field-initializers + -Wpointer-arith + -fno-strict-aliasing + -fno-builtin-memcmp + "$<$:-fno-rtti>" + -ffunction-sections + -fdata-sections ) # For GCC version 7.1 or greater, we need to disable the implicit fallthrough warning since # there's no consistent way to satisfy all compilers until they all accept the C++17 standard - if (CMAKE_COMPILER_IS_GNUCC AND NOT (CMAKE_CXX_COMPILER_VERSION LESS 7.1)) + if(CMAKE_COMPILER_IS_GNUCC AND NOT (CMAKE_CXX_COMPILER_VERSION LESS 7.1)) target_compile_options(openxr_loader PRIVATE -Wimplicit-fallthrough=0) endif() endif() -install(TARGETS openxr_loader +install( + TARGETS openxr_loader LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +)