Skip to content

Commit

Permalink
Merge pull request #17 from ntoskrnl7/env/arm_arm64
Browse files Browse the repository at this point in the history
Env/arm arm64
  • Loading branch information
ntoskrnl7 authored May 31, 2022
2 parents b3906d5 + 6af1f51 commit 7ade90f
Show file tree
Hide file tree
Showing 27 changed files with 356 additions and 105 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,13 @@ jobs:
shell: cmd
run: ..\build.bat . x64
working-directory: test

- name: build ARM
shell: cmd
run: ..\build.bat . ARM
working-directory: test

- name: build ARM64
shell: cmd
run: ..\build.bat . ARM64
working-directory: test
18 changes: 10 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cmake_policy(SET CMP0021 OLD)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
include(pkg-utils)

pkg_get_version(CRTSYS ${CMAKE_CURRENT_SOURCE_DIR}/include/_version VERSION)
pkg_get_version(CRTSYS ${CMAKE_CURRENT_SOURCE_DIR}/include/.internal/version VERSION)

project(
crtsys
Expand Down Expand Up @@ -39,7 +39,7 @@ else()
set(LDK_USE_RAISE_EXCEPTION OFF)
set(LDK_USE_RTL_RAISE_EXCEPTION OFF)
endif()
CPMAddPackage("gh:ntoskrnl7/Ldk@0.7.3")
CPMAddPackage("gh:ntoskrnl7/Ldk@0.7.4")

CPMAddPackage("gh:ntoskrnl7/FindWDK#master")
list(APPEND CMAKE_MODULE_PATH "${FindWDK_SOURCE_DIR}/cmake")
Expand Down Expand Up @@ -84,7 +84,6 @@ endif()

if (UCXXRT_ENABLED)
list(APPEND SOURCE_FILES src/custom/msvc/common/crt/src/stl/winapisupp.cpp)
list(REMOVE_ITEM SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/custom/crt/isa_available_init.c)
list(REMOVE_ITEM SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/custom/crt/math/ftol3.c)

CPMAddPackage("gh:ntoskrnl7/ucxxrt#master")
Expand All @@ -96,7 +95,11 @@ if (UCXXRT_ENABLED)
)
list(REMOVE_ITEM UCXXRT_SOURCE_FILES ${ucxxrt_SOURCE_DIR}/src/vcruntime/crt.cpp)
list(REMOVE_ITEM UCXXRT_SOURCE_FILES ${ucxxrt_SOURCE_DIR}/src/vcruntime/locales.cpp)
list(REMOVE_ITEM UCXXRT_SOURCE_FILES ${ucxxrt_SOURCE_DIR}/src/vcruntime/thread.cpp)
list(REMOVE_ITEM UCXXRT_SOURCE_FILES ${ucxxrt_SOURCE_DIR}/src/vcruntime/thread.cpp)
if(NOT "${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32" AND NOT "${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64" )
list(REMOVE_ITEM UCXXRT_SOURCE_FILES ${ucxxrt_SOURCE_DIR}/src/vcruntime/x86_exception_filter.cpp)
endif()
list(REMOVE_ITEM UCXXRT_SOURCE_FILES ${ucxxrt_SOURCE_DIR}/src/cpu_disp.cpp)
list(REMOVE_ITEM UCXXRT_SOURCE_FILES ${ucxxrt_SOURCE_DIR}/src/terminate.cpp)
list(REMOVE_ITEM UCXXRT_SOURCE_FILES ${ucxxrt_SOURCE_DIR}/src/misc/invalid_parameter.cpp)
list(REMOVE_ITEM UCXXRT_SOURCE_FILES ${ucxxrt_SOURCE_DIR}/src/sys_main.cpp)
Expand Down Expand Up @@ -151,7 +154,6 @@ endif()
#
# Add compile definitions
#
# target_compile_definitions(crtsys PUBLIC "_NO_CRT_STDIO_INLINE")
target_compile_definitions(crtsys PUBLIC "_KERNEL32_")
target_compile_definitions(crtsys PUBLIC "_ITERATOR_DEBUG_LEVEL=0")
if (CRTSYS_USE_LIBCNTPR)
Expand All @@ -176,8 +178,8 @@ endif()
#
# Forced Include File
#
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/include/winsdk/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/wdk/${WDK_VERSION}/forced.h")
target_compile_options(crtsys PRIVATE /FI"${CMAKE_CURRENT_SOURCE_DIR}/include/winsdk/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/wdk/${WDK_VERSION}/forced.h")
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/include/.internal/winsdk/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/wdk/${WDK_VERSION}/forced.h")
target_compile_options(crtsys PRIVATE /FI"${CMAKE_CURRENT_SOURCE_DIR}/include/.internal/winsdk/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/wdk/${WDK_VERSION}/forced.h")
endif()
target_compile_options(crtsys PRIVATE /FI"${CMAKE_CURRENT_SOURCE_DIR}/src/crtsys.h")
if (UCXXRT_ENABLED)
Expand Down Expand Up @@ -247,4 +249,4 @@ string(TOLOWER "${CMAKE_VS_PLATFORM_NAME}" PLATFROM_SHORT_NAME)
if(PLATFROM_SHORT_NAME STREQUAL "win32")
set(PLATFROM_SHORT_NAME "x86")
endif()
set_target_properties(crtsys PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/lib/${PLATFROM_SHORT_NAME})
set_target_properties(crtsys PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/lib/${PLATFROM_SHORT_NAME})
64 changes: 47 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
![Visual Studio 2017+](https://img.shields.io/badge/Visual%20Studio-2017+-682270?logo=visualstudio&logoColor=682270)
![CMake 3.14+](https://img.shields.io/badge/CMake-3.14+-yellow.svg?logo=cmake&logoColor=white)
![C++ 14+](https://img.shields.io/badge/C++-14+-white.svg?logo=cplusplus&logoColor=blue)
![Architecture](https://img.shields.io/badge/CPU-x86%20%2F%20x64%20%2F%20ARM%20%2F%20ARM64-blue.svg?logo=data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIj8+CjxzdmcgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgNTIgNTIiIGlkPSJMYXllcl8xIiB2ZXJzaW9uPSIxLjEiIHZpZXdCb3g9IjAgMCA1MiA1MiIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+CiAgICA8Zz4KICAgICAgICA8cGF0aCBmaWxsPSJ3aGl0ZSIgZD0iTTQ5LDE5LjV2LTJoLTYuOTk4NDEzMXYtNy40OTU3ODg2SDE0LjQwMTYxMTNsLTQuNDAwMDI0NCw0LjUzMDAyOTN2MjcuNDY5OTcwN0gxNy41VjQ5aDJ2LTYuOTk1Nzg4NmgzVjQ5aDJ2LTYuOTk1Nzg4NmgzICAgVjQ5aDJ2LTYuOTk1Nzg4NmgzVjQ5aDJ2LTYuOTk1Nzg4NmgyLjgxMTU4NDVsNC42OTAwMDI0LTUuNjQwMDE0NlYzNC41SDQ5di0yaC02Ljk5ODQxMzF2LTNINDl2LTJoLTYuOTk4NDEzMXYtM0g0OXYtMmgtNi45OTg0MTMxICAgdi0zSDQ5eiBNMzYuMDAxNTg2OSwzMy41MDQyMTE0YzAsMS42NTAwMjQ0LTEuMzQ5OTc1NiwzLTMsM2gtMTRjLTEuNjU5OTczMSwwLTMtMS4zNDk5NzU2LTMtM3YtMTRjMC0xLjY1OTk3MzEsMS4zNDAwMjY5LTMsMy0zaDE0ICAgYzEuNjUwMDI0NCwwLDMsMS4zNDAwMjY5LDMsM1YzMy41MDQyMTE0eiIgLz4KICAgICAgICA8cmVjdCBzdHlsZT0iZmlsbDp3aGl0ZSIgaGVpZ2h0PSIyIiB3aWR0aD0iNyIgeD0iMyIgeT0iMTcuNSIgLz4KICAgICAgICA8cmVjdCBzdHlsZT0iZmlsbDp3aGl0ZSIgaGVpZ2h0PSIyIiB3aWR0aD0iNyIgeD0iMyIgeT0iMjIuNSIgLz4KICAgICAgICA8cmVjdCBzdHlsZT0iZmlsbDp3aGl0ZSIgaGVpZ2h0PSIyIiB3aWR0aD0iNyIgeD0iMyIgeT0iMjcuNSIgLz4KICAgICAgICA8cmVjdCBzdHlsZT0iZmlsbDp3aGl0ZSIgaGVpZ2h0PSIyIiB3aWR0aD0iNyIgeD0iMyIgeT0iMzIuNSIgLz4KICAgICAgICA8cmVjdCBzdHlsZT0iZmlsbDp3aGl0ZSIgaGVpZ2h0PSI3IiB3aWR0aD0iMiIgeD0iMzIuNSIgeT0iMyIgLz4KICAgICAgICA8cmVjdCBzdHlsZT0iZmlsbDp3aGl0ZSIgaGVpZ2h0PSI3IiB3aWR0aD0iMiIgeD0iMjcuNSIgeT0iMyIgLz4KICAgICAgICA8cmVjdCBzdHlsZT0iZmlsbDp3aGl0ZSIgaGVpZ2h0PSI3IiB3aWR0aD0iMiIgeD0iMjIuNSIgeT0iMyIgLz4KICAgICAgICA8cmVjdCBzdHlsZT0iZmlsbDp3aGl0ZSIgaGVpZ2h0PSI3IiB3aWR0aD0iMiIgeD0iMTcuNSIgeT0iMyIgLz4KICAgIDwvZz4KPC9zdmc+)

커널 드라이버에서 C++ 및 STL 기능을 사용할 수 있도록 도와주는 CRT 라이브러리 입니다.

Expand Down Expand Up @@ -63,7 +64,7 @@

으로 인해서 새로운 라이브러리를 개발하게 되었습니다.

crtsys가 장점은 아래와 같습니다.
crtsys의 장점은 아래와 같습니다.

1. Micosoft CRT와 STL을 최대한 비슷하게 지원하기 위해서 Microsoft CRT 소스코드를 사용하긴 하지만 Microsoft Visual Studio가 설치되어있는 디렉토리 내의 소스를 직접 빌드하는 방법으로 처리하여, Visual Studio를 합법적으로 사용하는 사용자는 라이센스 문제 없이 사용 가능합니다.
2. Win32 API를 구현한 [Ldk](https://github.com/ntoskrnl7/Ldk)를 활용하여 많은 범위의 STL 기능을 지원합니다.
Expand All @@ -78,7 +79,8 @@ crtsys가 장점은 아래와 같습니다.

## Test Environments

- Windows 10
- Windows 10 x64
- **x86, x64, ARM, ARM64**로 빌드 가능하지만, 실제 테스트는 x86, x64 모듈에 대해서만 검증되었습니다.
- CMake 3.21.4
- Git 2.23.0
- Visual Studio 2017
Expand Down Expand Up @@ -207,10 +209,14 @@ lib 디렉토리와 include 디렉토리를 타 프로젝트에서 사용하시
```Batch
git clone https://github.com/ntoskrnl7/crtsys
cd crtsys/test
cmake -S . -B build
cmake --build build
cmake -S . -B build_x64
cmake --build build_x64
cmake -S . -B build_x86 -A Win32
cmake --build build_x86
cmake -S . -B build_ARM -A ARM
cmake --build build_ARM
cmake -S . -B build_ARM64 -A ARM64
cmake --build build_ARM64
```

혹은
Expand All @@ -220,18 +226,33 @@ lib 디렉토리와 include 디렉토리를 타 프로젝트에서 사용하시
cd crtsys/test
build.bat . x86
build.bat . x64
build.bat . ARM
build.bat . ARM64
```

혹은 아래 명령을 수행하시면 지원되는 모든 VS에 대해서 Debug, Release 구성을 모두 빌드합니다.
혹은 아래 명령을 수행하시면 지원되는 모든 아키텍쳐에 대해서 Debug, Release 구성을 모두 빌드합니다.

```Batch
git clone https://github.com/ntoskrnl7/crtsys
cd crtsys/test
build_all.bat test
```

2. build/Debug/crtsys_test.sys를 설치 및 로드하시기 바랍니다. (x86은 build_x86/Debug/crtsys_test.sys)
3. 정상적으로 로드 및 언로드가 되는지 확인하시기 바랍니다.
2. build/Debug/crtsys_test.sys를 설치 및 로드하시기 바랍니다.

x64 : build_x64/Debug/crtsys_test.sys
x86 : build_x86/Debug/crtsys_test.sys
ARM : build_ARM/Debug/crtsys_test.sys
ARM64 : build_ARM64/Debug/crtsys_test.sys

```batch
sc create CrtSysTest binpath= "빌드된 crtsys_test.sys의 전체 경로" displayname= "crtsys test" start= demand type= kernel
sc start CrtSysTest
sc stop CrtSysTest
sc delete CrtSysTest
```

3. 정상적으로 로드/언로드가 되었다면 테스트 성공한 것이며, 테스트 내용은 DebugView나 WinDbg를 통해서 확인 가능합니다.

## Usage

Expand All @@ -247,11 +268,19 @@ CMake를 사용하는것을 권장합니다.
2. CPM을 프로젝트 디렉토리에 다운로드 받으시기 바랍니다.

```batch
mkdir -p cmake
mkdir cmake
wget -O cmake/CPM.cmake https://github.com/cpm-cmake/CPM.cmake/releases/latest/download/get_cpm.cmake
```

혹은

```batch
mkdir cmake
curl -o cmake/CPM.cmake -LJO https://github.com/cpm-cmake/CPM.cmake/releases/latest/download/get_cpm.cmake
```

로 CPM.cmake를 다운로드 받으시기 바랍니다.

3. 프로젝트 디렉토리에 아래와 같은 파일을 작성해주시기 바랍니다.

- 디렉토리 구조
Expand All @@ -273,7 +302,7 @@ CMake를 사용하는것을 권장합니다.
include(cmake/CPM.cmake)
set(CRTSYS_NTL_MAIN ON) # use ntl::main
CPMAddPackage("gh:ntoskrnl7/crtsys@0.1.4")
CPMAddPackage("gh:ntoskrnl7/crtsys@0.1.5")
include(${crtsys_SOURCE_DIR}/cmake/CrtSys.cmake)
# add driver
Expand Down Expand Up @@ -302,26 +331,26 @@ CMake를 사용하는것을 권장합니다.

ntl::status ntl::main(ntl::driver &driver, const std::wstring &registry_path) {

std::wcout << "load (registry_path :" << registry_path << ")\n";
std::wcout << "load (registry_path :" << registry_path << ")\n";

// TODO
// TODO

driver.on_unload([registry_path]() {
std::wcout << "unload (registry_path :" << registry_path << ")\n";
});
driver.on_unload([registry_path]() {
std::wcout << "unload (registry_path :" << registry_path << ")\n";
});

return status::ok();
return status::ok();
}
```

1. 빌드를 수행합니다.
4. 빌드를 수행합니다.

```batch
cmake -S . -B build
cmake --build build
```

2. 드라이버가 정상적으로 시작되고 종료되는지 확인하시기 바랍니다.
5. 드라이버가 정상적으로 시작되고 종료되는지 확인하시기 바랍니다.

```batch
sc create CrtSysTest binpath= "빌드된 crtsys_test.sys의 전체 경로" displayname= "crtsys test" start= demand type= kernel
Expand All @@ -332,6 +361,7 @@ CMake를 사용하는것을 권장합니다.

## TODO

- CMake Install 구현
- 아직 구현되지 않은 C++ 및 STL 기능 구현
- Visual Studio 2017의 CRT 소스 코드 빌드
- 커널 드라이버와 사용자 프로세스 간 통신 기능
30 changes: 23 additions & 7 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
@REM build.bat "PATH" "x86 | x64" [Debug (default) | Release]
@REM build.bat "PATH" "2017 | 2019 | 2022" "x86 | x64"
@REM build.bat "PATH" "2017 | 2019 | 2022" "x86 | x64" [Debug (default) | Release]
@REM build.bat "PATH" "x86 | x64" | "ARM" | "ARM64" [Debug (default) | Release]
@REM build.bat "PATH" "2017 | 2019 | 2022" "x86 | x64" | "ARM" | "ARM64"
@REM build.bat "PATH" "2017 | 2019 | 2022" "x86 | x64" | "ARM" | "ARM64" [Debug (default) | Release]

@ECHO OFF

SETLOCAL ENABLEDELAYEDEXPANSION

IF EXIST "%1/CMakeLists.txt" (
SET WORK_PATH=%1
IF "%2" == "x86" (
IF /I "%2" == "x86" (
SET ARCH=Win32
SET ARCH_NAME=x86
)
IF "%2" == "x64" (
IF /I "%2" == "x64" (
SET ARCH=x64
SET ARCH_NAME=x64
)
IF "%2" == "Win32" (
IF /I "%2" == "Win32" (
SET ARCH=Win32
SET ARCH_NAME=x86
)
IF "%2" == "Win64" (
IF /I "%2" == "Win64" (
SET ARCH=x64
SET ARCH_NAME=x64
)
IF /I "%2" == "ARM" (
SET ARCH=ARM
SET ARCH_NAME=ARM
)
IF /I "%2" == "ARM64" (
SET ARCH=ARM64
SET ARCH_NAME=ARM64
)
IF /I "%3" == "Debug" (
SET CONFIG=Debug
)
Expand Down Expand Up @@ -61,6 +69,14 @@ IF EXIST "%1/CMakeLists.txt" (
SET ARCH=x64
SET ARCH_NAME=x64
)
IF /I "%3" == "ARM" (
SET ARCH=ARM
SET ARCH_NAME=ARM
)
IF /I "%3" == "ARM64" (
SET ARCH=ARM64
SET ARCH_NAME=ARM64
)
IF "!VS_VERSION!" == "" (
SET BUILD_PATH=!WORK_PATH!/build_!ARCH_NAME!
) ELSE (
Expand Down
15 changes: 15 additions & 0 deletions build_all.bat
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ IF EXIST "%1/CMakeLists.txt" (
START cmake -S %1 cmake -B %1/build_2019_x86 -A Win32 -G "Visual Studio 16 2019"
START cmake -S %1 cmake -B %1/build_2022_x64 -A x64 -G "Visual Studio 17 2022"
START cmake -S %1 cmake -B %1/build_2022_x86 -A Win32 -G "Visual Studio 17 2022"

START cmake -S %1 cmake -B %1/build_2017_ARM64 -A ARM64 -G "Visual Studio 15 2017"
START cmake -S %1 cmake -B %1/build_2017_ARM -A ARM -G "Visual Studio 15 2017"
START cmake -S %1 cmake -B %1/build_2019_ARM64 -A ARM64 -G "Visual Studio 16 2019"
START cmake -S %1 cmake -B %1/build_2019_ARM -A ARM -G "Visual Studio 16 2019"
START cmake -S %1 cmake -B %1/build_2022_ARM64 -A ARM64 -G "Visual Studio 17 2022"
START cmake -S %1 cmake -B %1/build_2022_ARM -A ARM -G "Visual Studio 17 2022"
) | PAUSE
START build_all.bat %1 Debug
START build_all.bat %1 Release
)
IF /I "%2" == "Release" (
START CMD /C "build.bat %1 2022 x64 Release && build.bat %1 2019 x64 Release && build.bat %1 2017 x64 Release"
START CMD /C "build.bat %1 2022 x86 Release && build.bat %1 2019 x86 Release && build.bat %1 2017 x86 Release"
START CMD /C "build.bat %1 2022 ARM64 Release && build.bat %1 2019 ARM64 Release && build.bat %1 2017 ARM64 Release"
START CMD /C "build.bat %1 2022 ARM Release && build.bat %1 2019 ARM Release && build.bat %1 2017 ARM Release"
)
IF /I "%2" == "Debug" (
START "2022 x64 Debug" build.bat %1 2022 x64 Debug
Expand All @@ -26,6 +35,12 @@ IF EXIST "%1/CMakeLists.txt" (
START "2019 x86 Debug" build.bat %1 2019 x86 Debug
START "2017 x64 Debug" build.bat %1 2017 x64 Debug
START "2017 x86 Debug" build.bat %1 2017 x86 Debug
START "2022 ARM64 Debug" build.bat %1 2022 ARM64 Debug
START "2022 ARM Debug" build.bat %1 2022 ARM Debug
START "2019 ARM64 Debug" build.bat %1 2019 ARM64 Debug
START "2019 ARM Debug" build.bat %1 2019 ARM Debug
START "2017 ARM64 Debug" build.bat %1 2017 ARM64 Debug
START "2017 ARM Debug" build.bat %1 2017 ARM Debug
)
) ELSE (
ECHO "%1/CMakeLists.txt not exist"
Expand Down
45 changes: 12 additions & 33 deletions cmake/CrtSys.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,42 +44,21 @@ list(APPEND CMAKE_MODULE_PATH "${FindWDK_SOURCE_DIR}/cmake")
find_package(WDK REQUIRED)

function(crtsys_add_driver _target)
cmake_parse_arguments(CRTSYS "" "WINVER" "" ${ARGN})

EXTENDED_CPP_FEATURES_ON(${_target})
add_executable(${_target} ${CRTSYS_UNPARSED_ARGUMENTS})

set_target_properties(${_target} PROPERTIES SUFFIX ".sys")
set_target_properties(${_target} PROPERTIES COMPILE_OPTIONS "${WDK_COMPILE_FLAGS}")
set_target_properties(${_target} PROPERTIES COMPILE_DEFINITIONS
"${WDK_COMPILE_DEFINITIONS};$<$<CONFIG:Debug>:${WDK_COMPILE_DEFINITIONS_DEBUG}>;_WIN32_WINNT=${WDK_WINVER}"
)
set_target_properties(${_target} PROPERTIES LINK_FLAGS "${WDK_LINK_FLAGS}")

set_property(TARGET crtsys_test PROPERTY INCLUDE_DIRECTORIES "${crtsys_SOURCE_DIR}/include;${crtsys_SOURCE_DIR}/include/$(VCToolsVersion);${crtsys_SOURCE_DIR}/include/${MSVC_TOOLSET_VERSION};${crtsys_SOURCE_DIR}/include/$(VCToolsVersion)/stl;${crtsys_SOURCE_DIR}/include/${MSVC_TOOLSET_VERSION}/stl;$(VC_IncludePath);$(WindowsSDK_IncludePath)")
target_include_directories(${_target} SYSTEM PRIVATE
"${WDK_ROOT}/Include/${WDK_VERSION}/shared"
"${WDK_ROOT}/Include/${WDK_VERSION}/km"
"${WDK_ROOT}/Include/${WDK_VERSION}/km/crt"
)

# Forced Include File
if(EXISTS "${crtsys_SOURCE_DIR}/include/winsdk/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/wdk/${WDK_VERSION}/forced.h")
target_compile_options(${_target} PRIVATE /FI"${crtsys_SOURCE_DIR}/include/winsdk/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/wdk/${WDK_VERSION}/forced.h")
endif()
cmake_parse_arguments(WDK "" "WINVER" "" ${ARGN})
wdk_add_driver(${_target} ${WDK_UNPARSED_ARGUMENTS} CUSTOM_ENTRY_POINT CrtSysDriverEntry EXTENDED_CPP_FEATURES)

if(CRTSYS_NTL_MAIN)
target_compile_definitions(crtsys PUBLIC CRTSYS_USE_NTL_MAIN)
endif()
target_link_libraries(${_target} crtsys WDK::NTOSKRNL WDK::HAL WDK::WMILIB WDK::BUFFEROVERFLOWK)
target_link_libraries(${_target} crtsys)

if(CMAKE_SIZEOF_VOID_P EQUAL 4)
target_link_libraries(${_target} WDK::MEMCMP)
get_target_property(INC_DIR_TMP ${_target} INCLUDE_DIRECTORIES)
set_property(TARGET ${_target} PROPERTY INCLUDE_DIRECTORIES "${crtsys_SOURCE_DIR}/include;${crtsys_SOURCE_DIR}/include/.internal/msvc/$(VCToolsVersion);${crtsys_SOURCE_DIR}/include/.internal/msvc/${MSVC_TOOLSET_VERSION};${crtsys_SOURCE_DIR}/include/.internal/msvc/$(VCToolsVersion)/stl;${crtsys_SOURCE_DIR}/include/.internal/msvc/${MSVC_TOOLSET_VERSION}/stl;$(VC_IncludePath);$(WindowsSDK_IncludePath);${INC_DIR_TMP}")

if(EXISTS "${crtsys_SOURCE_DIR}/include/.internal/winsdk/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/wdk/${WDK_VERSION}/forced.h")
target_compile_options(${_target} PRIVATE /FI"${crtsys_SOURCE_DIR}/include/.internal/winsdk/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/wdk/${WDK_VERSION}/forced.h")
endif()

if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set_property(TARGET ${_target} APPEND_STRING PROPERTY LINK_FLAGS "/ENTRY:CrtSysDriverEntry@8")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set_property(TARGET ${_target} APPEND_STRING PROPERTY LINK_FLAGS "/ENTRY:CrtSysDriverEntry")
target_compile_options(${_target} PRIVATE /FI"${crtsys_SOURCE_DIR}/include/.internal/adjust_link_order")

if(CRTSYS_NTL_MAIN)
target_compile_definitions(${_target} PUBLIC CRTSYS_USE_NTL_MAIN)
endif()
endfunction()
Loading

0 comments on commit 7ade90f

Please sign in to comment.