Skip to content

Commit

Permalink
Add cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
sammycage committed Aug 28, 2024
1 parent 6572077 commit 21aa9d9
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "plutovg"]
path = plutovg
url = https://github.com/sammycage/plutovg
108 changes: 108 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
cmake_minimum_required(VERSION 3.15)

set(LUNASVG_VERSION_MAJOR 3)
set(LUNASVG_VERSION_MINOR 0)
set(LUNASVG_VERSION_MICRO 0)

project(lunasvg LANGUAGES CXX VERSION ${LUNASVG_VERSION_MAJOR}.${LUNASVG_VERSION_MINOR}.${LUNASVG_VERSION_MICRO})

set(lunasvg_sources
source/lunasvg.cpp
source/graphics.cpp
source/svgelement.cpp
source/svggeometryelement.cpp
source/svglayoutstate.cpp
source/svgpaintelement.cpp
source/svgparser.cpp
source/svgproperty.cpp
source/svgrenderstate.cpp
source/svgtextelement.cpp
)

set(lunasvg_headers
include/lunasvg.h
source/graphics.h
source/svgelement.h
source/svggeometryelement.h
source/svglayoutstate.h
source/svgpaintelement.h
source/svgparserutils.h
source/svgproperty.h
source/svgrenderstate.h
source/svgtextelement.h
)

find_package(plutovg 0.0.1 QUIET)
if(NOT plutovg_FOUND)
add_subdirectory(plutovg)
endif()

add_library(lunasvg ${lunasvg_sources} ${lunasvg_headers})
add_library(lunasvg::lunasvg ALIAS lunasvg)

set_target_properties(lunasvg PROPERTIES
SOVERSION ${LUNASVG_VERSION_MAJOR}
CXX_VISIBILITY_PRESET hidden
CXX_STANDARD_REQUIRED ON
CXX_STANDARD 17
)

target_include_directories(lunasvg PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/source
)

target_include_directories(lunasvg PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/lunasvg>
)

target_link_libraries(lunasvg PRIVATE plutovg::plutovg)
target_compile_definitions(lunasvg PRIVATE LUNASVG_BUILD)
if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(lunasvg PUBLIC LUNASVG_BUILD_STATIC)
endif()

include(GNUInstallDirs)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/lunasvg.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lunasvg)

include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/lunasvgConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/lunasvgConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/lunasvg
)

write_basic_package_version_file(lunasvgConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)

install(TARGETS lunasvg
EXPORT lunasvgTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

install(EXPORT lunasvgTargets
FILE lunasvgTargets.cmake
NAMESPACE lunasvg::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/lunasvg
)

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/lunasvgConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/lunasvgConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/lunasvg
)

export(EXPORT lunasvgTargets
FILE ${CMAKE_CURRENT_BINARY_DIR}/lunasvgTargets.cmake
NAMESPACE lunasvg::
)

option(LUNASVG_BUILD_EXAMPLES "Build examples" ON)
if(LUNASVG_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
3 changes: 3 additions & 0 deletions cmake/lunasvgConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/lunasvgTargets.cmake")
2 changes: 2 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_executable(svg2png svg2png.cpp)
target_link_libraries(svg2png lunasvg)
1 change: 1 addition & 0 deletions plutovg
Submodule plutovg added at bbfbbc

0 comments on commit 21aa9d9

Please sign in to comment.