view CMakeLists.txt @ 26:767b7d68b88d

misc: added signature for changeset a70dbbce88eb
author David Demelier <markand@malikania.fr>
date Mon, 28 Mar 2022 21:45:07 +0200
parents 887a8fd73d1e
children 4da5819148c6
line wrap: on
line source

#
# CMakeLists.txt -- basic CMake build for libunicode
#
# Copyright (c) 2013-2022 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.
#

cmake_minimum_required(VERSION 3.20)
project(
	libunicode
	VERSION "1.0.0"
	DESCRIPTION "UTF-8 to UTF-32 conversions and various operations"
	HOMEPAGE_URL "http://projects.malikania.fr/libunicode"
	LANGUAGES C
)

include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

add_library(libunicode-static STATIC unicode.c unicode.h)
target_include_directories(libunicode-static PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
install(
	TARGETS libunicode-static
	EXPORT unicode-targets
	ARCHIVE DESTINATION lib
)

if (NOT CMAKE_C_COMPILER_ID MATCHES "MSVC" OR NOT BUILD_SHARED_LIBS)
	set_target_properties(libunicode-static PROPERTIES OUTPUT_NAME unicode)
else ()
	set_target_properties(libunicode-static PROPERTIES OUTPUT_NAME unicode-static)
endif ()

if (BUILD_SHARED_LIBS)
	add_library(libunicode-shared SHARED unicode.c unicode.h unicode.def)
	target_include_directories(libunicode-shared PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
	set_target_properties(
		libunicode-shared
		PROPERTIES
			OUTPUT_NAME unicode
			VERSION ${PROJECT_VERSION}
			SOVERSION ${PROJECT_VERSION_MAJOR}
	)
	install(
		TARGETS libunicode-shared
		EXPORT unicode-targets
		ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
		LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
		RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
	)
endif ()

configure_file(
	${PROJECT_SOURCE_DIR}/unicode.pc.in
	${PROJECT_BINARY_DIR}/unicode.pc
	@ONLY
)

write_basic_package_version_file(
	${PROJECT_BINARY_DIR}/unicode-config-version.cmake
	VERSION ${PROJECT_VERSION}
	COMPATIBILITY SameMajorVersion
)

install(FILES ${PROJECT_SOURCE_DIR}/unicode.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES ${PROJECT_BINARY_DIR}/unicode.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(FILES ${PROJECT_SOURCE_DIR}/libunicode.3 DESTINATION ${CMAKE_INSTALL_MANDIR}/man3)
install(
	EXPORT unicode-targets
	FILE unicode-targets.cmake
	NAMESPACE unicode::
	DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/unicode
)
install(
	FILES
		${PROJECT_BINARY_DIR}/unicode-config-version.cmake
		${PROJECT_SOURCE_DIR}/unicode-config.cmake
	DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/unicode
)