diff --git a/CMakeLists.txt b/CMakeLists.txt index f15684c7..02e43e14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,13 @@ cmake_minimum_required(VERSION 3.26.4) ########################################## option(MOMO_ENABLE_SANITIZER "Enable sanitizer" OFF) +option(MOMO_BUILD_AS_LIBRARY "Configure and Build the emulator as a shared library (without the samples and tests)" OFF) + +if(MOMO_BUILD_AS_LIBRARY) + add_compile_definitions(MOMO_BUILD_AS_LIBRARY=1) +else() + add_compile_definitions(MOMO_BUILD_AS_LIBRARY=0) +endif() ########################################## diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ea61b41b..ff79e18f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,11 +2,13 @@ add_subdirectory(common) add_subdirectory(emulator) add_subdirectory(unicorn-emulator) add_subdirectory(windows-emulator) -add_subdirectory(analyzer) -add_subdirectory(fuzzing-engine) -add_subdirectory(fuzzer) -if(WIN32) - add_subdirectory(bad-sample) - add_subdirectory(test-sample) +if (NOT MOMO_BUILD_AS_LIBRARY) + add_subdirectory(analyzer) + add_subdirectory(fuzzing-engine) + add_subdirectory(fuzzer) + if(WIN32) + add_subdirectory(bad-sample) + add_subdirectory(test-sample) + endif() + add_subdirectory(windows-emulator-test) endif() -add_subdirectory(windows-emulator-test) diff --git a/src/analyzer/CMakeLists.txt b/src/analyzer/CMakeLists.txt index 13b46b08..54c497d1 100644 --- a/src/analyzer/CMakeLists.txt +++ b/src/analyzer/CMakeLists.txt @@ -13,7 +13,6 @@ momo_assign_source_group(${SRC_FILES}) target_precompile_headers(analyzer PRIVATE std_include.hpp) target_link_libraries(analyzer PRIVATE - common reflect windows-emulator ) diff --git a/src/bad-sample/CMakeLists.txt b/src/bad-sample/CMakeLists.txt index 2e6e2502..eb1d6316 100644 --- a/src/bad-sample/CMakeLists.txt +++ b/src/bad-sample/CMakeLists.txt @@ -7,6 +7,6 @@ file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS list(SORT SRC_FILES) add_executable(bad-sample ${SRC_FILES}) -target_link_libraries(bad-sample PRIVATE common) +target_link_libraries(bad-sample PRIVATE emulator-common) momo_assign_source_group(${SRC_FILES}) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index dd09f43b..42753b78 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -3,14 +3,14 @@ file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS *.hpp ) -add_library(common ${SRC_FILES}) +add_library(emulator-common ${SRC_FILES}) momo_assign_source_group(${SRC_FILES}) -target_include_directories(common INTERFACE "${CMAKE_CURRENT_LIST_DIR}") +target_include_directories(emulator-common INTERFACE "${CMAKE_CURRENT_LIST_DIR}") set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) -target_link_libraries(common PUBLIC +target_link_libraries(emulator-common PUBLIC Threads::Threads ) diff --git a/src/fuzzer/CMakeLists.txt b/src/fuzzer/CMakeLists.txt index a06cae8b..8a7b600a 100644 --- a/src/fuzzer/CMakeLists.txt +++ b/src/fuzzer/CMakeLists.txt @@ -13,7 +13,6 @@ momo_assign_source_group(${SRC_FILES}) target_precompile_headers(fuzzer PRIVATE std_include.hpp) target_link_libraries(fuzzer PRIVATE - common fuzzing-engine windows-emulator ) diff --git a/src/fuzzing-engine/CMakeLists.txt b/src/fuzzing-engine/CMakeLists.txt index bda32d22..90ecd42b 100644 --- a/src/fuzzing-engine/CMakeLists.txt +++ b/src/fuzzing-engine/CMakeLists.txt @@ -11,7 +11,7 @@ add_library(fuzzing-engine ${SRC_FILES}) momo_assign_source_group(${SRC_FILES}) target_link_libraries(fuzzing-engine PRIVATE - common + emulator-common ) target_include_directories(fuzzing-engine INTERFACE diff --git a/src/unicorn-emulator/CMakeLists.txt b/src/unicorn-emulator/CMakeLists.txt index 3b473f3b..f86f2870 100644 --- a/src/unicorn-emulator/CMakeLists.txt +++ b/src/unicorn-emulator/CMakeLists.txt @@ -6,11 +6,15 @@ file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS list(SORT SRC_FILES) -add_library(unicorn-emulator SHARED ${SRC_FILES}) +if(MOMO_BUILD_AS_LIBRARY) + add_library(unicorn-emulator STATIC ${SRC_FILES}) +else() + add_library(unicorn-emulator SHARED ${SRC_FILES}) +endif() target_include_directories(unicorn-emulator INTERFACE "${CMAKE_CURRENT_LIST_DIR}" ) target_link_libraries(unicorn-emulator PUBLIC emulator) -target_link_libraries(unicorn-emulator PRIVATE unicorn common) +target_link_libraries(unicorn-emulator PRIVATE unicorn emulator-common) diff --git a/src/unicorn-emulator/unicorn_x64_emulator.hpp b/src/unicorn-emulator/unicorn_x64_emulator.hpp index f0535a56..6d5bd48e 100644 --- a/src/unicorn-emulator/unicorn_x64_emulator.hpp +++ b/src/unicorn-emulator/unicorn_x64_emulator.hpp @@ -12,6 +12,8 @@ namespace unicorn { +#if !MOMO_BUILD_AS_LIBRARY UNICORN_EMULATOR_DLL_STORAGE +#endif std::unique_ptr create_x64_emulator(); } diff --git a/src/windows-emulator-test/CMakeLists.txt b/src/windows-emulator-test/CMakeLists.txt index 42f1934b..0bffacc1 100644 --- a/src/windows-emulator-test/CMakeLists.txt +++ b/src/windows-emulator-test/CMakeLists.txt @@ -12,7 +12,6 @@ momo_assign_source_group(${SRC_FILES}) target_link_libraries(windows-emulator-test PRIVATE gtest - common windows-emulator ) diff --git a/src/windows-emulator/CMakeLists.txt b/src/windows-emulator/CMakeLists.txt index 0fb26ae9..b2ffe79c 100644 --- a/src/windows-emulator/CMakeLists.txt +++ b/src/windows-emulator/CMakeLists.txt @@ -13,12 +13,12 @@ momo_assign_source_group(${SRC_FILES}) target_precompile_headers(windows-emulator PRIVATE std_include.hpp) target_link_libraries(windows-emulator PRIVATE - common unicorn-emulator mini-gdbstub ) target_link_libraries(windows-emulator PUBLIC + emulator-common emulator )