Skip to content

Commit 21815fe

Browse files
committed
FindRESVG: Modernize with targets
1 parent 0b4885b commit 21815fe

File tree

3 files changed

+128
-56
lines changed

3 files changed

+128
-56
lines changed

cmake/Modules/FindRESVG.cmake

Lines changed: 107 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,107 @@
1-
# - Try to find RESVG
2-
# Once done this will define
3-
# RESVG_FOUND - System has RESVG
4-
# RESVG_INCLUDE_DIRS - The RESVG include directories
5-
# RESVG_LIBRARIES - The libraries needed to use RESVG
6-
find_path ( RESVG_INCLUDE_DIR ResvgQt.h
7-
PATHS ${RESVGDIR}/include/resvg
8-
$ENV{RESVGDIR}/include/resvg
9-
$ENV{RESVGDIR}/include
10-
/usr/include/resvg
11-
/usr/include
12-
/usr/local/include/resvg
13-
/usr/local/include )
14-
15-
find_library ( RESVG_LIBRARY NAMES resvg
16-
PATHS /usr/lib
17-
/usr/local/lib
18-
$ENV{RESVGDIR}
19-
$ENV{RESVGDIR}/lib )
20-
21-
set ( RESVG_LIBRARIES ${RESVG_LIBRARY} )
22-
set ( RESVG_INCLUDE_DIRS ${RESVG_INCLUDE_DIR} )
23-
24-
include ( FindPackageHandleStandardArgs )
25-
# handle the QUIETLY and REQUIRED arguments and set RESVG_FOUND to TRUE
26-
# if all listed variables are TRUE
27-
find_package_handle_standard_args ( RESVG "Could NOT find RESVG, using Qt SVG parsing instead" RESVG_LIBRARY RESVG_INCLUDE_DIR )
28-
mark_as_advanced( RESVG_LIBRARY RESVG_INCLUDE_DIR )
1+
# vim: ts=2 sw=2
2+
#[=======================================================================[.rst:
3+
FindRESVG
4+
---------
5+
Try to find the shared-library build of resvg, the Rust SVG library
6+
7+
IMPORTED targets
8+
^^^^^^^^^^^^^^^^
9+
10+
This module defines :prop_tgt:`IMPORTED` target ``RESVG::resvg`` when
11+
the library and headers are found.
12+
13+
Result Variables
14+
^^^^^^^^^^^^^^^^
15+
16+
This module defines the following variables:
17+
18+
::
19+
20+
RESVG_FOUND - Library and header files found
21+
RESVG_INCLUDE_DIRS - Include directory path
22+
RESVG_LIBRARIES - Link path to the library
23+
RESVG_DEFINITIONS - Compiler switches (currently unused)
24+
25+
Backwards compatibility
26+
^^^^^^^^^^^^^^^^^^^^^^^
27+
28+
For compatibility with previous versions of this module, uppercase names
29+
for FFmpeg and for all components are also recognized, and all-uppercase
30+
versions of the cache variables are also created.
31+
32+
Control variables
33+
^^^^^^^^^^^^^^^^^
34+
35+
The following variables can be used to provide path hints to the module:
36+
37+
RESVGDIR - Set in the calling CMakeLists.txt or on the command line
38+
ENV{RESVGDIR} - An environment variable in the cmake process context
39+
40+
Copyright (c) 2020, FeRD (Frank Dana) <[email protected]>
41+
#]=======================================================================]
42+
include(FindPackageHandleStandardArgs)
43+
44+
# CMake 3.4+ only: Convert relative paths to absolute
45+
if(DEFINED RESVGDIR AND CMAKE_VERSION VERSION_GREATER 3.4)
46+
get_filename_component(RESVGDIR "${RESVGDIR}" ABSOLUTE
47+
BASE_DIR ${CMAKE_CURRENT_BINARY_DIR})
48+
endif()
49+
50+
find_path(RESVG_INCLUDE_DIRS
51+
ResvgQt.h
52+
PATHS
53+
${RESVGDIR}
54+
${RESVGDIR}/include
55+
$ENV{RESVGDIR}
56+
$ENV{RESVGDIR}/include
57+
/usr/include
58+
/usr/local/include
59+
PATH_SUFFIXES
60+
resvg
61+
capi/include
62+
resvg/capi/include
63+
)
64+
65+
find_library(RESVG_LIBRARIES
66+
NAMES resvg
67+
PATHS
68+
${RESVGDIR}
69+
${RESVGDIR}/lib
70+
$ENV{RESVGDIR}
71+
$ENV{RESVGDIR}/lib
72+
/usr/lib
73+
/usr/local/lib
74+
PATH_SUFFIXES
75+
resvg
76+
target/release
77+
resvg/target/release
78+
)
79+
80+
if (RESVG_INCLUDE_DIRS AND RESVG_LIBRARIES)
81+
set(RESVG_FOUND TRUE)
82+
endif()
83+
set(RESVG_LIBRARIES ${RESVG_LIBRARIES} CACHE STRING "The Resvg library link path")
84+
set(RESVG_INCLUDE_DIRS ${RESVG_INCLUDE_DIRS} CACHE STRING "The Resvg include directories")
85+
set(RESVG_DEFINITIONS "" CACHE STRING "The Resvg CFLAGS")
86+
87+
mark_as_advanced(RESVG_LIBRARIES RESVG_INCLUDE_DIRS RESVG_DEFINITIONS)
88+
89+
# Give a nice error message if some of the required vars are missing.
90+
find_package_handle_standard_args(RESVG
91+
"Could NOT find RESVG, using Qt SVG parsing instead"
92+
RESVG_LIBRARIES RESVG_INCLUDE_DIRS )
93+
94+
# Export target
95+
if(RESVG_FOUND AND NOT TARGET RESVG::resvg)
96+
message(STATUS "Creating IMPORTED target RESVG::resvg")
97+
add_library(RESVG::resvg UNKNOWN IMPORTED)
98+
99+
set_target_properties(RESVG::resvg PROPERTIES
100+
INTERFACE_INCLUDE_DIRECTORIES "${RESVG_INCLUDE_DIRS}")
101+
102+
set_property(TARGET RESVG::resvg APPEND PROPERTY
103+
INTERFACE_COMPILE_DEFINITIONS "${RESVG_DEFINITIONS}")
104+
105+
set_property(TARGET RESVG::resvg APPEND PROPERTY
106+
IMPORTED_LOCATION "${RESVG_LIBRARIES}")
107+
endif()

