diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 46ad126b..4c909397 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -425,8 +425,8 @@ endif() if (TARGET Graphviz::GVC) - list(APPEND SOURCES widgets/GraphvizLayout.cpp) - list(APPEND HEADER_FILES widgets/GraphvizLayout.h) + list(APPEND SOURCE_FILES ${CUTTER_PRO_GRAPHVIZ_SOURCES}) + list(APPEND HEADER_FILES ${CUTTER_PRO_GRAPHVIZ_HEADERS}) endif() if (WIN32) @@ -442,8 +442,9 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" set_source_files_properties(${BINDINGS_SOURCE} PROPERTIES COMPILE_FLAGS -w) endif() - -add_executable(Cutter ${OPTIONS} ${UI_FILES} ${QRC_FILES} ${PLATFORM_RESOURCES} ${SOURCES} ${HEADER_FILES} ${BINDINGS_SOURCE}) +list(REMOVE_ITEM SOURCES Main.cpp) +add_library(CutterLib OBJECT ${UI_FILES} ${QRC_FILES} ${PLATFORM_RESOURCES} ${SOURCES} ${HEADER_FILES} ${BINDINGS_SOURCE}) +add_executable(Cutter ${OPTIONS} Main.cpp) set_target_properties(Cutter PROPERTIES OUTPUT_NAME cutter RUNTIME_OUTPUT_DIRECTORY .. @@ -458,33 +459,39 @@ foreach(_dir ${CUTTER_INCLUDE_DIRECTORIES}) $ $ ) + target_include_directories(CutterLib PUBLIC + $ + $ + ) endforeach() +target_link_libraries(Cutter CutterLib) if (TARGET Graphviz::GVC) - target_link_libraries(Cutter PRIVATE Graphviz::GVC) - target_compile_definitions(Cutter PRIVATE CUTTER_ENABLE_GRAPHVIZ) + target_link_libraries(CutterLib PRIVATE Graphviz::GVC) + target_compile_definitions(CutterLib PRIVATE CUTTER_ENABLE_GRAPHVIZ) endif() if(CUTTER_ENABLE_CRASH_REPORTS) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) - target_link_libraries(Cutter PRIVATE Threads::Threads) + target_link_libraries(CutterLib PRIVATE Threads::Threads) add_definitions(-DCUTTER_ENABLE_CRASH_REPORTS) if (NOT WIN32) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g ") endif() find_package(Breakpad REQUIRED) - target_link_libraries(Cutter PRIVATE Breakpad::client) + target_link_libraries(CutterLib PRIVATE Breakpad::client) endif() -target_link_libraries(Cutter PUBLIC ${QT_PREFIX}::Core ${QT_PREFIX}::Widgets ${QT_PREFIX}::Gui PRIVATE ${QT_PREFIX}::Svg ${QT_PREFIX}::Network) +target_link_libraries(CutterLib PUBLIC ${QT_PREFIX}::Core ${QT_PREFIX}::Widgets ${QT_PREFIX}::Gui PRIVATE ${QT_PREFIX}::Svg ${QT_PREFIX}::Network) if (CUTTER_QT6) - target_link_libraries(Cutter PUBLIC Qt6::Core5Compat Qt6::SvgWidgets) - target_link_libraries(Cutter PRIVATE Qt6::OpenGLWidgets) + target_link_libraries(CutterLib PUBLIC Qt6::Core5Compat Qt6::SvgWidgets) + target_link_libraries(CutterLib PRIVATE Qt6::OpenGLWidgets) endif() -target_link_libraries(Cutter PUBLIC ${RIZIN_TARGET}) +target_link_libraries(CutterLib PUBLIC ${RIZIN_TARGET}) + if(CUTTER_ENABLE_PYTHON) if (WIN32) # On windows some of the Python STABLE API functions are in seperate library @@ -494,15 +501,15 @@ if(CUTTER_ENABLE_PYTHON) if((NOT _PYTHON_LIBRARY STREQUAL "optimized") AND (NOT _PYTHON_LIBRARY STREQUAL "debug")) get_filename_component(_PYTHON_LIB_DIR ${_PYTHON_LIBRARY} DIRECTORY) message(STATUS "Add extra library dir for Python: ${_PYTHON_LIB_DIR}") - target_link_directories(Cutter PRIVATE ${_PYTHON_LIB_DIR}) + target_link_directories(CutterLib PRIVATE ${_PYTHON_LIB_DIR}) endif() endforeach() endif() - target_link_libraries(Cutter PRIVATE ${PYTHON_LIBRARIES}) + target_link_libraries(CutterLib PRIVATE ${PYTHON_LIBRARIES}) if(CUTTER_ENABLE_PYTHON_BINDINGS) - target_link_libraries(Cutter PRIVATE Shiboken2::libshiboken PySide2::pyside2) + target_link_libraries(CutterLib PRIVATE Shiboken2::libshiboken PySide2::pyside2) - get_target_property(RAW_BINDINGS_INCLUDE_DIRS Cutter INCLUDE_DIRECTORIES) + get_target_property(RAW_BINDINGS_INCLUDE_DIRS CutterLib INCLUDE_DIRECTORIES) if(NOT CUTTER_USE_BUNDLED_RIZIN) get_target_property(RAW_RIZIN_INCLUDE_DIRS ${RIZIN_TARGET} INTERFACE_INCLUDE_DIRECTORIES) list(APPEND RAW_BINDINGS_INCLUDE_DIRS "${RAW_RIZIN_INCLUDE_DIRS}") @@ -516,10 +523,6 @@ if(CUTTER_ENABLE_PYTHON) endif() endforeach() -<<<<<<< HEAD -======= - get_target_property(BINDINGS_INCLUDE_DIRS CutterLib INCLUDE_DIRECTORIES) ->>>>>>> Fix travis if(APPLE AND _qt5Core_install_prefix) list(APPEND BINDINGS_INCLUDE_DIRS "${_qt5Core_install_prefix}/include") list(APPEND BINDINGS_INCLUDE_DIRS "${_qt5Core_install_prefix}/include/QtCore") @@ -539,8 +542,8 @@ if(CUTTER_ENABLE_PYTHON) endif() if(TARGET KF5::SyntaxHighlighting) - target_link_libraries(Cutter PRIVATE KF5::SyntaxHighlighting) - target_compile_definitions(Cutter PRIVATE CUTTER_ENABLE_KSYNTAXHIGHLIGHTING) + target_link_libraries(CutterLib PRIVATE KF5::SyntaxHighlighting) + target_compile_definitions(CutterLib PRIVATE CUTTER_ENABLE_KSYNTAXHIGHLIGHTING) endif() if (CUTTER_APPIMAGE_BUILD) @@ -562,7 +565,7 @@ endif() include(Translations) # Install files -install(TARGETS Cutter +install(TARGETS Cutter CutterLib EXPORT CutterTargets RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" BUNDLE DESTINATION "." # needs to be tested diff --git a/src/CutterApplication.cpp b/src/CutterApplication.cpp index 1c231304..9f9ee7f5 100644 --- a/src/CutterApplication.cpp +++ b/src/CutterApplication.cpp @@ -143,7 +143,7 @@ CutterApplication::CutterApplication(int &argc, char **argv, bool test) : QAppli setStyle(new CutterProxyStyle()); #endif // QT_VERSION_CHECK(5, 10, 0) < QT_VERSION - if (clOptions.args.empty() && clOptions.fileOpenOptions.projectFile.isEmpty()) { + if (clOptions.args.empty() && clOptions.fileOpenOptions.projectFile.isEmpty() && !test) { // check if this is the first execution of Cutter in this computer // Note: the execution after the preferences been reset, will be considered as // first-execution @@ -151,7 +151,7 @@ CutterApplication::CutterApplication(int &argc, char **argv, bool test) : QAppli mainWindow->displayWelcomeDialog(); } mainWindow->displayNewFileDialog(); - } else { // filename specified as positional argument + } else if (!test) { // filename specified as positional argument bool askOptions = (clOptions.analysisLevel != AutomaticAnalysisLevel::Ask) || !clOptions.fileOpenOptions.projectFile.isEmpty(); mainWindow->openNewFile(clOptions.fileOpenOptions, askOptions); @@ -193,42 +193,6 @@ CutterApplication::CutterApplication(int &argc, char **argv, bool test) : QAppli Core()->setConfig("ghidra.sleighhome", sleighHome.absolutePath()); } #endif - - if (!test) { - if (args.empty()) { - if (analLevelSpecified) { - printf("%s\n", - QObject::tr("Filename must be specified to start analysis automatically.").toLocal8Bit().constData()); - std::exit(1); - } - - // check if this is the first execution of Cutter in this computer - // Note: the execution after the preferences benn reset, will be considered as first-execution - if (Config()->isFirstExecution()) { - mainWindow->displayWelcomeDialog(); - } - mainWindow->displayNewFileDialog(); - } else { // filename specified as positional argument - InitialOptions options; - options.filename = args[0]; - if (analLevelSpecified) { - switch (analLevel) { - case 0: - default: - options.analCmd = {}; - break; - case 1: - options.analCmd = { {"aaa", "Auto analysis"} }; - break; - case 2: - options.analCmd = { {"aaaa", "Auto analysis (experimental)"} }; - break; - } - } - options.script = cmd_parser.value(scriptOption); - mainWindow->openNewFile(options, analLevelSpecified); - } - } } CutterApplication::~CutterApplication() diff --git a/src/core/MainWindow.h b/src/core/MainWindow.h index 45d9a6ff..9b815f41 100644 --- a/src/core/MainWindow.h +++ b/src/core/MainWindow.h @@ -67,7 +67,7 @@ class CUTTER_EXPORT MainWindow : public QMainWindow public: bool responsive; - explicit MainWindow(QWidget *parent = nullptr); + explicit MainWindow(QWidget *parent = nullptr, bool testMode = false); ~MainWindow() override; void openNewFile(InitialOptions &options, bool skipOptionsDialog = false); diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 5d425e12..218120e4 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -1,4 +1,3 @@ - find_package(Qt5 REQUIRED COMPONENTS Test) set(TEST_HEADER_FILES