changeset 74:35ef15100de8

CMake: install pkg-config file, #440
author David Demelier <markand@malikania.fr>
date Sat, 26 Mar 2016 14:41:53 +0100
parents 8ee1178f1219
children f8160d515a76
files cmake/IrccdOptions.cmake cmake/IrccdVersion.cmake cmake/internal/irccd2.pc.in lib/CMakeLists.txt
diffstat 4 files changed, 77 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/cmake/IrccdOptions.cmake	Fri Mar 25 13:58:12 2016 +0100
+++ b/cmake/IrccdOptions.cmake	Sat Mar 26 14:41:53 2016 +0100
@@ -24,9 +24,10 @@
 # WITH_TESTS		Enable unit testing (default: off)
 # WITH_SYSTEMD		Install systemd service (default: off)
 # WITH_DOCS		Enable building of all documentation (default: on)
-# WITH_DOXYGEN	Enable internal irccd documentation (default: on)
-# WITH_HTML	Enable HTML documentation
+# WITH_DOXYGEN		Enable internal irccd documentation (default: on)
+# WITH_HTML		Enable HTML documentation
 # WITH_MAN		Install manpages (default: on, off for Windows)
+# WITH_PKGCONFIG	Install pkg-config files (default: on, off for Windows (except MinGW))
 # WITH_PLUGIN_<NAME>	Enable or disable the specified plugin (default: on)
 #
 # Note: the option() commands for WITH_PLUGIN_<name> variables are defined automatically from the IRCCD_PLUGINS
@@ -45,6 +46,7 @@
 # WITH_MANDIR		Path where to install manuals
 # WITH_CONFDIR		Path where to search configuration files
 # WITH_CACHEDIR		Path where to store temporary files
+# WITH_PKGCONFIGDIR	Path where to install pkg-config files
 #
 
 #
@@ -68,6 +70,13 @@
 	set(DEFAULT_SYSTEMD "No")
 endif ()
 
+# pkg-config is only relevant on UNIX or MinGW
+if (MINGW OR UNIX)
+	set(DEFAULT_PKGCONFIG "Yes")
+else ()
+	set(DEFAULT_PKGCONFIG "No")
+endif ()
+
 option(WITH_SSL "Enable SSL" On)
 option(WITH_JS "Enable embedded Duktape" On)
 option(WITH_TESTS "Enable unit testing" Off)
@@ -76,6 +85,7 @@
 option(WITH_HTML "Enable building of HTML documentation" On)
 option(WITH_DOXYGEN "Enable doxygen" Off)
 option(WITH_MAN "Install man pages" ${DEFAULT_MAN})
+option(WITH_PKGCONFIG "Enable pkg-config file" ${DEFAULT_PKGCONFIG})
 
 # Build options for all plugins.
 foreach (plugin ${IRCCD_PLUGINS})
@@ -99,6 +109,7 @@
 set(WITH_BINDIR "bin" CACHE STRING "Binary directory")
 set(WITH_MANDIR "share/man" CACHE STRING "Man directory")
 set(WITH_CONFDIR "etc" CACHE STRING "Configuration directory")
+set(WITH_PKGCONFIGDIR "lib/pkgconfig" CACHE STRING "Directory for pkg-config file")
 
 #
 # On Windows, we install the applcation like C:/Program Files/irccd so do not append irccd to the
--- a/cmake/IrccdVersion.cmake	Fri Mar 25 13:58:12 2016 +0100
+++ b/cmake/IrccdVersion.cmake	Sat Mar 26 14:41:53 2016 +0100
@@ -20,6 +20,7 @@
 set(IRCCD_VERSION_MAJOR "2")
 set(IRCCD_VERSION_MINOR "0")
 set(IRCCD_VERSION_PATCH "1")
+set(IRCCD_VERSION_SHLIB "2")
 set(IRCCD_VERSION "${IRCCD_VERSION_MAJOR}.${IRCCD_VERSION_MINOR}.${IRCCD_VERSION_PATCH}")
 
 #
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake/internal/irccd2.pc.in	Sat Mar 26 14:41:53 2016 +0100
@@ -0,0 +1,11 @@
+# pkg-config file for irccd @IRCCD_VERSION@
+prefix=@CMAKE_INSTALL_PREFIX@
+libdir=${prefix}/lib
+includedir=${prefix}/include
+
+Name: irccd
+Version: @IRCCD_VERSION@
+Description: IRC Client Daemon library
+URL: http://projects.malikania.fr/irccd
+Libs: -L${libdir} -lirccd2$<$<CONFIG:Debug>:d>
+Cflags: -I${includedir}
--- a/lib/CMakeLists.txt	Fri Mar 25 13:58:12 2016 +0100
+++ b/lib/CMakeLists.txt	Sat Mar 26 14:41:53 2016 +0100
@@ -1,8 +1,25 @@
+#
+# CMakeLists.txt -- CMake build system for irccd
+#
+# Copyright (c) 2013-2016 David Demelier <markand@malikania.fr>
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+
 project(lib)
 
 include(irccd/CMakeSources.cmake)
 
-# TMP
 add_library(libirccd ${HEADERS} ${SOURCES})
 
 target_include_directories(
@@ -20,6 +37,38 @@
 endif ()
 
 target_link_libraries(libirccd extern-duktape extern-ircclient extern-jansson ${LIBRARIES})
-set_target_properties(libirccd PROPERTIES PREFIX "")
+
+set_target_properties(
+	libirccd
+	PROPERTIES
+		PREFIX ""
+		OUTPUT_NAME_DEBUG libirccd2d
+		VERSION ${IRCCD_VERSION}
+		SOVERSION ${IRCCD_VERSION_SHLIB}
+)
+
+install(
+	TARGETS libirccd
+	RUNTIME DESTINATION bin
+	LIBRARY DESTINATION lib
+	ARCHIVE DESTINATION lib
+)
 
-# TODO: install with export stuff and all
+# pkg-config
+if (WITH_PKGCONFIG)
+	# Configure the pkg-config file.
+	configure_file(
+		${CMAKE_SOURCE_DIR}/cmake/internal/irccd2.pc.in
+		${CMAKE_BINARY_DIR}/irccd2.pc.tmp
+		@ONLY
+	)
+
+	# Adjust the library output name if debug.
+	file(
+		GENERATE
+		OUTPUT ${CMAKE_BINARY_DIR}/irccd2.pc
+		INPUT ${CMAKE_BINARY_DIR}/irccd2.pc.tmp
+	)
+
+	install(FILES ${CMAKE_BINARY_DIR}/irccd2.pc DESTINATION ${WITH_PKGCONFIGDIR})
+endif ()