Skip to content

Commit bb09721

Browse files
committed
macOS: Add macOS support
1 parent e533144 commit bb09721

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2882
-113
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ build-android/external
3434
*.files
3535
*.includes
3636
.vscode/
37+
.DS_Store

Diff for: BUILD.md

+151-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Build Instructions
22

3-
Instructions for building this repository on Linux, Windows, and Android.
3+
Instructions for building this repository on Linux, Windows, Android, and MacOS.
44

55
## Index
66

@@ -9,6 +9,7 @@ Instructions for building this repository on Linux, Windows, and Android.
99
3. [Windows Build](#windows-build)
1010
4. [Linux Build](#linux-build)
1111
5. [Android Build](#android-build)
12+
6. [MacOS build](#macos-build)
1213

1314
[](#contributing)
1415

@@ -177,14 +178,11 @@ See **Loader and Validation Layer Dependencies** for more information and other
177178
2. Execute `./update_external_sources.sh` -- this will download and build external components
178179
3. Create a `build` directory, change into that directory, and run cmake:
179180

180-
```script
181181
mkdir build
182182
cd build
183183
cmake -DCMAKE_BUILD_TYPE=Debug ..
184-
```
185184

186-
4. Change into the newly-created build directory
187-
5. Run `make -j8` to begin the build
185+
4. Run `make -j8` to begin the build
188186

189187
If your build system supports ccache, you can enable that via CMake option `-DUSE_CCACHE=On`
190188

@@ -502,12 +500,155 @@ To build, install, and run the Smoke demo for Android, run the following, and an
502500
./build-and-install
503501
adb shell am start -a android.intent.action.MAIN -c android-intent.category.LAUNCH -n com.example.Smoke/android.app.NativeActivity --es args "--validate"
504502

503+
[](#macos-build)
504+
505+
## Building on MacOS
506+
507+
### MacOS Build Requirements
508+
509+
Tested on OSX version 10.12.6
510+
511+
Setup Homebrew and components
512+
513+
- Follow instructions on [brew.sh](http://brew.sh) to get Homebrew installed.
514+
515+
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
516+
517+
- Ensure Homebrew is at the beginning of your PATH:
518+
519+
export PATH=/usr/local/bin:$PATH
520+
521+
- Add packages with the following (may need refinement)
522+
523+
brew install cmake python python3 git
524+
525+
### Clone the Repository
526+
527+
Clone the Vulkan-LoaderAndValidationLayers repository:
528+
529+
git clone https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers.git
530+
531+
### Get the External Libraries
532+
533+
Change to the cloned directory (`cd Vulkan-LoaderAndValidationLayers`) and run the script:
534+
535+
./update_external_sources.sh
536+
537+
This script downloads and builds the `glslang` and `MoltenVK` repositories.
538+
539+
### MacOS build
540+
541+
#### CMake Generators
542+
543+
This repository uses CMake to generate build or project files that are
544+
then used to build the repository.
545+
The CMake generators explicitly supported in this repository are:
546+
547+
- Unix Makefiles
548+
- Xcode
549+
550+
#### Building with the Unix Makefiles Generator
551+
552+
This generator is the default generator, so all that is needed for a debug
553+
build is:
554+
555+
mkdir build
556+
cd build
557+
cmake -DCMAKE_BUILD_TYPE=Debug ..
558+
make
559+
560+
To speed up the build on a multi-core machine, use the `-j` option for `make`
561+
to specify the number of cores to use for the build.
562+
For example:
563+
564+
make -j4
565+
566+
You can now run the demo applications from the command line:
567+
568+
open demos/cube.app
569+
open demos/cubepp.app
570+
open demos/smoketest.app
571+
open demos/vulkaninfo.app
572+
573+
Or you can locate them from `Finder` and launch them from there.
574+
575+
##### The Install Target and RPATH
576+
577+
The applications you just built are "bundled applications", but the executables
578+
are using the `RPATH` mechanism to locate runtime dependencies that are still
579+
in your build tree.
580+
581+
To see this, run this command from your `build` directory:
582+
583+
otool -l demos/cube.app/Contents/MacOS/cube
584+
585+
and note that the `cube` executable contains loader commands:
586+
587+
- `LC_LOAD_DYLIB` to load `libvulkan.1.dylib` via an `@rpath`
588+
- `LC_RPATH` that contains an absolute path to the build location of the Vulkan loader
589+
590+
This makes the bundled application "non-transportable", meaning that it won't run
591+
unless the Vulkan loader is on that specific absolute path.
592+
This is useful for debugging the loader or other components built in this repository,
593+
but not if you want to move the application to another machine or remove your build tree.
594+
595+
To address this problem, run:
596+
597+
make install
598+
599+
This step "cleans up" the `RPATH` to remove any external references
600+
and performs other bundle fix-ups.
601+
After running `make install`, re-run the `otool` command again and note:
602+
603+
- `LC_LOAD_DYLIB` is now `@executable_path/../MacOS/libvulkan.1.dylib`
604+
- `LC_RPATH` is no longer present
605+
606+
The "bundle fix-up" operation also puts a copy of the Vulkan loader into the bundle,
607+
making the bundle completely self-contained and self-referencing.
608+
609+
Note that the "install" target has a very different meaning compared to the Linux
610+
"make install" target.
611+
The Linux "install" copies the targets to system directories.
612+
In MacOS, "install" means fixing up application bundles.
613+
In both cases, the "install" target operations clean up the `RPATH`.
614+
615+
##### The Non-bundled vulkaninfo Application
616+
617+
There is also a non-bundled version of the `vulkaninfo` application that you can
618+
run from the command line:
619+
620+
demos/vulkaninfo
621+
622+
If you run this before you run "make install", vulkaninfo's RPATH is already set
623+
to point to the Vulkan loader in the build tree, so it has no trouble finding it.
624+
But the loader will not find the MoltenVK driver and you'll see a message about an
625+
incompatible driver. To remedy this:
626+
627+
VK_ICD_FILENAMES=../external/MoltenVK/Package/Latest/MoltenVK/macOS/MoltenVK_icd.json demos/vulkaninfo
628+
629+
If you run `vulkaninfo` after doing a "make install", the `RPATH` in the `vulkaninfo` application
630+
got removed and the OS needs extra help to locate the Vulkan loader:
631+
632+
DYLD_LIBRARY_PATH=loader VK_ICD_FILENAMES=../external/MoltenVK/Package/Latest/MoltenVK/macOS/MoltenVK_icd.json demos/vulkaninfo
633+
634+
#### Building with the Xcode Generator
635+
636+
To create and open an Xcode project:
637+
638+
mkdir build-xcode
639+
cd build-xcode
640+
cmake -GXcode ..
641+
open VULKAN.xcodeproj
642+
643+
Within Xcode, you can select Debug or Release builds in the project's Build Settings.
644+
You can also select individual schemes for working with specific applications like `cube`.
645+
505646
## Ninja Builds - All Platforms
506647

507648
The [Qt Creator IDE](https://qt.io/download-open-source/#section-2) can open a root CMakeList.txt
508649
as a project directly, and it provides tools within Creator to configure and generate Vulkan SDK
509650
build files for one to many targets concurrently.
510-
Alternatively, when invoking CMake, use the `-G Codeblocks` Ninja option to generate Ninja build
651+
Alternatively, when invoking CMake, use the `-G "Codeblocks - Ninja"` option to generate Ninja build
511652
files to be used as project files for QtCreator
512653

513654
- Follow the steps defined elsewhere for the OS using the update\_external\_sources script or as
@@ -518,7 +659,8 @@ files to be used as project files for QtCreator
518659
- In order to debug with QtCreator, a
519660
[Microsoft WDK: eg WDK 10](http://go.microsoft.com/fwlink/p/?LinkId=526733) is required.
520661

521-
Note that installing the WDK breaks the MSVC vcvarsall.bat build scripts provided by MSVC, requiring that the LIB, INCLUDE, and PATHenv variables be set to the WDK paths by some other means
662+
Note that installing the WDK breaks the MSVC vcvarsall.bat build scripts provided by MSVC,
663+
requiring that the LIB, INCLUDE, and PATHenv variables be set to the WDK paths by some other means
522664

523665
[](#update-external-sources)
524666

@@ -577,7 +719,8 @@ glslang\_revision file at the root of the Vulkan-LoaderAndValidationLayers tree
577719

578720
3) Configure the glslang source tree with CMake and build it with your IDE of choice
579721

580-
4) Enable the `CUSTOM_GLSLANG_BIN_PATH` and `CUSTOM_SPIRV_TOOLS_BIN_PATH` options in the Vulkan-LoaderAndValidationLayers CMake configuration and point the `GLSLANG_BINARY_PATH` and `SPIRV_TOOLS_BINARY_PATH` variables to the correct location
722+
4) Enable the `CUSTOM_GLSLANG_BIN_PATH` and `CUSTOM_SPIRV_TOOLS_BIN_PATH` options in the Vulkan-LoaderAndValidationLayers
723+
CMake configuration and point the `GLSLANG_BINARY_PATH` and `SPIRV_TOOLS_BINARY_PATH` variables to the correct location
581724

582725
5) If building on Windows with MSVC, set `DISABLE_BUILDTGT_DIR_DECORATION` to _On_.
583726
If building on Windows, but without MSVC set `DISABLE_BUILD_PATH_DECORATION` to _On_

Diff for: CMakeLists.txt

+21-3
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,26 @@ if (USE_CCACHE)
2424
endif(CCACHE_FOUND)
2525
endif()
2626

27+
if(APPLE)
28+
# CMake versions 3 or later need CMAKE_MACOSX_RPATH defined.
29+
# This avoids the CMP0042 policy message.
30+
set(CMAKE_MACOSX_RPATH 1)
31+
# The "install" target for MacOS fixes up bundles in place.
32+
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR})
33+
endif()
34+
2735
# Enable cmake folders
2836
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
2937
set(LVL_TARGET_FOLDER lvl_cmake_targets)
3038

31-
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
39+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
3240
set(FALLBACK_CONFIG_DIRS "/etc/xdg" CACHE STRING
3341
"Search path to use when XDG_CONFIG_DIRS is unset or empty or the current process is SUID/SGID. Default is freedesktop compliant.")
3442
set(FALLBACK_DATA_DIRS "/usr/local/share:/usr/share" CACHE STRING
3543
"Search path to use when XDG_DATA_DIRS is unset or empty or the current process is SUID/SGID. Default is freedesktop compliant.")
44+
endif()
3645

46+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
3747
include(FindPkgConfig)
3848
option(BUILD_WSI_XCB_SUPPORT "Build XCB WSI support" ON)
3949
option(BUILD_WSI_XLIB_SUPPORT "Build Xlib WSI support" ON)
@@ -80,7 +90,11 @@ if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
8090
set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -Wimplicit-fallthrough=0")
8191
endif()
8292

83-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 ${COMMON_COMPILE_FLAGS}")
93+
if (APPLE)
94+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_COMPILE_FLAGS}")
95+
else()
96+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 ${COMMON_COMPILE_FLAGS}")
97+
endif()
8498
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_COMPILE_FLAGS} -std=c++11 -fno-rtti")
8599
if (UNIX)
86100
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
@@ -136,7 +150,11 @@ option(BUILD_LOADER "Build loader" ON)
136150
option(BUILD_TESTS "Build tests" ON)
137151
option(BUILD_LAYERS "Build layers" ON)
138152
option(BUILD_DEMOS "Build demos" ON)
139-
option(BUILD_VKJSON "Build vkjson" ON)
153+
if (APPLE)
154+
option(BUILD_VKJSON "Build vkjson" OFF)
155+
else()
156+
option(BUILD_VKJSON "Build vkjson" ON)
157+
endif()
140158
option(BUILD_ICD "Build icd" ON)
141159
option(CUSTOM_GLSLANG_BIN_ROOT "Use the user defined GLSLANG_BINARY_ROOT" OFF)
142160
option(CUSTOM_SPIRV_TOOLS_BIN_ROOT "Use the user defined SPIRV_TOOLS*BINARY_ROOT paths" OFF)

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Vulkan Ecosystem Components
22

3-
This project provides the Khronos official Vulkan ICD desktop loader and the Vulkan validation layers for Windows, Linux, and Android.
3+
This project provides the Khronos official Vulkan ICD desktop loader and the Vulkan validation layers for Windows, Linux, Android, and MacOS.
44

55
## CI Build Status
66
| Platform | Build Status |

Diff for: demos/CMakeLists.txt

+44-8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
5151

5252
include_directories ("${PROJECT_SOURCE_DIR}/icd/common")
5353
link_libraries(${API_LOWERCASE} m)
54+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
55+
add_definitions(-DVK_USE_PLATFORM_MACOS_MVK)
5456
else()
5557
message(FATAL_ERROR "Unsupported Platform!")
5658
endif()
@@ -119,10 +121,40 @@ if(WIN32)
119121
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS -D_USE_MATH_DEFINES")
120122
endif()
121123

124+
# MacOS setup common to all demos
125+
if(APPLE)
126+
include(macOS/common.cmake)
127+
endif()
128+
129+
######################################################################################
130+
# vulkaninfo
131+
122132
add_executable(${API_LOWERCASE}info vulkaninfo.c)
123133
target_link_libraries(${API_LOWERCASE}info ${LIBRARIES})
134+
if(APPLE)
135+
set_target_properties(${API_LOWERCASE}info PROPERTIES
136+
INSTALL_RPATH "@loader_path/../lib"
137+
)
138+
install(TARGETS ${API_LOWERCASE}info DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
139+
endif()
140+
141+
# Create vulkaninfo application bundle for MacOS
142+
if(APPLE)
143+
include(macOS/vulkaninfo/vulkaninfo.cmake)
144+
endif()
145+
146+
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
147+
if(INSTALL_LVL_FILES)
148+
install(TARGETS ${API_LOWERCASE}info DESTINATION ${CMAKE_INSTALL_BINDIR})
149+
endif()
150+
endif()
151+
152+
######################################################################################
153+
# cube
124154

125-
if(NOT WIN32)
155+
if(APPLE)
156+
include(macOS/cube/cube.cmake)
157+
elseif(NOT WIN32)
126158
if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR})
127159
add_executable(cube cube.c ${PROJECT_SOURCE_DIR}/demos/cube.vert ${PROJECT_SOURCE_DIR}/demos/cube.frag cube.vert.inc cube.frag.inc)
128160
target_link_libraries(cube ${LIBRARIES})
@@ -138,7 +170,12 @@ else()
138170
target_link_libraries(cube ${LIBRARIES})
139171
endif()
140172

141-
if(NOT WIN32)
173+
######################################################################################
174+
# cubepp
175+
176+
if(APPLE)
177+
include(macOS/cubepp/cubepp.cmake)
178+
elseif(NOT WIN32)
142179
if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR})
143180
add_executable(cubepp cube.cpp ${PROJECT_SOURCE_DIR}/demos/cube.vert ${PROJECT_SOURCE_DIR}/demos/cube.frag cube.vert.inc cube.frag.inc)
144181
target_link_libraries(cubepp ${LIBRARIES})
@@ -154,14 +191,13 @@ else()
154191
target_link_libraries(cubepp ${LIBRARIES})
155192
endif()
156193

194+
######################################################################################
195+
# smoke
196+
157197
if ((${CMAKE_SYSTEM_PROCESSOR} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR}))
158-
if ((DEMOS_WSI_SELECTION STREQUAL "XCB") OR (DEMOS_WSI_SELECTION STREQUAL "WAYLAND") OR WIN32 OR (CMAKE_SYSTEM_NAME STREQUAL "Android"))
198+
if ((DEMOS_WSI_SELECTION STREQUAL "XCB") OR (DEMOS_WSI_SELECTION STREQUAL "WAYLAND") OR WIN32 OR
199+
(CMAKE_SYSTEM_NAME STREQUAL "Android") OR (CMAKE_SYSTEM_NAME STREQUAL "Darwin"))
159200
add_subdirectory(smoke)
160201
endif()
161202
endif()
162203

163-
if(UNIX)
164-
if(INSTALL_LVL_FILES)
165-
install(TARGETS ${API_LOWERCASE}info DESTINATION ${CMAKE_INSTALL_BINDIR})
166-
endif()
167-
endif()

0 commit comments

Comments
 (0)