diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..77aa90e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,53 @@ +cmake_minimum_required(VERSION 3.8) +project(oaknut LANGUAGES CXX VERSION 0.0.0) + +# Determine if we're built as a subproject (using add_subdirectory) +# or if this is the master project. +set(MASTER_PROJECT OFF) +if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + set(MASTER_PROJECT ON) +endif() + +# Disable in-source builds +set(CMAKE_DISABLE_SOURCE_CHANGES ON) +set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) +if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") + message(SEND_ERROR "In-source builds are not allowed.") +endif() + +# Source project files +set(header_files + ${CMAKE_CURRENT_SOURCE_DIR}/include/oaknut/impl/multi_typed_name.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/oaknut/impl/string_literal.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/oaknut/impl/enum.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/oaknut/impl/offset.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/oaknut/impl/imm.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/oaknut/impl/arm64_mnemonics.inc.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/oaknut/impl/reg.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/oaknut/impl/arm64_encode_helpers.inc.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/oaknut/oaknut.hpp +) + +# Library definition +add_library(oaknut INTERFACE) +add_library(merry::oaknut ALIAS oaknut) +target_sources(oaknut INTERFACE "$") +target_include_directories(oaknut INTERFACE $) +target_compile_features(oaknut INTERFACE cxx_std_20) + +# Tests +if (MASTER_PROJECT) + find_package(Catch2 3 REQUIRED) + + add_executable(oaknut-tests + tests/basic.cpp + ) + target_include_directories(oaknut-tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests) + target_link_libraries(oaknut-tests PRIVATE Catch2::Catch2WithMain merry::oaknut) + target_compile_options(oaknut-tests PRIVATE -Wall -Wextra -Wcast-qual -pedantic -pedantic-errors -Wfatal-errors -Wno-missing-braces) + + include(CTest) + include(Catch) + catch_discover_tests(oaknut-tests) + enable_testing() +endif() diff --git a/test.cpp b/tests/basic.cpp similarity index 77% rename from test.cpp rename to tests/basic.cpp index 64e8a03..c0eed71 100644 --- a/test.cpp +++ b/tests/basic.cpp @@ -1,6 +1,10 @@ +// SPDX-FileCopyrightText: 2022 merryhime +// SPDX-License-Identifier: MIT + #include #include +#include #include #include #include @@ -8,7 +12,7 @@ #include "oaknut/oaknut.hpp" -int main() +TEST_CASE("Basic Test") { const size_t page_size = getpagesize(); std::printf("page size: %zu\n", page_size); @@ -27,7 +31,6 @@ int main() pthread_jit_write_protect_np(true); sys_icache_invalidate(mem, page_size); - std::printf("%i\n", ((int (*)())mem)()); - - return 0; + int result = ((int (*)())mem)(); + REQUIRE(result == 42); }