From eff2cdee645baf946b006121b5289e8948c41c5c Mon Sep 17 00:00:00 2001 From: Thomas Fischer Date: Fri, 29 Jan 2016 08:53:27 +0100 Subject: [PATCH 1/2] Creating and installing .cmake file Creating and installing a .cmake file that simplifies locating this library from within a project that uses CMake. To make use of this .cmake file, the .cmake file must be loaded in a CMakeLists.txt file, for example through find_package(Osmpbf REQUIRED) Then two variables will be available: OSMPBF_INCLUDE_DIRS OSMPBF_LIBRARIES The former variable can be used in a 'include_directories' statement, the latter one in a 'target_link_libraries' statement. --- src/CMakeLists.txt | 3 +++ src/OsmpbfConfig.cmake.in | 2 ++ 2 files changed, 5 insertions(+) create mode 100644 src/OsmpbfConfig.cmake.in diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4a2b9ac..9923de5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -17,3 +17,6 @@ SET(INCLUDE_INSTALL "include/osmpbf") SET(files ${CMAKE_SOURCE_DIR}/include/osmpbf/osmpbf.h ${CMAKE_BINARY_DIR}/src/osmformat.pb.h ${CMAKE_BINARY_DIR}/src/fileformat.pb.h) INSTALL(FILES ${files} DESTINATION ${INCLUDE_INSTALL}) install(TARGETS osmpbf LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) + +configure_file("OsmpbfConfig.cmake.in" "OsmpbfConfig.cmake" @ONLY) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/OsmpbfConfig.cmake" DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/Osmpbf/) diff --git a/src/OsmpbfConfig.cmake.in b/src/OsmpbfConfig.cmake.in new file mode 100644 index 0000000..e6b00ec --- /dev/null +++ b/src/OsmpbfConfig.cmake.in @@ -0,0 +1,2 @@ +set(OSMPBF_INCLUDE_DIRS "@CMAKE_INSTALL_PREFIX@/include/osmpbf") +set(OSMPBF_LIBRARIES "@CMAKE_INSTALL_PREFIX@/lib/libosmpbf.a") From bdd69a147a5bcdbf45b23959e1c1c15398c0229c Mon Sep 17 00:00:00 2001 From: Thomas Fischer Date: Fri, 29 Jan 2016 09:10:21 +0100 Subject: [PATCH 2/2] Creating and installing .cmake file through Makefile Similarly to previous commit eff2cdee645baf946b00, create and install a Osmpbf.cmake file that can be used by other CMake-based projects. In constrast to the previous commit, this commit here adds the .cmake file's creation to the Makefile, thus becomes a functional duplicate. --- src/Makefile | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Makefile b/src/Makefile index f2e053c..3590704 100644 --- a/src/Makefile +++ b/src/Makefile @@ -13,7 +13,7 @@ CXXFLAGS += -Wall -Wextra -pedantic -Wredundant-decls -Wdisabled-optimization -W .PHONY: clean install -all: libosmpbf.a libosmpbf.so ../include/osmpbf/fileformat.pb.h ../include/osmpbf/osmformat.pb.h +all: libosmpbf.a libosmpbf.so ../include/osmpbf/fileformat.pb.h ../include/osmpbf/osmformat.pb.h OsmpbfConfig.cmake libosmpbf.a: fileformat.pb.o osmformat.pb.o $(AR) -cr $@ fileformat.pb.o osmformat.pb.o @@ -28,6 +28,12 @@ libosmpbf.so: fileformat.pb.o osmformat.pb.o $(PROTOC) --proto_path=. --cpp_out=. $< cp -v $(subst .proto,.pb.h,$<) ../include/osmpbf/ +%: %.in + # The placeholder for the installation prefix is '@CMAKE_INSTALL_PREFIX@'. + # Do not change that, it would only make the CMakeLists.txt file which does + # the same job as below line more complex. + sed -e 's!@CMAKE_INSTALL_PREFIX@!'$(DESTDIR)$(PREFIX)'!g' <$< >$@ + install: install -m 755 -d $(DESTDIR)$(LIBDIR) install -m 644 libosmpbf.a $(DESTDIR)$(LIBDIR) @@ -38,7 +44,9 @@ install: install -m 644 ../include/osmpbf/osmpbf.h $(DESTDIR)$(PREFIX)/include/osmpbf install -m 644 ../include/osmpbf/fileformat.pb.h $(DESTDIR)$(PREFIX)/include/osmpbf install -m 644 ../include/osmpbf/osmformat.pb.h $(DESTDIR)$(PREFIX)/include/osmpbf + install -m 755 -d $(DESTDIR)$(PREFIX)/lib/cmake/Osmpbf + install -m 644 OsmpbfConfig.cmake $(DESTDIR)$(PREFIX)/lib/cmake/Osmpbf clean: - rm -f *.pb.h *.pb.cc *.pb.o libosmpbf.a + rm -f *.pb.h *.pb.cc *.pb.o libosmpbf.a OsmpbfConfig.cmake