Marc Kupietz | ed0bfcf | 2021-03-14 14:56:15 +0100 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 3.9) |
Marc Kupietz | fa73154 | 2024-11-23 12:35:14 +0100 | [diff] [blame] | 2 | project(collocatordb VERSION 1.4.0 DESCRIPTION "Storing and retrieving collocation counts based on RocksDB") |
Marc Kupietz | 673bd81 | 2021-03-14 17:27:44 +0100 | [diff] [blame] | 3 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fno-rtti -std=c++11 -std=gnu++11") |
Marc Kupietz | ed0bfcf | 2021-03-14 14:56:15 +0100 | [diff] [blame] | 4 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g") |
| 5 | |
| 6 | include(GNUInstallDirs) |
Marc Kupietz | 15f56e7 | 2021-03-15 14:58:13 +0100 | [diff] [blame] | 7 | |
| 8 | # the RPATH to be used when installing, but only if it's not a system directory |
| 9 | list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir) |
| 10 | if("${isSystemDir}" STREQUAL "-1") |
| 11 | set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") |
| 12 | endif("${isSystemDir}" STREQUAL "-1") |
| 13 | |
Marc Kupietz | 6208fd7 | 2024-11-15 15:46:19 +0100 | [diff] [blame] | 14 | configure_file(src/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY) |
| 15 | include_directories(/usr/local/include /opt/homebrew/include build) |
Marc Kupietz | 4422923 | 2024-08-05 15:00:20 +0200 | [diff] [blame] | 16 | link_directories(/usr/local/lib64 /usr/local/lib /usr/lib64 /usr/lib /opt/homebrew/lib) |
| 17 | if (1 AND APPLE) |
| 18 | message("MacOS deteted") |
| 19 | set(LIBRT "") |
| 20 | find_library(ROCKSDB NAMES librocksdb.a) |
| 21 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flat_namespace") |
| 22 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -flat_namespace") |
| 23 | else() |
| 24 | set(LIBRT "rt") |
| 25 | find_library(ROCKSDB NAMES librocksdb.so.5.11) |
| 26 | endif() |
Marc Kupietz | 1b09e4d | 2021-03-14 15:20:19 +0100 | [diff] [blame] | 27 | find_library(ROCKSDB_STATIC librocksdb.a) |
| 28 | |
Marc Kupietz | 6208fd7 | 2024-11-15 15:46:19 +0100 | [diff] [blame] | 29 | get_cmake_property(_variableNames VARIABLES) |
| 30 | list (SORT _variableNames) |
| 31 | foreach (_variableName ${_variableNames}) |
| 32 | message(STATUS "${_variableName}=${${_variableName}}") |
| 33 | endforeach() |
| 34 | |
Marc Kupietz | ed0bfcf | 2021-03-14 14:56:15 +0100 | [diff] [blame] | 35 | enable_testing() |
| 36 | add_library(collocatordb SHARED src/collocatordb.cc) |
Marc Kupietz | 4422923 | 2024-08-05 15:00:20 +0200 | [diff] [blame] | 37 | |
| 38 | target_link_libraries(collocatordb pthread ${LIBRT} snappy z bz2 lz4 zstd ${ROCKSDB} dl) |
| 39 | |
Marc Kupietz | ed0bfcf | 2021-03-14 14:56:15 +0100 | [diff] [blame] | 40 | set_target_properties(collocatordb PROPERTIES |
| 41 | VERSION ${PROJECT_VERSION} |
| 42 | SOVERSION 1 |
| 43 | PUBLIC_HEADER src/collocatordb.h) |
| 44 | |
| 45 | add_library(collocatordb_static STATIC src/collocatordb.cc) |
Marc Kupietz | 4422923 | 2024-08-05 15:00:20 +0200 | [diff] [blame] | 46 | target_link_libraries(collocatordb_static ${ROCKSDB_STATIC} pthread ${LIBRT} snappy z bz2 lz4 zstd dl) |
Marc Kupietz | ed0bfcf | 2021-03-14 14:56:15 +0100 | [diff] [blame] | 47 | |
| 48 | add_executable(basic_test tests/basic_test.c tests/acutest.h) |
| 49 | TARGET_LINK_LIBRARIES(basic_test ${ROCKSDB} collocatordb) |
| 50 | add_test(BASIC_TEST basic_test) |
| 51 | |
Marc Kupietz | 1b09e4d | 2021-03-14 15:20:19 +0100 | [diff] [blame] | 52 | add_executable(static_library_test tests/basic_test.c tests/acutest.h) |
| 53 | TARGET_LINK_LIBRARIES(static_library_test collocatordb_static) |
| 54 | add_test(STATIC_LIBRARY_TEST static_library_test) |
| 55 | |
Marc Kupietz | ed0bfcf | 2021-03-14 14:56:15 +0100 | [diff] [blame] | 56 | # Install library |
Marc Kupietz | 8f977ca | 2021-03-22 17:52:52 +0100 | [diff] [blame] | 57 | install(TARGETS ${PROJECT_NAME} collocatordb_static |
Marc Kupietz | 15f56e7 | 2021-03-15 14:58:13 +0100 | [diff] [blame] | 58 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
Marc Kupietz | d15845c | 2022-04-11 22:28:11 +0200 | [diff] [blame] | 59 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
Marc Kupietz | 15f56e7 | 2021-03-15 14:58:13 +0100 | [diff] [blame] | 60 | PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) |
Marc Kupietz | 4422923 | 2024-08-05 15:00:20 +0200 | [diff] [blame] | 61 | |
| 62 | if (1 AND APPLE) |
| 63 | add_custom_command(TARGET collocatordb POST_BUILD |
| 64 | COMMAND install_name_tool -id "/usr/local/lib/libcollocatordb.1.dylib" $<TARGET_FILE:collocatordb>) |
| 65 | endif() |
Marc Kupietz | b17122d | 2024-11-21 14:32:29 +0100 | [diff] [blame] | 66 | |
Marc Kupietz | b9912e3 | 2024-11-23 10:11:06 +0100 | [diff] [blame] | 67 | file(GLOB TOOLS_SOURCES tools/*.c tools/*.cc) |
| 68 | add_custom_target(tools) |
| 69 | foreach(TOOL_SOURCE ${TOOLS_SOURCES}) |
| 70 | get_filename_component(TOOL_NAME ${TOOL_SOURCE} NAME_WE) |
| 71 | add_executable(${TOOL_NAME} ${TOOL_SOURCE}) |
| 72 | target_link_libraries(${TOOL_NAME} ${ROCKSDB} collocatordb) |
| 73 | set_target_properties(${TOOL_NAME} PROPERTIES |
| 74 | INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib64" |
| 75 | BUILD_WITH_INSTALL_RPATH TRUE) |
| 76 | add_dependencies(tools ${TOOL_NAME}) |
| 77 | install(TARGETS ${TOOL_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) |
| 78 | endforeach() |
| 79 | |
Marc Kupietz | b17122d | 2024-11-21 14:32:29 +0100 | [diff] [blame] | 80 | file(GLOB EXAMPLES_SOURCES examples/*.c examples/*.cc) |
Marc Kupietz | b17122d | 2024-11-21 14:32:29 +0100 | [diff] [blame] | 81 | add_custom_target(examples) |
Marc Kupietz | b17122d | 2024-11-21 14:32:29 +0100 | [diff] [blame] | 82 | foreach(EXAMPLE_SOURCE ${EXAMPLES_SOURCES}) |
| 83 | get_filename_component(EXAMPLE_NAME ${EXAMPLE_SOURCE} NAME_WE) |
| 84 | add_executable(${EXAMPLE_NAME} EXCLUDE_FROM_ALL ${EXAMPLE_SOURCE}) |
| 85 | target_link_libraries(${EXAMPLE_NAME} ${ROCKSDB} collocatordb) |
| 86 | add_dependencies(examples ${EXAMPLE_NAME}) |
| 87 | endforeach() |