Skip to content

Commit

Permalink
FindRESVG: Modernize with targets
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdnyc committed Jan 8, 2020
1 parent 4ebda59 commit 6aa799c
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 57 deletions.
135 changes: 107 additions & 28 deletions cmake/Modules/FindRESVG.cmake
Original file line number Diff line number Diff line change
@@ -1,28 +1,107 @@
# - Try to find RESVG
# Once done this will define
# RESVG_FOUND - System has RESVG
# RESVG_INCLUDE_DIRS - The RESVG include directories
# RESVG_LIBRARIES - The libraries needed to use RESVG
find_path ( RESVG_INCLUDE_DIR ResvgQt.h
PATHS ${RESVGDIR}/include/resvg
$ENV{RESVGDIR}/include/resvg
$ENV{RESVGDIR}/include
/usr/include/resvg
/usr/include
/usr/local/include/resvg
/usr/local/include )

find_library ( RESVG_LIBRARY NAMES resvg
PATHS /usr/lib
/usr/local/lib
$ENV{RESVGDIR}
$ENV{RESVGDIR}/lib )

set ( RESVG_LIBRARIES ${RESVG_LIBRARY} )
set ( RESVG_INCLUDE_DIRS ${RESVG_INCLUDE_DIR} )

include ( FindPackageHandleStandardArgs )
# handle the QUIETLY and REQUIRED arguments and set RESVG_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args ( RESVG "Could NOT find RESVG, using Qt SVG parsing instead" RESVG_LIBRARY RESVG_INCLUDE_DIR )
mark_as_advanced( RESVG_LIBRARY RESVG_INCLUDE_DIR )
# vim: ts=2 sw=2
#[=======================================================================[.rst:
FindRESVG
---------
Try to find the shared-library build of resvg, the Rust SVG library
IMPORTED targets
^^^^^^^^^^^^^^^^
This module defines :prop_tgt:`IMPORTED` target ``RESVG::resvg`` when
the library and headers are found.
Result Variables
^^^^^^^^^^^^^^^^
This module defines the following variables:
::
RESVG_FOUND - Library and header files found
RESVG_INCLUDE_DIRS - Include directory path
RESVG_LIBRARIES - Link path to the library
RESVG_DEFINITIONS - Compiler switches (currently unused)
Backwards compatibility
^^^^^^^^^^^^^^^^^^^^^^^
For compatibility with previous versions of this module, uppercase names
for FFmpeg and for all components are also recognized, and all-uppercase
versions of the cache variables are also created.
Control variables
^^^^^^^^^^^^^^^^^
The following variables can be used to provide path hints to the module:
RESVGDIR - Set in the calling CMakeLists.txt or on the command line
ENV{RESVGDIR} - An environment variable in the cmake process context
Copyright (c) 2020, FeRD (Frank Dana) <[email protected]>
#]=======================================================================]
include(FindPackageHandleStandardArgs)

# CMake 3.4+ only: Convert relative paths to absolute
if(DEFINED RESVGDIR AND CMAKE_VERSION VERSION_GREATER 3.4)
get_filename_component(RESVGDIR "${RESVGDIR}" ABSOLUTE
BASE_DIR ${CMAKE_CURRENT_BINARY_DIR})
endif()

find_path(RESVG_INCLUDE_DIRS
ResvgQt.h
PATHS
${RESVGDIR}
${RESVGDIR}/include
$ENV{RESVGDIR}
$ENV{RESVGDIR}/include
/usr/include
/usr/local/include
PATH_SUFFIXES
resvg
capi/include
resvg/capi/include
)

find_library(RESVG_LIBRARIES
NAMES resvg
PATHS
${RESVGDIR}
${RESVGDIR}/lib
$ENV{RESVGDIR}
$ENV{RESVGDIR}/lib
/usr/lib
/usr/local/lib
PATH_SUFFIXES
resvg
target/release
resvg/target/release
)

if (RESVG_INCLUDE_DIRS AND RESVG_LIBRARIES)
set(RESVG_FOUND TRUE)
endif()
set(RESVG_LIBRARIES ${RESVG_LIBRARIES} CACHE STRING "The Resvg library link path")
set(RESVG_INCLUDE_DIRS ${RESVG_INCLUDE_DIRS} CACHE STRING "The Resvg include directories")
set(RESVG_DEFINITIONS "" CACHE STRING "The Resvg CFLAGS")

mark_as_advanced(RESVG_LIBRARIES RESVG_INCLUDE_DIRS RESVG_DEFINITIONS)

