Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 945bf66

Browse filesBrowse files
authored
Merge pull request #107 from DavidLudwig/find_package-2
use CMake's find_package(...) to find GraphicsMagick
2 parents ac46974 + af0a9f1 commit 945bf66
Copy full SHA for 945bf66

File tree

2 files changed

+91
-17
lines changed
Filter options

2 files changed

+91
-17
lines changed

‎P0267_RefImpl/P0267_RefImpl/cairo/CMakeLists.txt

Copy file name to clipboardExpand all lines: P0267_RefImpl/P0267_RefImpl/cairo/CMakeLists.txt
+2-17Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.8)
33
project(io2d CXX)
44

55
find_package(Cairo REQUIRED)
6+
find_package(GraphicsMagick REQUIRED)
67

78
add_library(io2d_cairo
89
cairo_renderer-graphicsmagickinit.cpp
@@ -23,23 +24,7 @@ target_include_directories(io2d_cairo PUBLIC
2324

2425
target_compile_features(io2d_cairo PUBLIC cxx_std_17)
2526

26-
target_link_libraries(io2d_cairo PUBLIC io2d_core Cairo::Cairo)
27-
28-
if(MSVC)
29-
find_path(GRAPHICSMAGICK_INCLUDE_DIR magick/api.h)
30-
find_library(GRAPHICSMAGICK_LIB graphicsmagick)
31-
elseif(APPLE)
32-
find_path(GRAPHICSMAGICK_INCLUDE_DIR magick/api.h PATH_SUFFIXES GraphicsMagick)
33-
find_library(GRAPHICSMAGICK_LIB GraphicsMagick)
34-
else() # Linux
35-
find_path(GRAPHICSMAGICK_INCLUDE_DIR magick/api.h PATH_SUFFIXES GraphicsMagick)
36-
find_library(GRAPHICSMAGICK_LIB GraphicsMagick)
37-
endif()
38-
39-
target_include_directories(io2d_cairo SYSTEM PUBLIC ${GRAPHICSMAGICK_INCLUDE_DIR})
40-
41-
target_link_libraries(io2d_cairo PUBLIC ${GRAPHICSMAGICK_LIB})
42-
27+
target_link_libraries(io2d_cairo PUBLIC io2d_core Cairo::Cairo GraphicsMagick::GraphicsMagick)
4328

4429
install(
4530
TARGETS io2d_cairo EXPORT io2d_targets

‎cmake/FindGraphicsMagick.cmake

Copy file name to clipboard
+89Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#
2+
# FindGraphicsMagick.cmake
3+
#
4+
# When done, if GraphicsMagick is found, the following will be defined:
5+
#
6+
# Library Targets:
7+
# - GraphicsMagick::GraphicsMagick
8+
#
9+
# Global Variables:
10+
# - GRAPHICSMAGICK_FOUND
11+
#
12+
13+
# Use pkg-config, if available, to help find the library
14+
find_package(PkgConfig)
15+
pkg_check_modules(PC_GRAPHICSMAGICK GraphicsMagick)
16+
17+
# Find the header(s)
18+
find_path(GRAPHICSMAGICK_INCLUDE_DIRS
19+
NAMES magick/api.h
20+
HINTS ${PC_GRAPHICSMAGICK_INCLUDE_DIRS}
21+
)
22+
23+
# Find the pre-compiled binary. For Windows + MSVC, this will be its .lib file.
24+
find_library(GRAPHICSMAGICK_LIBRARIES
25+
GraphicsMagick
26+
HINTS ${PC_GRAPHICSMAGICK_LIBRARY_DIRS}
27+
)
28+
29+
# Search for base path of installation
30+
if (GRAPHICSMAGICK_INCLUDE_DIRS)
31+
set(_TMP_PATH ${GRAPHICSMAGICK_INCLUDE_DIRS})
32+
while(TRUE)
33+
get_filename_component(_TMP_PATH_PART ${_TMP_PATH} NAME)
34+
string(TOLOWER ${_TMP_PATH_PART} _TMP_PATH_PART)
35+
if (${_TMP_PATH_PART} STREQUAL "graphicsmagick" OR ${_TMP_PATH_PART} STREQUAL "include")
36+
get_filename_component(_TMP_PATH ${_TMP_PATH} DIRECTORY)
37+
continue()
38+
endif()
39+
if (NOT (${_TMP_PATH} STREQUAL ""))
40+
set(GRAPHICSMAGICK_PATH ${_TMP_PATH})
41+
endif()
42+
break()
43+
endwhile()
44+
endif()
45+
46+
# Look for a pre-compiled .dll file
47+
find_path(GRAPHICSMAGICK_DLL
48+
NAMES graphicsmagick.dll
49+
HINTS ${GRAPHICSMAGICK_PATH}
50+
PATH_SUFFIXES bin
51+
)
52+
53+
# Perform CMake Find-module stuff
54+
include(FindPackageHandleStandardArgs)
55+
find_package_handle_standard_args(GraphicsMagick
56+
REQUIRED_VARS GRAPHICSMAGICK_INCLUDE_DIRS GRAPHICSMAGICK_LIBRARIES
57+
)
58+
59+
# Create a library target
60+
if (GRAPHICSMAGICK_FOUND AND NOT TARGET GraphicsMagick::GraphicsMagick)
61+
if (GRAPHICSMAGICK_DLL)
62+
# Not using 'SHARED' when Cairo is available through a .dll can
63+
# cause build issues with MSVC, at least when trying to link against
64+
# a vcpkg-provided copy of "cairod".
65+
add_library(GraphicsMagick::GraphicsMagick SHARED IMPORTED)
66+
else()
67+
add_library(GraphicsMagick::GraphicsMagick UNKNOWN IMPORTED)
68+
endif()
69+
70+
set_target_properties(GraphicsMagick::GraphicsMagick PROPERTIES
71+
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
72+
INTERFACE_INCLUDE_DIRECTORIES ${GRAPHICSMAGICK_INCLUDE_DIRS}
73+
)
74+
75+
if (GRAPHICSMAGICK_DLL)
76+
# When using a .dll, the location of *both* the .dll file, and its
77+
# .lib, needs to be specified to CMake. The path to the .dll goes
78+
# into IMPORTED_LOCATION(_*), whereas the path to the .lib goes
79+
# into IMPORTED_IMPLIB(_*).
80+
set_target_properties(GraphicsMagick::GraphicsMagick PROPERTIES
81+
IMPORTED_LOCATION ${GRAPHICSMAGICK_DLL}
82+
IMPORTED_IMPLIB ${GRAPHICSMAGICK_LIBRARIES}
83+
)
84+
else()
85+
set_target_properties(GraphicsMagick::GraphicsMagick PROPERTIES
86+
IMPORTED_LOCATION ${GRAPHICSMAGICK_LIBRARIES}
87+
)
88+
endif()
89+
endif()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.