Skip to content

Commit

Permalink
Merge pull request #26 from nomacs/master
Browse files Browse the repository at this point in the history
Add CMake
  • Loading branch information
roniemartinez authored Dec 21, 2018
2 parents 41a26b6 + a6b75ad commit 1ab22db
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ QPsdPlugin.pro.user
Release/*
Debug/*
Profile/*
build*
CMakeUserPaths.cmake
76 changes: 76 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
cmake_minimum_required(VERSION 3.5)

project(qpsd)

# load paths from the user file if exists
if (EXISTS ${CMAKE_SOURCE_DIR}/CMakeUserPaths.cmake)
include(${CMAKE_SOURCE_DIR}/CMakeUserPaths.cmake)

message(STATUS "using user paths...")
elseif(MSVC)
message(WARNING "Could not find CMakeUserPaths.cmake - please use this file to specify your install directories (see CMakeUserPathsGit.cmake)")
endif()

# locate qmake
if(NOT QT_QMAKE_EXECUTABLE)
find_program(QT_QMAKE_EXECUTABLE NAMES "qmake" "qmake-qt5" "qmake.exe")
endif()
if(NOT QT_QMAKE_EXECUTABLE)
message(FATAL_ERROR "you have to set the path to the Qt5 qmake executable in CMakeUserPaths.cmake")
else()
message(STATUS "QMake found: ${QT_QMAKE_EXECUTABLE}")
endif()

get_filename_component(QT_QMAKE_PATH ${QT_QMAKE_EXECUTABLE} PATH)

set(QT_ROOT ${QT_QMAKE_PATH}/)
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${QT_QMAKE_PATH}/../lib/cmake/Qt5)

find_package(Qt5 COMPONENTS Core Gui REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

file(GLOB LIBQPSD_SOURCES "*.cpp")
file(GLOB LIBQPSD_HEADERS "*.h")

SET(CMAKE_DEBUG_POSTFIX "d")

add_library(${PROJECT_NAME} MODULE ${LIBQPSD_SOURCES} ${LIBQPSD_HEADERS})
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Gui)

set_target_properties(${PROJECT_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR}/libs)
set_target_properties(${PROJECT_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_BINARY_DIR}/libs)
set_target_properties(${PROJECT_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_REALLYRELEASE ${CMAKE_CURRENT_BINARY_DIR}/libs)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/imageformats")

# install to qt plugins dir
execute_process(
COMMAND ${QT_QMAKE_EXECUTABLE} -query QT_INSTALL_PLUGINS
OUTPUT_VARIABLE QT_PLUGINS_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)

if (QT_PLUGINS_DIR)

# status
message(STATUS "")
message(STATUS "-----------------------------------------------------------------------------")
message(STATUS " ${PROJECT_NAME} configured")
message(STATUS " <https://github.com/Code-ReaQtor/libqpsd>")
message(STATUS " it will be installed to ${QT_PLUGINS_DIR}/imageformats")
message(STATUS "-----------------------------------------------------------------------------")

else ()
message(FATAL_ERROR "Qt5 plugin directory cannot be detected.")
endif ()

# Prefix with DESTDIR if available to allow packaging
if (ENV{DESTDIR} AND NOT ENV{DESTDIR} STREQUAL "")
set(plugins_dir "$ENV{DESTDIR}${QT_PLUGINS_DIR}")
else ()
set(plugins_dir "${QT_PLUGINS_DIR}")
endif ()

install(
TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION "${plugins_dir}/imageformats")
10 changes: 10 additions & 0 deletions CMakeUserPathsGit.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# If you want to use prefix paths with cmake, copy and rename this file to CMakeUserPaths.cmake
# Do not add this file to GIT!

IF (CMAKE_CL_64)

SET(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "C:/Qt/Qt5.11.1-x64/bin")
ELSE()

SET(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "C:/Qt/Qt5.11.1-x86/bin")
ENDIF()
38 changes: 38 additions & 0 deletions README-nomacs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Building libqpsd for nomacs

## Build libqpsd (Windows)

### Compile dependencies

- [Qt](https://www.qt.io/)

### Compile LibQPSD

- copy `CMakeUserPathsGit.cmake` and rename it to `CMakeUserPaths.cmake`
- add your library paths to the `${CMAKE_PREFIX_PATH}` in `CMakeUserPaths.cmake`
- Open CMake GUI
- set this folder to `where is the source code`
- choose a build folder (e.g. `build2017-x64`)
- Hit `Configure`then `Generate`
- Open the Project
- Compile the Solution (build Release and Debug)
- Build `INSTALL`
- You should now have a `qpsd.dll` in $YOUR_QT_PATH$/plugins/imageformats
- nomacs will automatically copy the plugins from there to it's build folder

## Build libqpsd (Ubuntu)

install dependencies
```bash
sudo apt-get install debhelper cdbs qt5-qmake qttools5-dev-tools qt5-default qttools5-dev libqt5svg5-dev qt5-image-formats-plugins cmake
```
cd to this directory, then configure the project:
```bash
mkdir build
cd build
cmake ..
```
and compile:
```bash
make
```

0 comments on commit 1ab22db

Please sign in to comment.