From a056193dafd97782b9fd9249019f4482fd1890eb Mon Sep 17 00:00:00 2001 From: Niklas Date: Wed, 19 Feb 2025 01:08:56 +0100 Subject: [PATCH] Switch default values for install from System to User directories - Previous installs of the plugin require more than User level permission -> switch to User accessible and from Xournal supported directories while keeping everything a CMake argument for custom overrides - Add additional support of icon install - Instead of scanning for files once on configure update and rescan directories for new files and file changes every time the install command is ran - Less CMake commands by extending the PreLoad.cmake file with default values (they are now also removed from the main CMakeLists.txt file) --- .gitignore | 1 + CMakeLists.txt | 49 +++++++++++++++++++++++++++++++++---------------- PreLoad.cmake | 30 +++++++++++++++++++++++++----- README.md | 6 ++++++ 4 files changed, 65 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index b21784b..c00be78 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ out* *.out build/ *.svg +dist do.sh ImageTranscription/inkpath.so ImageTranscription/ipcvobj.so diff --git a/CMakeLists.txt b/CMakeLists.txt index 15d2c00..e93a942 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,20 +2,24 @@ cmake_minimum_required(VERSION 3.22.1) set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) PROJECT(inkpath) +set(PLUGIN_NAME "ImageTranscription") +set(PLUGIN_DIR "${CMAKE_CURRENT_SOURCE_DIR}/plugin") +set(CMAKE_INSTALL_PREFIX_PLUGIN "${CMAKE_INSTALL_PREFIX}") + +# Options +set(CMAKE_INSTALL_PREFIX_ICONS "" CACHE PATH "Installation path for icons") + # Send artifacts to /build/ImageTranscription. That will be the final artifact. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/ImageTranscription) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/ImageTranscription) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/ImageTranscription) # Things work a little differently on Windows vs Linux. -IF(WIN32) - message("Building for Windows") - set(INSTALL_DESTINATION "C:/Program Files/Xournal++/share/xournalpp/plugins") -ELSE() - # Need position-independent code flag enabled to make Lua work - set(CMAKE_POSITION_INDEPENDENT_CODE ON) - set(INSTALL_DESTINATION /usr/share/xournalpp/plugins) -ENDIF() +if(UNIX AND NOT APPLE) + # For dynamic libraries enabling a -fPIC (Position-Independent Code) flag is + # required when compiling code into shared libraries + set(CMAKE_POSITION_INDEPENDENT_CODE ON) +endif() # Define our sources file(GLOB CV_SOURCES src/cv/*.cpp) @@ -25,7 +29,7 @@ file(GLOB DEBUG_SOURCES src/cv/debug/*.cpp) # Locate dependent packages FIND_PACKAGE(OpenCV REQUIRED) INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS}) - + FIND_PACKAGE(Lua 5.4 REQUIRED) INCLUDE_DIRECTORIES(${LUA_INCLUDE_DIR}) @@ -54,14 +58,27 @@ ENDIF() target_link_libraries(inkpath ${OpenCV_LIBRARIES}) -# Copy the script and manifest into the build artifact -file(GLOB PLUGIN_FILES "${CMAKE_CURRENT_SOURCE_DIR}/plugin/*") -FOREACH(FILE ${PLUGIN_FILES}) - file(COPY ${FILE} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) -ENDFOREACH() - # Finally, set an install target. -install(DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} DESTINATION ${INSTALL_DESTINATION}) +install( + DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} + DESTINATION ${CMAKE_INSTALL_PREFIX_PLUGIN} +) +# Copy plugin directory files to the install prefix +install( + DIRECTORY ${PLUGIN_DIR}/ + DESTINATION ${CMAKE_INSTALL_PREFIX_PLUGIN}/${PLUGIN_NAME} + FILES_MATCHING + PATTERN "*" +) +# Copy icon files to the install prefix for icons +if(CMAKE_INSTALL_PREFIX_ICONS) + install( + DIRECTORY ${PLUGIN_DIR}/ + DESTINATION ${CMAKE_INSTALL_PREFIX_ICONS} + FILES_MATCHING + PATTERN "*.svg" + ) +endif() # Also set up debugging target add_executable(inkpath-debug EXCLUDE_FROM_ALL ${CV_SOURCES} ${DEBUG_SOURCES}) diff --git a/PreLoad.cmake b/PreLoad.cmake index 9658c5e..aa80632 100644 --- a/PreLoad.cmake +++ b/PreLoad.cmake @@ -1,5 +1,25 @@ -IF (WIN32) - # Need to specify specific generator b/c building on MSYS2 MINGW64 - set (CMAKE_GENERATOR "MinGW Makefiles" CACHE INTERNAL "" FORCE) - message("generator is set to ${CMAKE_GENERATOR}") -ENDIF() \ No newline at end of file +if(NOT DEFINED CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type") +endif() + +if(WIN32) + set(CMAKE_GENERATOR "MinGW Makefiles" CACHE STRING "Default to MinGW cross compilation") + message("Force CMAKE_GENERATOR: ${CMAKE_GENERATOR}") + if(NOT DEFINED CMAKE_INSTALL_PREFIX) + set(CMAKE_INSTALL_PREFIX "$ENV{LOCALAPPDATA}/xournalpp/plugins" CACHE PATH "Default user Xournal++ plugins directory on Windows") + if(NOT DEFINED CMAKE_INSTALL_PREFIX_ICONS) + set(CMAKE_INSTALL_PREFIX_ICONS "$ENV{LOCALAPPDATA}/icons" CACHE PATH "Default user GTK icons directory on Windows") + endif() + endif() +else() + if(NOT DEFINED CMAKE_INSTALL_PREFIX) + set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/.config/xournalpp/plugins" CACHE PATH "Default user Xournal++ plugins directory on Linux") + if(NOT DEFINED CMAKE_INSTALL_PREFIX_ICONS) + set(CMAKE_INSTALL_PREFIX_ICONS "$ENV{HOME}/.local/share/icons" CACHE PATH "Default user GTK icons directory on Linux") + endif() + endif() +endif() + +message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") +message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}") +message(STATUS "CMAKE_INSTALL_PREFIX_ICONS: ${CMAKE_INSTALL_PREFIX_ICONS}") diff --git a/README.md b/README.md index cd2a381..854927d 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,12 @@ cmake .. make ``` +To install the plugin to the local `dist` directory instead of the system specific Xournal++ User directory: + +```sh +cmake -B build -S . -DCMAKE_INSTALL_PREFIX="dist" +``` + ### Arch ```BASH