xref: /freebsd/contrib/libcbor/src/CMakeLists.txt (revision a90b9d0159070121c221b966469c3e36d912bf82)
1set(SOURCES cbor.c allocators.c cbor/streaming.c cbor/internal/encoders.c cbor/internal/builder_callbacks.c cbor/internal/loaders.c cbor/internal/memory_utils.c cbor/internal/stack.c cbor/internal/unicode.c cbor/encoding.c cbor/serialization.c cbor/arrays.c cbor/common.c cbor/floats_ctrls.c cbor/bytestrings.c cbor/callbacks.c cbor/strings.c cbor/maps.c cbor/tags.c cbor/ints.c)
2
3include(JoinPaths)
4include(CheckFunctionExists)
5set(CMAKE_SKIP_BUILD_RPATH FALSE)
6
7if (NOT DEFINED CMAKE_MACOSX_RPATH)
8	set(CMAKE_MACOSX_RPATH 0)
9endif()
10
11add_library(cbor ${SOURCES})
12target_include_directories(cbor PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
13
14# Explicitly link math.h if necessary
15check_function_exists(ldexp LDEXP_AVAILABLE)
16if (NOT LDEXP_AVAILABLE)
17	target_link_libraries(cbor m)
18endif()
19
20include(GenerateExportHeader)
21generate_export_header(cbor EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/cbor/cbor_export.h)
22target_include_directories(cbor PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
23install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cbor/cbor_export.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cbor)
24
25if (NOT ${CBOR_VERSION_MAJOR} EQUAL 0)
26	MESSAGE(FATAL_ERROR "Change the shared library version scheme to reflect https://github.com/PJK/libcbor/issues/52.")
27endif()
28
29set_target_properties(cbor PROPERTIES
30		VERSION ${CBOR_VERSION}
31		MACHO_COMPATIBILITY_VERSION ${CBOR_VERSION_MAJOR}.${CBOR_VERSION_MINOR}.0
32		SOVERSION ${CBOR_VERSION_MAJOR}.${CBOR_VERSION_MINOR})
33
34join_paths(libdir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
35join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
36configure_file(libcbor.pc.in libcbor.pc @ONLY)
37
38# http://www.cmake.org/Wiki/CMake:Install_Commands
39install(TARGETS cbor
40	ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
41	LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
42	RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
43
44install(DIRECTORY cbor DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
45                FILES_MATCHING PATTERN "*.h")
46
47install(FILES cbor.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
48
49install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libcbor.pc"
50	DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
51
52include(CMakePackageConfigHelpers)
53configure_package_config_file(
54	libcborConfig.cmake.in
55	${CMAKE_CURRENT_BINARY_DIR}/libcborConfig.cmake
56  INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libcbor
57	PATH_VARS CMAKE_INSTALL_INCLUDEDIR
58)
59write_basic_package_version_file(
60	${CMAKE_CURRENT_BINARY_DIR}/libcborConfigVersion.cmake
61	VERSION ${CBOR_VERSION}
62  COMPATIBILITY SameMajorVersion
63)
64install(
65	FILES
66		${CMAKE_CURRENT_BINARY_DIR}/libcborConfig.cmake
67		${CMAKE_CURRENT_BINARY_DIR}/libcborConfigVersion.cmake
68	DESTINATION
69		${CMAKE_INSTALL_LIBDIR}/cmake/libcbor
70	)
71