@@ -15,8 +15,14 @@ project (DirectXTK
1515 HOMEPAGE_URL "https://go.microsoft.com/fwlink/?LinkId=248929"
1616 LANGUAGES CXX)
1717
18+ if (DEFINED XBOX_CONSOLE_TARGET)
19+ set (CMAKE_CXX_STANDARD_LIBRARIES "" )
20+ endif ()
21+
1822option (BUILD_TOOLS "Build XWBTool" ON )
1923
24+ option (BUILD_SHARED_LIBS "Build DirectXTK as a shared library" OFF )
25+
2026option (BUILD_XAUDIO_WIN10 "Build for XAudio 2.9" OFF )
2127option (BUILD_XAUDIO_WIN8 "Build for XAudio 2.8" ON )
2228option (BUILD_XAUDIO_REDIST "Build for XAudio2Redist" OFF )
@@ -245,7 +251,28 @@ if(NOT USE_PREBUILT_SHADERS)
245251 USES_TERMINAL )
246252endif ()
247253
248- add_library (${PROJECT_NAME} STATIC ${LIBRARY_SOURCES} ${LIBRARY_HEADERS} )
254+ if (WIN32 AND BUILD_SHARED_LIBS )
255+ message (STATUS "Build library as a DLL" )
256+
257+ configure_file (
258+ "${CMAKE_CURRENT_SOURCE_DIR} /build/DirectXTK.rc.in"
259+ "${CMAKE_CURRENT_BINARY_DIR} /DirectXTK.rc" @ONLY)
260+
261+ add_library (${PROJECT_NAME} SHARED ${LIBRARY_SOURCES} ${LIBRARY_HEADERS} "${CMAKE_CURRENT_BINARY_DIR} /DirectXTK.rc" )
262+
263+ target_compile_definitions (${PROJECT_NAME} PRIVATE DIRECTX_TOOLKIT_EXPORT)
264+ target_compile_definitions (${PROJECT_NAME} INTERFACE DIRECTX_TOOLKIT_IMPORT)
265+
266+ if (XBOX_CONSOLE_TARGET MATCHES "durango" )
267+ target_link_libraries (${PROJECT_NAME} PRIVATE kernelx.lib combase.lib d3d12_x.lib xi.lib)
268+ endif ()
269+
270+ if (MINGW)
271+ target_link_libraries (${PROJECT_NAME} PRIVATE xinput1_4.lib)
272+ endif ()
273+ else ()
274+ add_library (${PROJECT_NAME} ${LIBRARY_SOURCES} ${LIBRARY_HEADERS} )
275+ endif ()
249276
250277target_include_directories (${PROJECT_NAME} PRIVATE ${COMPILED_SHADERS} Src)
251278
@@ -431,10 +458,18 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|IntelLLVM")
431458elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU" )
432459 foreach (t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME} )
433460 target_compile_options (${t} PRIVATE "-Wno-ignored-attributes" "-Walloc-size-larger-than=4GB" )
461+
462+ if (BUILD_SHARED_LIBS )
463+ target_compile_options (${t} PRIVATE "-Wno-attributes" )
464+ endif ()
434465 endforeach ()
435466elseif (CMAKE_CXX_COMPILER_ID MATCHES "Intel" )
436467 set_target_properties (${PROJECT_NAME} PROPERTIES CXX_STANDARD 14)
437468elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
469+ if (BUILD_SHARED_LIBS )
470+ target_compile_options (${PROJECT_NAME} PRIVATE "/wd4251" "/wd4275" )
471+ endif ()
472+
438473 if (ENABLE_CODE_ANALYSIS)
439474 message (STATUS "Building with Code Analysis (PREFIX)" )
440475 foreach (t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME} )
0 commit comments