Skip to content

Commit

Permalink
Add proper cmake targeting; Cleanup source tree.
Browse files Browse the repository at this point in the history
  • Loading branch information
ek0 committed Jun 13, 2024
1 parent e51b2ee commit 5e675f4
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 28 deletions.
40 changes: 26 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cmake_policy(SET CMP0067 NEW)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_STANDARD 23)

project(bn-test VERSION 0.1)
project(bn-test VERSION 0.1 LANGUAGES CXX)

if(WIN32)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
Expand All @@ -28,31 +28,43 @@ FetchContent_Declare(googletest
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

include_directories(".")
add_library(bntest STATIC)

add_library(bntest STATIC
# HEADERS
"bntest.h"
target_sources(bntest
PUBLIC
# HEADERS
"${CMAKE_CURRENT_LIST_DIR}/src/bntest.h"

# SOURCE FILES
"bntest.cc")
PRIVATE
# SOURCE FILES
"${CMAKE_CURRENT_LIST_DIR}/src/bntest.cc")

target_link_libraries(bntest
PUBLIC binaryninjaapi
PRIVATE binaryninjaapi
PUBLIC GTest::gtest_main)

target_include_directories(bntest
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

install(TARGETS bntest
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
install(FILES "src/bntest.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

if(DEFINED ENABLE_TESTING)
message(STATUS "Enabling bntest plugin for testing...")
enable_testing()
add_library(bntest-tests SHARED
"tests.cc"
"examples/test-plugin.cc"
"examples/mlil_tests.cc")

#include(GoogleTest)
#gtest_discover_tests(bntest-tests)

target_link_libraries(bntest-tests
PRIVATE bntest)
PRIVATE bntest
PRIVATE binaryninjaapi)

install(TARGETS bntest-tests DESTINATION "$ENV{APPDATA}\\Binary Ninja\\plugins")
endif()
endif()
12 changes: 0 additions & 12 deletions bntest.h

This file was deleted.

1 change: 0 additions & 1 deletion tests.cc → examples/test-plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ BINARYNINJAPLUGIN bool CorePluginInit() {
RunTests);
return true;
}

}
2 changes: 1 addition & 1 deletion bntest.cc → src/bntest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ void InitTests() {
new BinaryNinjaTestListener);
}

void RunTests() { RUN_ALL_TESTS(); }
int RunTests() { return RUN_ALL_TESTS(); }

} // namespace bntest
16 changes: 16 additions & 0 deletions src/bntest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef BNTEST_BNTEST_H
#define BNTEST_BNTEST_H

namespace bntest {

// Initialize the test suite. Should be called during your plugin
// initialization.
void InitTests();

// Run all registered tests.
// Returns the result of RUN_ALL_TESTS macro.
int RunTests();

} // namespace bntest

#endif

0 comments on commit 5e675f4

Please sign in to comment.