-
Notifications
You must be signed in to change notification settings - Fork 363
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
Add CMake build script to the project #209
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
|
||
project(NanoSVG C) | ||
|
||
# CMake needs *.c files to do something useful | ||
configure_file(src/nanosvg.h ${CMAKE_CURRENT_BINARY_DIR}/nanosvg.c) | ||
configure_file(src/nanosvgrast.h ${CMAKE_CURRENT_BINARY_DIR}/nanosvgrast.c) | ||
|
||
add_library(nanosvg ${CMAKE_CURRENT_BINARY_DIR}/nanosvg.c) | ||
|
||
find_library(MATH_LIBRARY m) # Business as usual | ||
if(MATH_LIBRARY) | ||
target_link_libraries(nanosvg PUBLIC ${MATH_LIBRARY}) | ||
endif() | ||
|
||
target_include_directories(nanosvg PUBLIC $<INSTALL_INTERFACE:include/nanosvg>) | ||
target_compile_definitions(nanosvg PRIVATE NANOSVG_IMPLEMENTATION) | ||
|
||
# Same for nanosvgrast | ||
add_library(nanosvgrast ${CMAKE_CURRENT_BINARY_DIR}/nanosvgrast.c) | ||
target_link_libraries(nanosvgrast PUBLIC nanosvg) | ||
target_include_directories(nanosvgrast PRIVATE src) | ||
target_compile_definitions(nanosvgrast PRIVATE NANOSVGRAST_IMPLEMENTATION) | ||
|
||
# Installation and export: | ||
|
||
include(CMakePackageConfigHelpers) | ||
|
||
write_basic_package_version_file( | ||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" | ||
VERSION 1.0 | ||
COMPATIBILITY AnyNewerVersion | ||
) | ||
|
||
install(TARGETS nanosvg nanosvgrast | ||
EXPORT ${PROJECT_NAME}Targets | ||
) | ||
|
||
export(EXPORT ${PROJECT_NAME}Targets | ||
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake" | ||
NAMESPACE ${PROJECT_NAME}:: | ||
) | ||
|
||
set(ConfigPackageLocation lib/cmake/${PROJECT_NAME}) | ||
|
||
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in | ||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" | ||
INSTALL_DESTINATION ${ConfigPackageLocation} | ||
NO_CHECK_REQUIRED_COMPONENTS_MACRO | ||
) | ||
|
||
install( | ||
FILES | ||
src/nanosvg.h | ||
src/nanosvgrast.h | ||
DESTINATION | ||
include/nanosvg | ||
) | ||
|
||
install(EXPORT ${PROJECT_NAME}Targets | ||
FILE | ||
${PROJECT_NAME}Targets.cmake | ||
NAMESPACE | ||
${PROJECT_NAME}:: | ||
DESTINATION | ||
${ConfigPackageLocation} | ||
) | ||
|
||
install( | ||
FILES | ||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" | ||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" | ||
DESTINATION | ||
${ConfigPackageLocation} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@PACKAGE_INIT@ | ||
|
||
if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/NanoSVGTargets.cmake) | ||
include("${CMAKE_CURRENT_LIST_DIR}/NanoSVGTargets.cmake") | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this change, it's no longer possible to include
nanosvgrast.h
after includingnanosvg.h
as it leads to duplicate symbols:and dozens more errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That include should not be there, my bad reviewing it. @tamasmeszaros would you mind making another PR fixing that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I would not remove the include but rather extend the include guards for the whole files for nanosvg.h and nanosvgrast.h.
See #215
I've also added a bonus PR #216 with a CMake build script for the examples. Use it if you like it :)