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

Development package files #159

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*~
/build/
a.out
test-core
test-core-int64
70 changes: 70 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
cmake_minimum_required(VERSION 3.16)
project(picojson
VERSION 1.3.0
LANGUAGES CXX
)

include(GNUInstallDirs)

option(PKGCONFIG_RELOCATABLE "Create a pkgconfig file with relocatable path" OFF)
set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}"
CACHE PATH "Location of header files"
)

add_library(picojson INTERFACE)
add_library(picojson::picojson ALIAS picojson)
target_include_directories(picojson INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

install(FILES picojson.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/"
)

if(NOT WIN32)
# Install pkg-config file
if(PKGCONFIG_RELOCATABLE)
set(prefix "\${pcfiledir}/../..")
set(includedir "\${prefix}/include")
else()
set(prefix "${CMAKE_INSTALL_PREFIX}")
set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
endif()
configure_file(picojson.pc.in
"${CMAKE_CURRENT_BINARY_DIR}/picojson.pc"
NEWLINE_STYLE UNIX
@ONLY
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/picojson.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
)
endif()

install(TARGETS picojson EXPORT picojson-targets
INCLUDES DESTINATION include
)

set(config_package_location ${CMAKE_INSTALL_LIBDIR}/cmake/picojson)
install(EXPORT picojson-targets
FILE picojson-targets.cmake
NAMESPACE picojson::
DESTINATION ${config_package_location}
)

include(CMakePackageConfigHelpers)
configure_package_config_file(picojson-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/picojson-config.cmake
INSTALL_DESTINATION ${config_package_location}
PATH_VARS INCLUDE_INSTALL_DIR
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/picojson-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
ARCH_INDEPENDENT
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/picojson-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/picojson-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/picojson
)
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
prefix=/usr/local
includedir=$(prefix)/include
libdir=$(prefix)/lib
ifdef pkgconfig_relocatable
CMAKE_EXTRA_ARGS=-DPKGCONFIG_RELOCATABLE=TRUE
endif

check: test

Expand All @@ -14,14 +18,20 @@ test-core-int64: picojson.h test.cc picotest/picotest.c picotest/picotest.h
$(CXX) -Wall -DPICOJSON_USE_INT64 test.cc picotest/picotest.c -o $@

clean:
rm -fr build
rm -f test-core test-core-int64

install:
install -d $(DESTDIR)$(includedir)
install -p -m 0644 picojson.h $(DESTDIR)$(includedir)
mkdir -p build
cmake -DCMAKE_INSTALL_PREFIX=$(prefix) -DCMAKE_INSTALL_INCLUDEDIR=$(includedir) $(CMAKE_EXTRA_ARGS) -S . -B build
cmake --build build --target install

uninstall:
rm -f $(DESTDIR)$(includedir)/picojson.h
rm -f $(DESTDIR)$(libdir)/pkgconfig/picojson.pc
rm -f $(DESTDIR)$(libdir)/cmake/picojson/picojson-config.cmake
rm -f $(DESTDIR)$(libdir)/cmake/picojson/picojson-config-version.cmake
rm -f $(DESTDIR)$(libdir)/cmake/picojson/picojson-targets.cmake

clang-format: picojson.h examples/github-issues.cc examples/iostream.cc examples/streaming.cc
clang-format -i $?
Expand Down
5 changes: 5 additions & 0 deletions picojson-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/picojson-targets.cmake")

check_required_components(picojson)
7 changes: 7 additions & 0 deletions picojson.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
prefix=@prefix@
includedir=@includedir@

Name: picojson
Description: Tiny JSON parser / serializer for C++
Version: @version@
Cflags: -I${includedir}