Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
cmake_minimum_required(VERSION 3.16)

project(kf LANGUAGES CXX)

# Check if building as a stand-alone project
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(IS_TOPLEVEL_PROJECT TRUE)
else()
set(IS_TOPLEVEL_PROJECT FALSE)
endif()

add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

target_include_directories(${PROJECT_NAME}
INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

if(${IS_TOPLEVEL_PROJECT})
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# Add a pseudo-project to make kf headers visible in IDE
file(GLOB_RECURSE ${PROJECT_NAME}_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/kf/*")

# Organize files into filters matching their relative paths
foreach(header ${${PROJECT_NAME}_HEADERS})
file(RELATIVE_PATH rel_path "${CMAKE_CURRENT_SOURCE_DIR}" "${header}")

get_filename_component(rel_dir "${rel_path}" DIRECTORY)
if(rel_dir)
string(REPLACE "/" "\\" filter "${rel_dir}")
source_group("${filter}" FILES "${header}")
endif()
endforeach()

add_custom_target(${PROJECT_NAME}-headers SOURCES ${${PROJECT_NAME}_HEADERS})
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX)

# Add all .md files from the root directory to the solution
file(GLOB ROOT_MD_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.md")
add_custom_target("docs" SOURCES ${ROOT_MD_FILES})

# Add tests
add_subdirectory("test")
endif()

# TODO: add install target
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ Kernel foundation library for Windows.
## Requirements
- Visual Studio 2019 or newer

## How to build tests
Use CMake to generate a Visual Studio solution:

```cmd
cmake -Bbuild .
```

Then open in Visual Studio `<project root>\build\kf.sln` and build it or run CMake:

```cmd
cmake --build build
```

## Roadmap
- [ ] Document
- [ ] Add tests
Expand Down
1 change: 1 addition & 0 deletions include/kf/Hex.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include "USimpleString.h"
#include "ASimpleString.h"
#include <span>
#include <array>

Expand Down
48 changes: 48 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
cmake_minimum_required(VERSION 3.16)

project(kf-test LANGUAGES CXX)

# Set C++ standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Set warning level to /W4 for MSVC
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX")

# TODO: fix warnings in code and remove this define
add_compile_definitions(_CRT_SECURE_NO_WARNINGS=1)

# Fetch dependencies
include(FetchContent)

# TODO: add stable reference in future
FetchContent_Declare(
findwdk
GIT_REPOSITORY https://github.com/SergiusTheBest/FindWDK
GIT_TAG stl
)

# TODO: add stable reference in future
FetchContent_Declare(
kmtest
GIT_REPOSITORY https://github.com/SergiusTheBest/kmtest.git
)

FetchContent_MakeAvailable(findwdk kmtest)

# Add CMake package for WDK projects
list(APPEND CMAKE_MODULE_PATH "${findwdk_SOURCE_DIR}/cmake")
find_package(WDK REQUIRED)

wdk_add_driver(kf-test WINVER NTDDI_WIN10 STL
pch.h
pch.cpp
HexTest.cpp
)

target_link_libraries(kf-test kf::kf kmtest::kmtest)

# Activate precompiled headers, unfortunately `target_precompile_headers` doesn't work with `wdk_add_driver`
set_target_properties(kf-test PROPERTIES COMPILE_FLAGS "/Yupch.h")
set_source_files_properties(pch.cpp PROPERTIES COMPILE_FLAGS "/Ycpch.h")
7 changes: 7 additions & 0 deletions test/HexTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "pch.h"
#include <kf/Hex.h>

SCENARIO("TODO: implement")
{
REQUIRE(true);
}
1 change: 1 addition & 0 deletions test/pch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "pch.h"
42 changes: 42 additions & 0 deletions test/pch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once
#include <ntifs.h>
#include <array>
#include <kmtest/kmtest.h>

// TODO: move this default implementation to kf

///////////////////////////////////////////////////////////
// Implement CRT error reporting and STL checks

extern "C" inline int _CrtDbgReport(
_In_ int /*_ReportType*/,
_In_opt_z_ char const* /*_FileName*/,
_In_ int /*_Linenumber*/,
_In_opt_z_ char const* /*_ModuleName*/,
_In_opt_z_ char const* /*_Format*/,
...)
{
#pragma warning(suppress: 28159) // Consider using 'error logging or driver shutdown' instead of 'KeBugCheckEx'
KeBugCheckEx(KERNEL_SECURITY_CHECK_FAILURE, 0, 0, 0, 0);
}

namespace std
{
[[noreturn]] inline void __cdecl _Xinvalid_argument(_In_z_ const char* /*What*/)
{
#pragma warning(suppress: 28159) // Consider using 'error logging or driver shutdown' instead of 'KeBugCheckEx'
KeBugCheckEx(KERNEL_SECURITY_CHECK_FAILURE, 0, 0, 0, 0);
}

[[noreturn]] inline void __cdecl _Xlength_error(_In_z_ const char* /*What*/)
{
#pragma warning(suppress: 28159) // Consider using 'error logging or driver shutdown' instead of 'KeBugCheckEx'
KeBugCheckEx(KERNEL_SECURITY_CHECK_FAILURE, 0, 0, 0, 0);
}

[[noreturn]] inline void __cdecl _Xout_of_range(_In_z_ const char* /*What*/)
{
#pragma warning(suppress: 28159) // Consider using 'error logging or driver shutdown' instead of 'KeBugCheckEx'
KeBugCheckEx(KERNEL_SECURITY_CHECK_FAILURE, 0, 0, 0, 0);
}
}