I have a really tough time trying to figure out how DirectX 11 (specifically I'm interested in Direct3D) can be integrated with CMake on Windows 10.
Inside C:\Windows\System32
one can find the runtime libraries (DLLs) since nowadays DirectX is integrated into the installation of Windows 10 (important for my case are d3d11.dll
and d3dx11.dll
). However the DLLs are not really enough to develop code that uses DirectX.
For developing software on Windows 10 for Windows 10 one generally needs the Windows SDK. I have both 10 and 8.1. DirectX 9, 10, 11 and 12 related files can be found inside C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\um\x86
or ...\x64
depending on whether you want 32 or 64bit. Inside C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um
one can find the header files.
People say that simply doing
target_link_libraries(my_project PRIVATE d3d11 d3dx11)
should do the trick. However I get an error (using CMake 3.12 with Visual Studio 2017 Pro with the former being shipped as part of the latter) that the .lib
cannot be found.
I tried adding the following
link_directories("C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.17763.0\\um\\x64")
include_directories("C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17763.0\\um")
but nothing changes.
Here is the full CMakeLists.txt
of my simple project:
cmake_minimum_required (VERSION 3.12)
link_directories("C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.17763.0\\um\\x64")
include_directories("C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17763.0\\um")
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
foreach(dir ${dirs})
message(STATUS "Include directory: \"${dir}\"")
endforeach()
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY LINK_DIRECTORIES)
foreach(dir ${dirs})
message(STATUS "Link directory: \"${dir}\"")
endforeach()
add_executable (DirectX11_CMake_Example "DirectX11_CMake_Example.cpp" "DirectX11_CMake_Example.h")
target_compile_definitions(DirectX11_CMake_Example PRIVATE "UNICODE" "_UNICODE")
target_link_libraries(DirectX11_CMake_Example PRIVATE d3d11 d3dx11)