Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cmake modernization #1

Merged
merged 3 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vscode
build/*
67 changes: 54 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
cmake_minimum_required(VERSION 3.3)
cmake_minimum_required(VERSION 3.13)

project(lunasvg VERSION 2.3.1 LANGUAGES CXX C)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_C_STANDARD 11)

# Default to hidden visibility for symbols
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)

option(BUILD_SHARED_LIBS "Builds as shared library" OFF)
option(LUNASVG_BUILD_EXAMPLES "Builds examples" OFF)

Expand All @@ -15,25 +20,61 @@ add_subdirectory(source)
add_subdirectory(3rdparty/software)
add_subdirectory(3rdparty/plutovg)

if(BUILD_SHARED_LIBS)
target_compile_definitions(lunasvg PUBLIC LUNASVG_SHARED)
target_compile_definitions(lunasvg PRIVATE LUNASVG_EXPORT)
set_target_properties(lunasvg
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)

add_library(lunasvg::lunasvg ALIAS lunasvg)

if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(lunasvg PUBLIC LUNASVG_STATIC_DEFINE)
endif()

if(LUNASVG_BUILD_EXAMPLES)
add_subdirectory(example)
endif()

set(LUNASVG_LIBDIR ${CMAKE_INSTALL_PREFIX}/lib)
set(LUNASVG_INCDIR ${CMAKE_INSTALL_PREFIX}/include)
#
# Installation
#
include(GNUInstallDirs)
install(
FILES
${CMAKE_CURRENT_SOURCE_DIR}/include/lunasvg.h
${CMAKE_CURRENT_BINARY_DIR}/include/lunasvg_export.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lunasvg
)
install(
TARGETS lunasvg
EXPORT lunasvg-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
seanharmer marked this conversation as resolved.
Show resolved Hide resolved
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(
EXPORT lunasvg-targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/lunasvg NAMESPACE lunasvg:: FILE lunasvgTargets.cmake
)

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(FILES
include/lunasvg.h
DESTINATION ${LUNASVG_INCDIR}
${CMAKE_CURRENT_BINARY_DIR}/lunasvgConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/lunasvgConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/lunasvg
)

install(TARGETS lunasvg
LIBRARY DESTINATION ${LUNASVG_LIBDIR}
ARCHIVE DESTINATION ${LUNASVG_LIBDIR}
INCLUDES DESTINATION ${LUNASVG_INCDIR}
)
export(EXPORT lunasvg-targets FILE ${CMAKE_CURRENT_BINARY_DIR}/lunasvgTargets.cmake NAMESPACE lunasvg::)
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: 1 addition & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.3)
cmake_minimum_required(VERSION 3.13)

set(CMAKE_CXX_STANDARD 14)

Expand Down
16 changes: 14 additions & 2 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
# Generate a standard header with export macros
include(GenerateExportHeader)
generate_export_header(lunasvg)

target_include_directories(lunasvg
PUBLIC
"${CMAKE_CURRENT_LIST_DIR}"
# When building a project that uses the lunasvg library,
# we need to look in the installed include directory
PUBLIC
$<INSTALL_INTERFACE:include>

# When building the lunasvg library we need to look in the
# build dir for the lunasvg_export.h header and in the source
# dir for other headers
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
)
11 changes: 2 additions & 9 deletions include/lunasvg.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,8 @@
#include <memory>
#include <string>

#if defined(_MSC_VER) && defined(LUNASVG_SHARED)
#ifdef LUNASVG_EXPORT
#define LUNASVG_API __declspec(dllexport)
#else
#define LUNASVG_API __declspec(dllimport)
#endif
#else
#define LUNASVG_API
#endif
#include <lunasvg_export.h>
#define LUNASVG_API LUNASVG_EXPORT

namespace lunasvg {

Expand Down