|
2 | 2 | #
|
3 | 3 | # SPDX-License-Identifier: BSD-3-Clause
|
4 | 4 |
|
5 |
| -cmake_minimum_required(VERSION 3.5) |
6 |
| -project(binsparse-rc) |
| 5 | +cmake_minimum_required(VERSION 3.20) |
| 6 | +project(binsparse VERSION 1.0.0) |
7 | 7 |
|
8 | 8 | cmake_policy(SET CMP0079 NEW)
|
9 | 9 |
|
10 | 10 | set(CMAKE_C_STANDARD 11)
|
11 |
| - |
12 | 11 | set(CMAKE_CXX_STANDARD 20)
|
13 |
| - |
14 | 12 | set(CMAKE_C_FLAGS "-O3 -march=native")
|
15 | 13 |
|
16 |
| -add_library(binsparse-rc STATIC) |
| 14 | +include(GNUInstallDirs) |
| 15 | + |
| 16 | +add_library(binsparse STATIC) |
17 | 17 |
|
18 | 18 | add_subdirectory(include)
|
19 | 19 | add_subdirectory(src)
|
20 | 20 |
|
21 | 21 | # NOTE: For now, both HDF5 and cJSON are `PUBLIC`, meaning that anything that
|
22 |
| -# depends on `binsparse-rc` will also link/include HDF5 and cJSON. We can change |
23 |
| -# these to `PRIVATE` to use them only when building binsparse-rc. |
| 22 | +# depends on `binsparse` will also link/include HDF5 and cJSON. We can change |
| 23 | +# these to `PRIVATE` to use them only when building binsparse. |
24 | 24 |
|
25 | 25 | find_package(HDF5 REQUIRED COMPONENTS C)
|
26 |
| -target_link_libraries(binsparse-rc PUBLIC ${HDF5_C_LIBRARIES}) |
27 |
| -target_include_directories(binsparse-rc PUBLIC . ${HDF5_INCLUDE_DIRS}) |
| 26 | +target_link_libraries(binsparse PUBLIC ${HDF5_C_LIBRARIES}) |
28 | 27 |
|
29 | 28 | include(FetchContent)
|
30 | 29 | FetchContent_Declare(
|
31 | 30 | cJSON
|
32 |
| - GIT_REPOSITORY https://github.com/DaveGamble/cJSON.git |
33 |
| - GIT_TAG v1.7.17 |
| 31 | + # GIT_REPOSITORY https://github.com/DaveGamble/cJSON.git |
| 32 | + GIT_REPOSITORY https://github.com/p1k0chu/cJSON.git |
| 33 | + GIT_TAG 887642c0a93bd8a6616bf90daacac0ea7d4b095e |
34 | 34 | )
|
35 | 35 | FetchContent_MakeAvailable(cJSON)
|
36 | 36 |
|
37 | 37 | configure_file(${cJSON_SOURCE_DIR}/cJSON.h ${CMAKE_BINARY_DIR}/include/cJSON/cJSON.h)
|
38 |
| -target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_BINARY_DIR}/include) |
39 | 38 | target_link_libraries(${PROJECT_NAME} PUBLIC cjson)
|
40 | 39 |
|
| 40 | +# Set up include directories properly for both build and install |
| 41 | +target_include_directories(${PROJECT_NAME} |
| 42 | + PUBLIC |
| 43 | + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> |
| 44 | + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
| 45 | + $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include> |
| 46 | + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> |
| 47 | + ${HDF5_INCLUDE_DIRS}) |
| 48 | + |
41 | 49 | if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
42 | 50 | add_subdirectory(examples)
|
43 | 51 | add_subdirectory(test)
|
44 | 52 | endif()
|
| 53 | + |
| 54 | +# Installation rules - these are always needed when the library is built |
| 55 | +install(TARGETS binsparse |
| 56 | + EXPORT binsparse-targets |
| 57 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 58 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 59 | + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
| 60 | + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) |
| 61 | + |
| 62 | +# Install headers |
| 63 | +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/binsparse |
| 64 | + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 65 | + FILES_MATCHING PATTERN "*.h" |
| 66 | + PATTERN "*.hpp") |
| 67 | + |
| 68 | +# Export targets |
| 69 | +install(EXPORT binsparse-targets |
| 70 | + FILE binsparse-targets.cmake |
| 71 | + NAMESPACE binsparse:: |
| 72 | + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/binsparse) |
| 73 | + |
| 74 | +# Create and install package config files |
| 75 | +include(CMakePackageConfigHelpers) |
| 76 | +write_basic_package_version_file( |
| 77 | + "${CMAKE_CURRENT_BINARY_DIR}/binsparse-config-version.cmake" |
| 78 | + VERSION ${PROJECT_VERSION} |
| 79 | + COMPATIBILITY SameMajorVersion) |
| 80 | + |
| 81 | +configure_package_config_file( |
| 82 | + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/binsparse-config.cmake.in" |
| 83 | + "${CMAKE_CURRENT_BINARY_DIR}/binsparse-config.cmake" |
| 84 | + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/binsparse) |
| 85 | + |
| 86 | +install(FILES |
| 87 | + "${CMAKE_CURRENT_BINARY_DIR}/binsparse-config.cmake" |
| 88 | + "${CMAKE_CURRENT_BINARY_DIR}/binsparse-config-version.cmake" |
| 89 | + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/binsparse) |
0 commit comments