修复WinDevice的cmake问题

This commit is contained in:
DevWiki 2023-12-19 19:00:44 +08:00
parent fb8463a51d
commit 5cce100311
3 changed files with 62 additions and 38 deletions

1
.gitignore vendored
View File

@ -80,3 +80,4 @@ CMakeLists.txt.user*
*/lib
*/cmake*
*/build
build*/

View File

@ -1 +1,2 @@
/cmake-*
/output

View File

@ -27,53 +27,75 @@ if (ENABLE_UTF8_SOURCE)
endif()
endif()
# 使
file(GLOB_RECURSE SOURCE_FILES "./src/*")
#
add_library(WinDevice SHARED
${SOURCE_FILES}
)
# DirectX
set(Windows_Kits_DIR "C:\\Program Files (x86)\\Windows Kits\\10")
set(Windows_Kits_Version "10.0.19041.0")
set(DirectX_SDK_INCLUDE_DIR "${Windows_Kits_DIR}\\Include\\${Windows_Kits_Version}\\um")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
# 64-bit
set(CMAKE_LIBRARY_ARCHITECTURE x64)
set(DirectX_SDK_LIB_DIR "${Windows_Kits_DIR}\\Lib\\${Windows_Kits_Version}\\um\\x64")
else()
# 32-bit
set(CMAKE_LIBRARY_ARCHITECTURE x86)
set(DirectX_SDK_LIB_DIR "${Windows_Kits_DIR}\\Lib\\${Windows_Kits_Version}\\um\\x86")
endif()
# WinDevice
target_include_directories(WinDevice
PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>
PRIVATE
${DirectX_SDK_INCLUDE_DIR}
include/third_lib
)
# d3d lib
target_link_libraries(WinDevice PRIVATE
"${DirectX_SDK_LIB_DIR}\\d3d9.lib"
"${DirectX_SDK_LIB_DIR}\\d3d10.lib"
"${DirectX_SDK_LIB_DIR}\\d3d11.lib"
"${DirectX_SDK_LIB_DIR}\\d3d12.lib"
"${DirectX_SDK_LIB_DIR}\\ddraw.lib"
"${DirectX_SDK_LIB_DIR}\\dxgi.lib")
# output
set(OUTPUT_DIR ${CMAKE_SOURCE_DIR}/output)
file(MAKE_DIRECTORY ${OUTPUT_DIR})
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
# Debug
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG")
set(LIBRARY_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/build/debug/lib")
set(LIBRARY_OUTPUT_PATH "${OUTPUT_DIR}/debug")
else()
# Release
set(LIBRARY_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/build/release/lib")
set(LIBRARY_OUTPUT_PATH "${OUTPUT_DIR}/release")
endif()
# 使
file(GLOB PROJECT_SOURCES
src/*.cpp
src/*.h
src/Audio/*.cpp
src/Audio/*.h
src/Video/*.cpp
src/Video/*.h
src/Utils/*.cpp
src/Utils/*.h
)
#
add_library(WinDevice ${PROJECT_SOURCES})
# include
file(GLOB_RECURSE EXPORTED_HEADERS ${CMAKE_SOURCE_DIR}/src/*.h)
foreach(HEADER ${EXPORTED_HEADERS})
get_filename_component(HEADER_DIR ${HEADER} DIRECTORY)
get_filename_component(HEADER_NAME ${HEADER} NAME)
string(REPLACE "${CMAKE_SOURCE_DIR}/src/" "" HEADER_RELATIVE_PATH ${HEADER_DIR})
file(COPY ${HEADER} DESTINATION ${OUTPUT_DIR}/include/${HEADER_RELATIVE_PATH})
endforeach()
# WinDevice
target_include_directories(WinDevice PUBLIC
"${CMAKE_SOURCE_DIR}/src"
)
# output/third_lib
set(OUTPUT_THIRD_LIB_DIR ${OUTPUT_DIR}/third_lib)
file(MAKE_DIRECTORY ${OUTPUT_THIRD_LIB_DIR})
# WinDevice
set(THIRD_LIB_DIR ${CMAKE_SOURCE_DIR}/include/third_lib)
target_include_directories(WinDevice PRIVATE
include/third_lib
src
)
# include/third_lib output/third_lib
file(COPY ${CMAKE_SOURCE_DIR}/include/third_lib/ DESTINATION ${OUTPUT_THIRD_LIB_DIR})
target_include_directories(WinDevice PUBLIC "${CMAKE_SOURCE_DIR}/src")
target_include_directories(WinDevice PRIVATE "${CMAKE_SOURCE_DIR}/include/third_lib")
# "install"
set(INSTALL_DIR "${CMAKE_SOURCE_DIR}/install")
#
install(TARGETS WinDevice
ARCHIVE DESTINATION "${INSTALL_DIR}/lib" #
LIBRARY DESTINATION "${INSTALL_DIR}/lib" #
)
target_link_libraries(WinDevice PRIVATE dxguid)
target_compile_definitions(WinDevice PRIVATE -DWINDEVICE_EXPORTS)