diff --git a/CMakeLists.txt b/CMakeLists.txt index f8fb174..eecdb95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,10 @@ -cmake_minimum_required (VERSION 2.8.4) +cmake_minimum_required (VERSION 2.8.8) set(project_name juci) project (${project_name}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -Wall -Wextra -Wno-unused-parameter -Wno-reorder") -if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug")) +if(CMAKE_BUILD_TYPE STREQUAL "") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") endif() @@ -18,6 +18,22 @@ endif() set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules/") find_package(LibClang REQUIRED) + +#Find liblldb with the same version as the version of libclang found +string(REPLACE libclang liblldb LIBLLDB_LIBRARIES "${LIBCLANG_LIBRARIES}") +if(EXISTS "${LIBLLDB_LIBRARIES}") + set(LIBLLDB_FOUND TRUE) +elseif(EXISTS "${LIBLLDB_LIBRARIES}.1") + set(LIBLLDB_LIBRARIES "${LIBLLDB_LIBRARIES}.1") + set(LIBLLDB_FOUND TRUE) +endif() +if(LIBLLDB_FOUND) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJUCI_ENABLE_DEBUG") +else() + set(LIBLLDB_LIBRARIES "") + message("liblldb not found. Building juCi++ without debugging support") +endif() + find_package(Boost 1.54 COMPONENTS regex system filesystem REQUIRED) find_package(ASPELL REQUIRED) include(FindPkgConfig) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4e56656..50994b8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,20 +13,6 @@ if(MSYS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMSYS_PROCESS_USE_SH") endif() -string(REPLACE libclang liblldb LIBLLDB_LIBRARIES "${LIBCLANG_LIBRARIES}") -if(EXISTS "${LIBLLDB_LIBRARIES}") - set(LIBLLDB_FOUND TRUE) -elseif(EXISTS "${LIBLLDB_LIBRARIES}.1") - set(LIBLLDB_LIBRARIES "${LIBLLDB_LIBRARIES}.1") - set(LIBLLDB_FOUND TRUE) -endif() -if(LIBLLDB_FOUND) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJUCI_ENABLE_DEBUG") -else() - set(LIBLLDB_LIBRARIES "") - message("liblldb not found. Building juCi++ without debugging support") -endif() - set(global_includes ${Boost_INCLUDE_DIRS} ${GTKMM_INCLUDE_DIRS} @@ -38,54 +24,40 @@ set(global_includes ) set(global_libraries - ${LIBCLANG_LIBRARIES} ${GTKMM_LIBRARIES} ${GTKSVMM_LIBRARIES} ${Boost_LIBRARIES} - ${ASPELL_LIBRARIES} + ${LIBCLANG_LIBRARIES} ${LIBLLDB_LIBRARIES} + ${ASPELL_LIBRARIES} ) set(project_files - cmake.cc - cmake.h config.cc - config.h dialogs.cc - dialogs.h directories.cc - directories.h - dispatcher.cc - dispatcher.h entrybox.cc - entrybox.h - files.h - filesystem.cc - filesystem.h - info.h info.cc juci.cc - juci.h menu.cc - menu.h notebook.cc - notebook.h project.cc - project.h - project_build.h - project_build.cc selectiondialog.cc - selectiondialog.h - source.cc - source.h - source_clang.cc - source_clang.h terminal.cc - terminal.h tooltips.cc - tooltips.h window.cc - window.h + + ../tiny-process-library/process.cpp +) + +#Files used both in ../src and ../tests +set(project_shared_files + cmake.cc + dispatcher.cc + filesystem.cc + project_build.cc + source.cc + source_clang.cc ../libclangmm/src/CodeCompleteResults.cc ../libclangmm/src/CompilationDatabase.cc @@ -101,11 +73,10 @@ set(project_files ../libclangmm/src/Tokens.cc ../libclangmm/src/TranslationUnit.cc ../libclangmm/src/Utility.cc - - ../tiny-process-library/process.cpp) +) if(LIBLLDB_FOUND) - list(APPEND project_files debug_clang.h debug_clang.cc) + list(APPEND project_shared_files debug_clang.cc) endif() if(MSYS) @@ -116,11 +87,13 @@ endif() include_directories(${global_includes}) +add_library(project_shared ${project_shared_files}) + if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") AND (NOT $ENV{distribution} STREQUAL "")) add_library(${project_name} OBJECT ${project_files}) else() add_executable(${project_name} ${project_files}) - target_link_libraries(${project_name} ${global_libraries}) + target_link_libraries(${project_name} ${global_libraries} project_shared) install(TARGETS ${project_name} RUNTIME DESTINATION bin ) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2f78419..e04a37a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -4,38 +4,43 @@ set(global_includes ${Boost_INCLUDE_DIRS} ${GTKMM_INCLUDE_DIRS} ${GTKSVMM_INCLUDE_DIRS} + ${LIBCLANG_INCLUDE_DIRS} ${ASPELL_INCLUDE_DIR} - ../src + ../libclangmm/src ../tiny-process-library + ../src ) set(global_libraries ${GTKMM_LIBRARIES} ${GTKSVMM_LIBRARIES} ${Boost_LIBRARIES} + ${LIBCLANG_LIBRARIES} + ${LIBLLDB_LIBRARIES} ${ASPELL_LIBRARIES} ) -set(stub_sources +set(stub_files stubs/config.cc stubs/dialogs.cc - stubs/dispatcher.cc stubs/info.cc stubs/selectiondialog.cc stubs/terminal.cc stubs/tooltips.cc ) -include_directories(${global_includes}) +add_library(stubs ${stub_files}) -add_library(stubs_library ${stub_sources}) +include_directories(${global_includes}) -add_executable(cmake_build_test cmake_build_test.cc - ../src/filesystem.cc ../src/cmake.cc ../src/project_build.cc) -target_link_libraries(cmake_build_test ${global_libraries} stubs_library) +add_executable(cmake_build_test cmake_build_test.cc) +target_link_libraries(cmake_build_test ${global_libraries} project_shared stubs) add_test(cmake_build_test cmake_build_test) -add_executable(source_test source_test.cc - ../src/source.cc) -target_link_libraries(source_test ${global_libraries} stubs_library) +add_executable(source_test source_test.cc) +target_link_libraries(source_test ${global_libraries} project_shared stubs) add_test(source_test source_test) + +add_executable(source_clang_test source_clang_test.cc) +target_link_libraries(source_clang_test ${global_libraries} project_shared stubs) +add_test(source_clang_test source_clang_test) diff --git a/tests/clang_project/CMakeLists.txt b/tests/clang_project/CMakeLists.txt new file mode 100644 index 0000000..335f619 --- /dev/null +++ b/tests/clang_project/CMakeLists.txt @@ -0,0 +1 @@ +set(project_name hello) diff --git a/tests/clang_project/build/compile_commands.json b/tests/clang_project/build/compile_commands.json new file mode 100644 index 0000000..8c1f911 --- /dev/null +++ b/tests/clang_project/build/compile_commands.json @@ -0,0 +1,7 @@ +[ +{ + "directory": "build", + "command": "c++ -std=c++1y -Wall -Wextra -Wno-unused-parameter main.cpp", + "file": "main.cpp" +} +] \ No newline at end of file diff --git a/tests/clang_project/main.cpp b/tests/clang_project/main.cpp new file mode 100644 index 0000000..811f08b --- /dev/null +++ b/tests/clang_project/main.cpp @@ -0,0 +1,5 @@ +#include + +int main() { + std::cout << "hello world\n"; +} diff --git a/tests/source_clang_test.cc b/tests/source_clang_test.cc new file mode 100644 index 0000000..64c4222 --- /dev/null +++ b/tests/source_clang_test.cc @@ -0,0 +1,43 @@ +#include +#include "source_clang.h" +#include "config.h" +#include "filesystem.h" + +std::string hello_world_error=R"(#include + +int main() { + std::cout << "hello world\n" +} +)"; + +//Requires display server to work +//However, it is possible to use the Broadway backend if the test is run in a pure terminal environment: +//broadwayd& +//make test + +int main() { + auto app=Gtk::Application::create(); + Gsv::init(); + + Config::get().project.default_build_path="./build"; + Source::ClangView *clang_view=new Source::ClangView(boost::filesystem::canonical(std::string(JUCI_TESTS_PATH)+"/clang_project/main.cpp"), + Gsv::LanguageManager::get_default()->get_language("cpp")); + while(!clang_view->parsed) { + while(Gtk::Main::events_pending()) + Gtk::Main::iteration(false); + } + g_assert(clang_view->diagnostics.size()==0); + clang_view->get_buffer()->set_text(hello_world_error); + while(Gtk::Main::events_pending()) + Gtk::Main::iteration(false); + while(!clang_view->parsed) { + while(Gtk::Main::events_pending()) + Gtk::Main::iteration(false); + } + g_assert(clang_view->diagnostics.size()>0); + + clang_view->async_delete(); + clang_view->delete_thread.join(); + while(Gtk::Main::events_pending()) + Gtk::Main::iteration(false); +} diff --git a/tests/source_test.cc b/tests/source_test.cc index 237b2d5..8c1a733 100644 --- a/tests/source_test.cc +++ b/tests/source_test.cc @@ -2,18 +2,6 @@ #include "source.h" #include "filesystem.h" -int filesystem::read(const std::string &path, Glib::RefPtr text_buffer) { - return 0; -} - -int filesystem::read_non_utf8(const std::string &path, Glib::RefPtr text_buffer) { - return 0; -} - -bool filesystem::write(const std::string &path, Glib::RefPtr text_buffer) { - return false; -} - std::string hello_world=R"(#include int main() { diff --git a/tests/stubs/dispatcher.cc b/tests/stubs/dispatcher.cc deleted file mode 100644 index 8c04845..0000000 --- a/tests/stubs/dispatcher.cc +++ /dev/null @@ -1,5 +0,0 @@ -#include "dispatcher.h" - -Dispatcher::Dispatcher() {} - -Dispatcher::~Dispatcher() {} diff --git a/tests/stubs/selectiondialog.cc b/tests/stubs/selectiondialog.cc index 2b14137..f8b9d67 100644 --- a/tests/stubs/selectiondialog.cc +++ b/tests/stubs/selectiondialog.cc @@ -17,4 +17,10 @@ SelectionDialog::SelectionDialog(Gtk::TextView& text_view, Glib::RefPtr start_mark): + SelectionDialogBase(text_view, start_mark, false, false) {} + bool CompletionDialog::on_key_press(GdkEventKey* key) { return true;} + +bool CompletionDialog::on_key_release(GdkEventKey* key) {return true;} diff --git a/tests/stubs/terminal.cc b/tests/stubs/terminal.cc index 0eb09ef..43f97c6 100644 --- a/tests/stubs/terminal.cc +++ b/tests/stubs/terminal.cc @@ -1,5 +1,17 @@ #include "terminal.h" +Terminal::InProgress::InProgress(const std::string& start_msg): stop(false) {} + +Terminal::InProgress::~InProgress() {} + +std::shared_ptr Terminal::print_in_progress(std::string start_msg) { + return std::make_shared(""); +} + +void Terminal::InProgress::done(const std::string& msg) {} + +void Terminal::InProgress::cancel(const std::string &msg) {} + Terminal::Terminal() {} bool Terminal::on_motion_notify_event(GdkEventMotion* motion_event) {return false;} @@ -17,3 +29,5 @@ int Terminal::process(std::istream &stdin_stream, std::ostream &stdout_stream, c size_t Terminal::print(const std::string &message, bool bold) { return 0; } + +void Terminal::async_print(const std::string &message, bool bold) {} diff --git a/tests/stubs/tooltips.cc b/tests/stubs/tooltips.cc index a7d73d9..909e5d9 100644 --- a/tests/stubs/tooltips.cc +++ b/tests/stubs/tooltips.cc @@ -1,7 +1,16 @@ #include "tooltips.h" +Gdk::Rectangle Tooltips::drawn_tooltips_rectangle=Gdk::Rectangle(); + +Tooltip::Tooltip(std::function()> create_tooltip_buffer, + Gtk::TextView& text_view, + Glib::RefPtr start_mark, + Glib::RefPtr end_mark): text_view(text_view) {} + Tooltip::~Tooltip() {} -Gdk::Rectangle Tooltips::drawn_tooltips_rectangle=Gdk::Rectangle(); +void Tooltips::show(Gdk::Rectangle const&, bool) {} + +void Tooltips::show(bool) {} void Tooltips::hide() {}