src/CMakeLists.txt

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,6 @@ IF (ENABLE_BLACKMAGIC)
100100
ENDIF (BLACKMAGIC_FOUND)
101101
ENDIF (ENABLE_BLACKMAGIC)
102102

103-
104-
################### RESVG #####################
105-
# Find resvg library (used for rendering svg files)
106-
FIND_PACKAGE(RESVG)
107-
108-
# Include resvg headers (optional SVG library)
109-
if (RESVG_FOUND)
110-
include_directories(${RESVG_INCLUDE_DIRS})
111-
112-
# define a global var (used in the C++)
113-
add_definitions( -DUSE_RESVG=1 )
114-
SET(CMAKE_SWIG_FLAGS "-DUSE_RESVG=1")
115-
endif(RESVG_FOUND)
116-
117103
############### PROFILING #################
118104
#set(PROFILER "/usr/lib/libprofiler.so.0.3.2")
119105
#set(PROFILER "/usr/lib/libtcmalloc.so.4")
@@ -357,6 +343,27 @@ if (TARGET cppzmq)
357343
target_link_libraries(openshot PUBLIC cppzmq)
358344
endif()
359345

346+
################### RESVG #####################
347+
# Migrate some legacy variable names
348+
if(DEFINED RESVGDIR AND NOT DEFINED RESVG_ROOT)
349+
set(RESVG_ROOT ${RESVGDIR})
350+
endif()
351+
if(DEFINED ENV{RESVGDIR} AND NOT DEFINED RESVG_ROOT)
352+
set(RESVG_ROOT $ENV{RESVGDIR})
353+
endif()
354+
355+
# Find resvg library (used for rendering svg files)
356+
FIND_PACKAGE(RESVG)
357+
358+
# Include resvg headers (optional SVG library)
359+
if (TARGET RESVG::resvg)
360+
#include_directories(${RESVG_INCLUDE_DIRS})
361+
target_link_libraries(openshot PUBLIC RESVG::resvg)
362+
363+
# define a global var (used in the C++)
364+
add_definitions( -DUSE_RESVG=1 )
365+
set(CMAKE_SWIG_FLAGS "-DUSE_RESVG=1")
366+
endif()
360367

361368
############### LINK LIBRARY #################
362369
# Link remaining dependency libraries
@@ -368,10 +375,6 @@ if(ImageMagick_FOUND)
368375
target_link_libraries(openshot PUBLIC ${ImageMagick_LIBRARIES})
369376
endif()
370377

371-
if(RESVG_FOUND)
372-
target_link_libraries(openshot PUBLIC ${RESVG_LIBRARIES})
373-
endif()
374-
375378
if(BLACKMAGIC_FOUND)
376379
target_link_libraries(openshot PUBLIC ${BLACKMAGIC_LIBRARY_DIR})
377380
endif()

tests/CMakeLists.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,6 @@ IF (ENABLE_BLACKMAGIC)
9494
ENDIF (ENABLE_BLACKMAGIC)
9595

9696

97-
################### RESVG #####################
98-
# Find resvg library (used for rendering svg files)
99-
FIND_PACKAGE(RESVG)
100-
101-
# Include resvg headers (optional SVG library)
102-
if (RESVG_FOUND)
103-
include_directories(${RESVG_INCLUDE_DIRS})
104-
endif(RESVG_FOUND)
105-
106-
10797
############### SET TEST SOURCE FILES #################
10898
SET ( OPENSHOT_TEST_FILES
10999
Cache_Tests.cpp

0 commit comments

Comments
 (0)