# Give a nice error message if some of the required vars are missing.
find_package_handle_standard_args(RESVG
"Could NOT find RESVG, using Qt SVG parsing instead"
RESVG_LIBRARIES RESVG_INCLUDE_DIRS )

# Export target
if(RESVG_FOUND AND NOT TARGET RESVG::resvg)
message(STATUS "Creating IMPORTED target RESVG::resvg")
add_library(RESVG::resvg UNKNOWN IMPORTED)

set_target_properties(RESVG::resvg PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${RESVG_INCLUDE_DIRS}")

set_property(TARGET RESVG::resvg APPEND PROPERTY
INTERFACE_COMPILE_DEFINITIONS "${RESVG_DEFINITIONS}")

set_property(TARGET RESVG::resvg APPEND PROPERTY
IMPORTED_LOCATION "${RESVG_LIBRARIES}")
endif()
39 changes: 21 additions & 18 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,6 @@ IF (ENABLE_BLACKMAGIC)
ENDIF (BLACKMAGIC_FOUND)
ENDIF (ENABLE_BLACKMAGIC)


################### RESVG #####################
# Find resvg library (used for rendering svg files)
FIND_PACKAGE(RESVG)

# Include resvg headers (optional SVG library)
if (RESVG_FOUND)
include_directories(${RESVG_INCLUDE_DIRS})

# define a global var (used in the C++)
add_definitions( -DUSE_RESVG=1 )
SET(CMAKE_SWIG_FLAGS "-DUSE_RESVG=1")
endif(RESVG_FOUND)

############### PROFILING #################
#set(PROFILER "/usr/lib/libprofiler.so.0.3.2")
#set(PROFILER "/usr/lib/libtcmalloc.so.4")
Expand Down Expand Up @@ -357,6 +343,27 @@ if (TARGET cppzmq)
target_link_libraries(openshot PUBLIC cppzmq)
endif()

################### RESVG #####################
# Migrate some legacy variable names
if(DEFINED RESVGDIR AND NOT DEFINED RESVG_ROOT)
set(RESVG_ROOT ${RESVGDIR})
endif()
if(DEFINED ENV{RESVGDIR} AND NOT DEFINED RESVG_ROOT)
set(RESVG_ROOT $ENV{RESVGDIR})
endif()

# Find resvg library (used for rendering svg files)
FIND_PACKAGE(RESVG)

# Include resvg headers (optional SVG library)
if (TARGET RESVG::resvg)
#include_directories(${RESVG_INCLUDE_DIRS})
target_link_libraries(openshot PUBLIC RESVG::resvg)

# define a global var (used in the C++)
add_definitions( -DUSE_RESVG=1 )
set(CMAKE_SWIG_FLAGS "-DUSE_RESVG=1")
endif()

############### LINK LIBRARY #################
# Link remaining dependency libraries
Expand All @@ -368,10 +375,6 @@ if(ImageMagick_FOUND)
target_link_libraries(openshot PUBLIC ${ImageMagick_LIBRARIES})
endif()

if(RESVG_FOUND)
target_link_libraries(openshot PUBLIC ${RESVG_LIBRARIES})
endif()

if(BLACKMAGIC_FOUND)
target_link_libraries(openshot PUBLIC ${BLACKMAGIC_LIBRARY_DIR})
endif()
Expand Down
12 changes: 1 addition & 11 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ENDIF (ImageMagick_FOUND)

################# LIBOPENSHOT-AUDIO ###################
# Find JUCE-based openshot Audio libraries
FIND_PACKAGE(OpenShotAudio 0.1.8 REQUIRED)
FIND_PACKAGE(OpenShotAudio 0.1.9 REQUIRED)

# Include Juce headers (needed for compile)
include_directories(${LIBOPENSHOT_AUDIO_INCLUDE_DIRS})
Expand All @@ -94,16 +94,6 @@ IF (ENABLE_BLACKMAGIC)
ENDIF (ENABLE_BLACKMAGIC)


################### RESVG #####################
# Find resvg library (used for rendering svg files)
FIND_PACKAGE(RESVG)

# Include resvg headers (optional SVG library)
if (RESVG_FOUND)
include_directories(${RESVG_INCLUDE_DIRS})
endif(RESVG_FOUND)


############### SET TEST SOURCE FILES #################
SET ( OPENSHOT_TEST_FILES
Cache_Tests.cpp
Expand Down

0 comments on commit 6aa799c

Please sign in to comment.