diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..ed60c502b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,45 @@ +cmake_minimum_required(VERSION 3.20) +project(MoltenVK) + +set(MVK_GIT_REV "unknown") + +function(check_lists_equal list1 list2) + set(DIFF_ITEMS ) + # Check if each element in the first list is in the second list + foreach(element IN LISTS ${list1}) + if(NOT ${element} IN LISTS ${list2}) + LIST(APPEND DIFF_ITEMS ${element}) + endif() + endforeach() + + if(DIFF_ITEMS) + message(STATUS "glob found the following files ${DIFF_ITEMS} which aren't part of the SRC_LIST in ${CMAKE_CURRENT_LIST_FILE}") + endif () +endfunction() + +find_package(Git) +if(GIT_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD + OUTPUT_VARIABLE MVK_GIT_REV + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + message( STATUS "GIT hash: ${MVK_GIT_REV}") +else() + message(STATUS "GIT not found") +endif() + +configure_file(${CMAKE_CURRENT_LIST_DIR}/mvkGitRevDerived.h.in + ${CMAKE_CURRENT_BINARY_DIR}/mvkGitRevDerived.h) + +add_subdirectory(External) +add_subdirectory(MoltenVKShaderConverter) +add_subdirectory(MoltenVK) + +target_include_directories(MoltenVK PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) + +install ( TARGETS MoltenVK moltenvk_shader_converter EXPORT MotlenVK ) +export ( TARGETS MoltenVK moltenvk_shader_converter cereal glslang SPIRV OGLCompiler OSDependent MachineIndependent + GenericCodeGen + FILE ${CMAKE_BINARY_DIR}/MoltenVKConfig.cmake ) \ No newline at end of file diff --git a/External/CMakeLists.txt b/External/CMakeLists.txt new file mode 100644 index 000000000..e71cf5299 --- /dev/null +++ b/External/CMakeLists.txt @@ -0,0 +1,8 @@ +set(SKIP_PORTABILITY_TEST ON) +set(JUST_INSTALL_CEREAL ON) + +add_subdirectory(cereal) +add_subdirectory(glslang) +set(SPIRV_TOOLS_BUILD_STATIC ON) +add_subdirectory(SPIRV-Cross) +add_subdirectory(Vulkan-Headers) diff --git a/MoltenVK/CMakeLists.txt b/MoltenVK/CMakeLists.txt new file mode 100644 index 000000000..4bd61cc86 --- /dev/null +++ b/MoltenVK/CMakeLists.txt @@ -0,0 +1,28 @@ +## +## MoltenVK-iOS Files +## + +file(GLOB_RECURSE MOLTEN_VK_SOURCES CONFIGURE_DEPENDS ${CMAKE_CURRENT_LIST_DIR}/MoltenVK *.mm *.m *.cpp) +list(PREPEND MOLTEN_VK_SOURCES ../Common/MVKOSExtensions.mm) + +## +## MoltenVK-iOS +## + +add_library(MoltenVK STATIC ${MOLTEN_VK_SOURCES}) + +target_include_directories(MoltenVK + PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/../Common + ${CMAKE_CURRENT_LIST_DIR}/MoltenVK/API + ${CMAKE_CURRENT_LIST_DIR}/MoltenVK/Commands + ${CMAKE_CURRENT_LIST_DIR}/MoltenVK/GPUObjects + ${CMAKE_CURRENT_LIST_DIR}/MoltenVK/Layers + ${CMAKE_CURRENT_LIST_DIR}/MoltenVK/OS + ${CMAKE_CURRENT_LIST_DIR}/MoltenVK/Utility + ${CMAKE_CURRENT_LIST_DIR}/MoltenVK/Vulkan + ${CMAKE_CURRENT_LIST_DIR}/include +) + +target_compile_features(MoltenVK PRIVATE cxx_std_17) +target_link_libraries(MoltenVK PUBLIC moltenvk_shader_converter) diff --git a/MoltenVKShaderConverter/CMakeLists.txt b/MoltenVKShaderConverter/CMakeLists.txt new file mode 100644 index 000000000..554e0140c --- /dev/null +++ b/MoltenVKShaderConverter/CMakeLists.txt @@ -0,0 +1,40 @@ +## +## MoltenVKShaderConverter Files +## +set(SRC_LIST + ../Common/MVKOSExtensions.mm + MoltenVKShaderConverter/SPIRVSupport.cpp + MoltenVKShaderConverterTool/MoltenVKShaderConverterTool.cpp + MoltenVKShaderConverterTool/OSSupport.mm + MoltenVKShaderConverterTool/main.cpp + MoltenVKShaderConverter/FileSupport.mm + MoltenVKShaderConverter/GLSLConversion.mm + MoltenVKShaderConverter/GLSLToSPIRVConverter.cpp + MoltenVKShaderConverter/SPIRVConversion.mm + MoltenVKShaderConverter/SPIRVToMSLConverter.cpp +) + +file(GLOB SRCS RELATIVE CONFIGURE_DEPENDS ${CMAKE_CURRENT_LIST_DIR}/MoltenVKShaderConverter *.mm *.cpp *.m) +list(PREPEND SRCS ../Common/MVKOSExtensions.mm) + +check_lists_equal(${SRCS}, ${SRC_LIST}) + +add_library(moltenvk_shader_converter STATIC ${SRC_LIST}) + +find_library(FOUNDATION_LIBRARY Foundation REQUIRED) +find_library(METAL_LIBRARY Metal REQUIRED) +find_library(APPKIT_LIBRARY AppKit REQUIRED) +find_library(IOKIT_LIBRARY IOKit REQUIRED) +find_library(IOSURFACE_LIBRARY IOSurface REQUIRED) +find_library(QUARTZCORE_LIBRARY QuartzCore REQUIRED) + + +target_link_libraries(moltenvk_shader_converter PUBLIC ${FOUNDATION_LIBRARY} ${METAL_LIBRARY} ${APPKIT_LIBRARY} + ${IOKIT_LIBRARY} ${IOSURFACE_LIBRARY} ${QUARTZCORE_LIBRARY} + cereal spirv-cross-msl glslang SPIRV-Tools-opt spirv-cross-reflect SPIRV) + +target_include_directories(moltenvk_shader_converter PUBLIC MoltenVKShaderConverter include + ${CMAKE_CURRENT_LIST_DIR}/../Common + ${CMAKE_CURRENT_LIST_DIR}/../External + ${CMAKE_CURRENT_LIST_DIR}) +target_compile_features(moltenvk_shader_converter PUBLIC cxx_std_17) diff --git a/mvkGitRevDerived.h.in b/mvkGitRevDerived.h.in new file mode 100644 index 000000000..efb8b8672 --- /dev/null +++ b/mvkGitRevDerived.h.in @@ -0,0 +1,2 @@ +// Auto-generated by MoltenVK +static const char* mvkRevString = "@MVK_GIT_REV@"; \ No newline at end of file