|
| 1 | +# CMake minimum version |
| 2 | +cmake_minimum_required(VERSION 3.14) |
| 3 | + |
| 4 | +# Project name |
| 5 | +project(c-cote) |
| 6 | + |
| 7 | +# Project version |
| 8 | +set(COTE_VERSION_MAJOR 1) |
| 9 | +set(COTE_VERSION_MINOR 0) |
| 10 | +set(COTE_VERSION_PATCH 0) |
| 11 | + |
| 12 | +# Additional flags |
| 13 | +set(c_flags "${c_flags} -Os -ffunction-sections -Wall -fPIC") |
| 14 | +set(linker_flags "${linker_flags} -Wl,-gc-sections") |
| 15 | +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") |
| 16 | + |
| 17 | +# Definitions |
| 18 | +add_definitions(-DCOTE_EXPORT_SYMBOLS -DCOTE_API_VISIBILITY) |
| 19 | + |
| 20 | +# Output directories |
| 21 | +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build/lib) |
| 22 | +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build/bin) |
| 23 | + |
| 24 | +# CMake subdirectories |
| 25 | +if (NOT TARGET amp) |
| 26 | + if(EXISTS lib/amp) |
| 27 | + add_subdirectory(lib/amp) |
| 28 | + endif() |
| 29 | +endif() |
| 30 | +if (NOT TARGET axon) |
| 31 | + if(EXISTS lib/axon) |
| 32 | + add_subdirectory(lib/axon) |
| 33 | + endif() |
| 34 | +endif() |
| 35 | +if (NOT TARGET discover) |
| 36 | + if(EXISTS lib/discover) |
| 37 | + add_subdirectory(lib/discover) |
| 38 | + endif() |
| 39 | +endif() |
| 40 | +if(NOT TARGET cjson) |
| 41 | + if(EXISTS lib/cJSON) |
| 42 | + add_subdirectory(lib/cJSON) |
| 43 | + endif() |
| 44 | +endif() |
| 45 | + |
| 46 | +# List of sources |
| 47 | +file(GLOB_RECURSE src "src/*.c") |
| 48 | + |
| 49 | +# Add include directories |
| 50 | +include_directories(inc) |
| 51 | +if(EXISTS lib/amp) |
| 52 | + include_directories(lib/amp/inc) |
| 53 | +endif() |
| 54 | +if(EXISTS lib/axon) |
| 55 | + include_directories(lib/axon/inc) |
| 56 | +endif() |
| 57 | +if(EXISTS lib/discover) |
| 58 | + include_directories(lib/discover/inc) |
| 59 | +endif() |
| 60 | +if(EXISTS lib/cJSON) |
| 61 | + include_directories(lib/cJSON) |
| 62 | +endif() |
| 63 | + |
| 64 | +# Creation of the library |
| 65 | +add_library(cote SHARED ${src}) |
| 66 | + |
| 67 | +# Link the library with the wanted libraries |
| 68 | +target_link_libraries(cote discover axon amp cjson pthread rt) |
| 69 | + |
| 70 | +# Properties of the library |
| 71 | +set_target_properties(cote |
| 72 | + PROPERTIES |
| 73 | + SOVERSION "${COTE_VERSION_MAJOR}" |
| 74 | + VERSION "${COTE_VERSION_MAJOR}.${COTE_VERSION_MINOR}.${COTE_VERSION_PATCH}" |
| 75 | +) |
| 76 | + |
| 77 | +# Creation of the examples binaries |
| 78 | +option(ENABLE_COTE_EXAMPLES "Enable building cote examples" OFF) |
| 79 | +if(ENABLE_COTE_EXAMPLES) |
| 80 | + add_executable(monitor "examples/monitor/monitor.c") |
| 81 | + target_link_libraries(monitor cote) |
| 82 | + add_executable(publisher "examples/pubsub/publisher.c") |
| 83 | + target_link_libraries(publisher cote) |
| 84 | + add_executable(subscriber "examples/pubsub/subscriber.c") |
| 85 | + target_link_libraries(subscriber cote) |
| 86 | + add_executable(publisher_namespace1 "examples/pubsub_namespace/publisher_namespace1.c") |
| 87 | + target_link_libraries(publisher_namespace1 cote) |
| 88 | + add_executable(subscriber_namespace1 "examples/pubsub_namespace/subscriber_namespace1.c") |
| 89 | + target_link_libraries(subscriber_namespace1 cote) |
| 90 | + add_executable(publisher_topic1_topic2 "examples/pubsub_topics/publisher_topic1_topic2.c") |
| 91 | + target_link_libraries(publisher_topic1_topic2 cote) |
| 92 | + add_executable(subscriber_topic1_topic2 "examples/pubsub_topics/subscriber_topic1_topic2.c") |
| 93 | + target_link_libraries(subscriber_topic1_topic2 cote) |
| 94 | + add_executable(subscriber_topic1 "examples/pubsub_topics/subscriber_topic1.c") |
| 95 | + target_link_libraries(subscriber_topic1 cote) |
| 96 | + add_executable(subscriber_topic2 "examples/pubsub_topics/subscriber_topic2.c") |
| 97 | + target_link_libraries(subscriber_topic2 cote) |
| 98 | + add_executable(subscriber_topics "examples/pubsub_topics/subscriber_topics.c") |
| 99 | + target_link_libraries(subscriber_topics cote) |
| 100 | + add_executable(requester "examples/reqrep/requester.c") |
| 101 | + target_link_libraries(requester cote) |
| 102 | + add_executable(responder "examples/reqrep/responder.c") |
| 103 | + target_link_libraries(responder cote) |
| 104 | +endif() |
| 105 | + |
| 106 | +# Installation |
| 107 | +set(CMAKE_INSTALL_FULL_LIBDIR lib) |
| 108 | +set(CMAKE_INSTALL_FULL_BINDIR bin) |
| 109 | +set(CMAKE_INSTALL_FULL_INCLUDEDIR include) |
| 110 | +if(EXISTS lib/cJSON) |
| 111 | + install(FILES lib/cJSON/cJSON.h DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}") |
| 112 | + install(TARGETS cjson |
| 113 | + ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" |
| 114 | + LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" |
| 115 | + RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}" |
| 116 | + INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}" |
| 117 | + ) |
| 118 | +endif() |
| 119 | +if(EXISTS lib/amp) |
| 120 | + install(FILES lib/amp/inc/amp.h DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}") |
| 121 | + install(TARGETS amp |
| 122 | + ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" |
| 123 | + LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" |
| 124 | + RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}" |
| 125 | + INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}" |
| 126 | + ) |
| 127 | +endif() |
| 128 | +if(EXISTS lib/axon) |
| 129 | + install(FILES lib/axon/inc/axon.h DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}") |
| 130 | + install(TARGETS axon |
| 131 | + ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" |
| 132 | + LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" |
| 133 | + RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}" |
| 134 | + INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}" |
| 135 | + ) |
| 136 | +endif() |
| 137 | +if(EXISTS lib/discover) |
| 138 | + install(FILES lib/discover/inc/discover.h DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}") |
| 139 | + install(TARGETS discover |
| 140 | + ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" |
| 141 | + LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" |
| 142 | + RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}" |
| 143 | + INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}" |
| 144 | + ) |
| 145 | +endif() |
| 146 | +install(FILES inc/cote.h DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}") |
| 147 | +install(TARGETS cote |
| 148 | + ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" |
| 149 | + LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" |
| 150 | + RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}" |
| 151 | + INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}" |
| 152 | +) |
| 153 | +if(ENABLE_COTE_EXAMPLES) |
| 154 | + install(TARGETS monitor publisher subscriber publisher_namespace1 subscriber_namespace1 publisher_topic1_topic2 subscriber_topic1_topic2 subscriber_topic1 subscriber_topic2 subscriber_topics requester responder |
| 155 | + ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" |
| 156 | + LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}" |
| 157 | + RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}" |
| 158 | + INCLUDES DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}" |
| 159 | + ) |
| 160 | +endif() |
0 commit comments