From d7b60adc62fbd1ca7234ea36bfc34d5b7323365d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Fri, 15 Feb 2019 14:23:30 +0100 Subject: [PATCH] find and include python plugin dependencies --- .appveyor.yml | 2 +- .gitmodules | 3 +++ CMakeLists.txt | 63 +++++++++++++++++++++++++++++++++++++++++++- docs/install.md | 2 +- lib/pybind11 | 1 + src/CMakeLists.txt | 41 +++++++++++++++++----------- tests/CMakeLists.txt | 7 ++++- 7 files changed, 100 insertions(+), 19 deletions(-) create mode 160000 lib/pybind11 diff --git a/.appveyor.yml b/.appveyor.yml index d370363..6dd147e 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -12,7 +12,7 @@ cache: before_build: - git submodule update --init --recursive # - C:\msys64\usr\bin\bash -lc "pacman --noconfirm -Syyuu" - - C:\msys64\usr\bin\bash -lc "pacman --noconfirm --needed -S make mingw-w64-x86_64-{cmake,toolchain,clang,gtkmm3,gtksourceviewmm3,boost,aspell,aspell-en,libgit2,universal-ctags-git,libffi}" + - C:\msys64\usr\bin\bash -lc "pacman --noconfirm --needed -S make mingw-w64-x86_64-{cmake,toolchain,clang,gtkmm3,gtksourceviewmm3,boost,aspell,aspell-en,libgit2,universal-ctags-git,libffi,pygobject-devel}" build_script: - C:\msys64\usr\bin\bash -lc "cd $APPVEYOR_BUILD_FOLDER && mkdir build && cd build && cmake -G\"MSYS Makefiles\" -DCMAKE_INSTALL_PREFIX=/mingw64 -DBUILD_TESTING=1 .. && make -j$(nproc) && make test" diff --git a/.gitmodules b/.gitmodules index a963aaa..b67fd67 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "lib/libclangmm"] path = lib/libclangmm url = https://gitlab.com/cppit/libclangmm +[submodule "lib/pybind11"] + path = lib/pybind11 + url = https://github.com/pybind/pybind11 diff --git a/CMakeLists.txt b/CMakeLists.txt index d0882b7..8dec029 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,9 +48,68 @@ option(BUILD_FUZZING "Build tests") option(LIBCLANG_PATH "Use custom path for libclang") option(LIBLLDB_PATH "Use custom path for liblldb") +if(${CMAKE_VERSION} VERSION_GREATER 3.11.4) + if (${CMAKE_HOST_WIN32}) + if("$ENV{APPVEYOR}" STREQUAL "True") + set(MINGW_PATH "C:/msys64/mingw64") + else() + set(MINGW_PATH "$ENV{MSYSTEM_PREFIX}") + endif() + set(MINGW_PYTHON_VERSION 3.7) + set(MINGW_LIBRARY_DIR "${MINGW_PATH}/lib") + set(MINGW_INCLUDE_DIR "${MINGW_PATH}/include") + find_file(Python3_LIBRARIES "libpython${MINGW_PYTHON_VERSION}m.dll.a" HINTS ${MINGW_LIBRARY_DIR} NO_DEFAULT_PATH) + find_path(Python3_INCLUDE_DIRS "Python.h" HINTS "${MINGW_INCLUDE_DIR}/python${MINGW_PYTHON_VERSION}m" NO_DEFAULT_PATH) + if (EXISTS ${Python3_LIBRARIES} AND EXISTS ${Python3_INCLUDE_DIRS}) + set(Python3_FOUND True) + set(Python3_LIBRARY_DIRS "${MINGW_LIBRARY_DIR}/python${MINGW_PYTHON_VERSION}") + set(Python3_VERSION_MAJOR 3) + set(Python3_VERSION_MINOR 7) + endif() + else() + find_package(Python3 COMPONENTS Development) + endif() +else() + find_package(PythonLibs 3) + message(${PYTHONLIBS_VERSION_STRING}) +endif() + +if(${Python3_FOUND}) + if(${CMAKE_HOST_WIN32}) + set(PYTHONLIBS_FOUND True) + set(PYTHON_MODULE_EXTENSION True) + endif() + set(PYTHONLIBS_FOUND ${Python3_FOUND}) + set(PYTHON_LIBRARIES ${Python3_LIBRARIES}) + set(PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS}) + set(PYTHON_LIBRARY_DIR ${Python3_LIBRARY_DIRS}/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}) +endif() + +include(FindPkgConfig) + +set(PYGOBJECT_FOUND False) + +if(${PYTHONLIBS_FOUND}) + add_subdirectory(lib/pybind11) + pkg_check_modules(PYGOBJECT pygobject-3.0) + if("${PYGOBJECT_FOUND}" STREQUAL "") + set(PYGOBJECT_FOUND False) + endif() +endif() + +if(${PYGOBJECT_FOUND}) + add_definitions(-DJUCI_ENABLE_PLUGINS) +else() + message(STATUS "Python or pygobject not found. Building juCi++ without plugin support.") +endif() + +set(BUILD_TESTING_SAVED ${BUILD_TESTING}) +set(BUILD_TESTING OFF CACHE BOOL "Disable sub-project tests" FORCE) +add_subdirectory(lib/libclangmm) +add_subdirectory(lib/tiny-process-library) +set(BUILD_TESTING ${BUILD_TESTING_SAVED} CACHE BOOL "Set to previous value" FORCE) find_package(Boost 1.54 COMPONENTS REQUIRED filesystem serialization) find_package(ASPELL REQUIRED) -include(FindPkgConfig) pkg_check_modules(GTKMM gtkmm-3.0 REQUIRED) pkg_check_modules(GTKSVMM gtksourceviewmm-3.0 REQUIRED) pkg_check_modules(LIBGIT2 libgit2 REQUIRED) @@ -112,6 +171,8 @@ include_directories( ${LIBCLANG_INCLUDE_DIRS} ${ASPELL_INCLUDE_DIR} ${LIBGIT2_INCLUDE_DIRS} + ${PYTHON_INCLUDE_DIRS} + ${PYGOBJECT_INCLUDE_DIRS} ) add_subdirectory("src") diff --git a/docs/install.md b/docs/install.md index 45a2239..baa4d53 100644 --- a/docs/install.md +++ b/docs/install.md @@ -143,7 +143,7 @@ make install Install dependencies (replace `x86_64` with `i686` for 32-bit MSYS2 installs): ```sh -pacman -S git mingw-w64-x86_64-cmake make mingw-w64-x86_64-toolchain mingw-w64-x86_64-clang mingw-w64-x86_64-gtkmm3 mingw-w64-x86_64-gtksourceviewmm3 mingw-w64-x86_64-boost mingw-w64-x86_64-aspell mingw-w64-x86_64-aspell-en mingw-w64-x86_64-libgit2 mingw-w64-x86_64-universal-ctags-git +pacman -S git make mingw-w64-x86_64-{cmake,toolchain,clang,gtkmm3,gtksourceviewmm3,boost,aspell,aspell-en,libgit2,universal-ctags-git,pygobject-devel} ``` Note that juCi++ must be built and run in a MinGW Shell (for instance MinGW-w64 Win64 Shell). diff --git a/lib/pybind11 b/lib/pybind11 new file mode 160000 index 0000000..9a19306 --- /dev/null +++ b/lib/pybind11 @@ -0,0 +1 @@ +Subproject commit 9a19306fbf30642ca331d0ec88e7da54a96860f9 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 86eadb9..9a41714 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -41,25 +41,36 @@ target_link_libraries(juci_shared tiny-process-library ) -set(JUCI_FILES - config.cpp - dialogs.cpp - dialogs_unix.cpp - directories.cpp - entrybox.cpp - info.cpp - juci.cpp - notebook.cpp - project.cpp - selection_dialog.cpp - window.cpp +set(JUCI_SOURCES + config.cc + dialogs.cc + dialogs_unix.cc + directories.cc + entrybox.cc + info.cc + juci.cc + notebook.cc + project.cc + selection_dialog.cc + tooltips.cc + window.cc ) + if(APPLE) - list(APPEND JUCI_FILES window_macos.m) + list(APPEND JUCI_SOURCES window_macos.m) +endif() + + +set(JUCI_TARGET_LIBRARIES + juci_shared +) + +if(${PYTHONLIBS_FOUND}) + list(APPEND JUCI_TARGET_LIBRARIES pybind11 ${PYTHON_LIBRARIES} ${PYGOBJECT_LIBRARIES}) endif() -add_executable(juci ${JUCI_FILES}) -target_link_libraries(juci juci_shared) +add_executable(juci ${JUCI_SOURCES}) +target_link_libraries(juci ${JUCI_TARGET_LIBRARIES}) if(APPLE) target_link_libraries(juci "-framework Foundation -framework AppKit") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5428c91..00322dc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,7 +5,12 @@ endif() add_definitions(-DJUCI_BUILD_PATH="${CMAKE_BINARY_DIR}" -DJUCI_TESTS_PATH="${CMAKE_CURRENT_SOURCE_DIR}") -include_directories(${CMAKE_SOURCE_DIR}/src) +include_directories( + ${CMAKE_SOURCE_DIR}/src + ${CMAKE_SOURCE_DIR}/libclangmm/src + ${CMAKE_SOURCE_DIR}/tiny-process-library + ${CMAKE_SOURCE_DIR}/pybind11 +) add_library(test_stubs OBJECT stubs/config.cpp