blob: 07dc4049612cef2a86daf723ffbd968f2f18f3eb [file] [log] [blame]
Marc Kupietzed0bfcf2021-03-14 14:56:15 +01001cmake_minimum_required(VERSION 3.9)
Marc Kupietzce2d0052024-11-15 15:46:37 +01002project(collocatordb VERSION 1.3.2 DESCRIPTION "Storing and retrieving collocation counts based on RocksDB")
Marc Kupietz673bd812021-03-14 17:27:44 +01003set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fno-rtti -std=c++11 -std=gnu++11")
Marc Kupietzed0bfcf2021-03-14 14:56:15 +01004set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
5
6include(GNUInstallDirs)
Marc Kupietz15f56e72021-03-15 14:58:13 +01007
8# the RPATH to be used when installing, but only if it's not a system directory
9list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
10if("${isSystemDir}" STREQUAL "-1")
11 set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
12endif("${isSystemDir}" STREQUAL "-1")
13
Marc Kupietz6208fd72024-11-15 15:46:19 +010014configure_file(src/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY)
15include_directories(/usr/local/include /opt/homebrew/include build)
Marc Kupietz44229232024-08-05 15:00:20 +020016link_directories(/usr/local/lib64 /usr/local/lib /usr/lib64 /usr/lib /opt/homebrew/lib)
17if (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")
23else()
24 set(LIBRT "rt")
25 find_library(ROCKSDB NAMES librocksdb.so.5.11)
26endif()
Marc Kupietz1b09e4d2021-03-14 15:20:19 +010027find_library(ROCKSDB_STATIC librocksdb.a)
28
Marc Kupietz6208fd72024-11-15 15:46:19 +010029get_cmake_property(_variableNames VARIABLES)
30list (SORT _variableNames)
31foreach (_variableName ${_variableNames})
32 message(STATUS "${_variableName}=${${_variableName}}")
33endforeach()
34
Marc Kupietzed0bfcf2021-03-14 14:56:15 +010035enable_testing()
36add_library(collocatordb SHARED src/collocatordb.cc)
Marc Kupietz44229232024-08-05 15:00:20 +020037
38target_link_libraries(collocatordb pthread ${LIBRT} snappy z bz2 lz4 zstd ${ROCKSDB} dl)
39
Marc Kupietzed0bfcf2021-03-14 14:56:15 +010040set_target_properties(collocatordb PROPERTIES
41 VERSION ${PROJECT_VERSION}
42 SOVERSION 1
43 PUBLIC_HEADER src/collocatordb.h)
44
45add_library(collocatordb_static STATIC src/collocatordb.cc)
Marc Kupietz44229232024-08-05 15:00:20 +020046target_link_libraries(collocatordb_static ${ROCKSDB_STATIC} pthread ${LIBRT} snappy z bz2 lz4 zstd dl)
Marc Kupietzed0bfcf2021-03-14 14:56:15 +010047
48add_executable(basic_test tests/basic_test.c tests/acutest.h)
49TARGET_LINK_LIBRARIES(basic_test ${ROCKSDB} collocatordb)
50add_test(BASIC_TEST basic_test)
51
Marc Kupietz1b09e4d2021-03-14 15:20:19 +010052add_executable(static_library_test tests/basic_test.c tests/acutest.h)
53TARGET_LINK_LIBRARIES(static_library_test collocatordb_static)
54add_test(STATIC_LIBRARY_TEST static_library_test)
55
Marc Kupietzed0bfcf2021-03-14 14:56:15 +010056# Install library
Marc Kupietz8f977ca2021-03-22 17:52:52 +010057install(TARGETS ${PROJECT_NAME} collocatordb_static
Marc Kupietz15f56e72021-03-15 14:58:13 +010058 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Marc Kupietzd15845c2022-04-11 22:28:11 +020059 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
Marc Kupietz15f56e72021-03-15 14:58:13 +010060 PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
Marc Kupietz44229232024-08-05 15:00:20 +020061
62if (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>)
65endif()