-
Notifications
You must be signed in to change notification settings - Fork 38
/
CMakeLists.txt
58 lines (49 loc) · 2.06 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
cmake_minimum_required(VERSION 3.0)
project(lua-mongo)
set(USE_LUA_VERSION "" CACHE STRING "Build for Lua version 'X.Y' ('jit' for LuaJIT).")
set(ver 5.1)
if(USE_LUA_VERSION MATCHES "^[0-9]\\.[0-9]$")
set(ver ${USE_LUA_VERSION})
string(REGEX REPLACE "\\." "" ver_ ${USE_LUA_VERSION})
set(lua lua-${ver} lua${ver} lua${ver_})
elseif(USE_LUA_VERSION STREQUAL "jit")
set(lua luajit)
elseif(USE_LUA_VERSION STREQUAL "")
set(lua lua)
else()
message(FATAL_ERROR "Unrecognized Lua version '${USE_LUA_VERSION}'")
endif()
find_package(mongoc-1.0 1.16 REQUIRED)
find_package(PkgConfig)
pkg_search_module(LUA REQUIRED ${lua})
if(NOT LUA_FOUND)
message(FATAL_ERROR "Lua not found - set USE_LUA_VERSION to match your configuration")
elseif(USE_LUA_VERSION STREQUAL "")
string(REGEX MATCH "^[0-9]\\.[0-9]" USE_LUA_VERSION ${LUA_VERSION})
message(STATUS "Using Lua '${USE_LUA_VERSION}', version ${LUA_VERSION} (set USE_LUA_VERSION to override)")
set(ver ${USE_LUA_VERSION})
else()
message(STATUS "Using Lua '${USE_LUA_VERSION}', version ${LUA_VERSION}")
endif()
add_definitions(-Wall -Wextra -Wpedantic -Wundef -Wshadow -Wredundant-decls -Wstrict-prototypes -Wmissing-prototypes
-Wno-variadic-macros -Wno-unused-result -Wno-unused-parameter)
include_directories(${MONGOC_INCLUDE_DIRS} ${LUA_INCLUDE_DIRS})
link_directories(${MONGOC_LIBRARY_DIRS})
file(GLOB srcs src/*.c)
add_library(mongo SHARED ${srcs})
target_link_libraries(mongo PRIVATE mongo::mongoc_shared)
set_target_properties(mongo PROPERTIES PREFIX "")
if(APPLE)
target_link_libraries(mongo "-undefined dynamic_lookup")
set_target_properties(mongo PROPERTIES SUFFIX ".so")
endif()
include(GNUInstallDirs)
install(TARGETS mongo DESTINATION ${CMAKE_INSTALL_LIBDIR}/lua/${ver})
enable_testing()
find_program(LUA_COMMAND NAMES ${lua})
file(GLOB tests test/test-*.lua)
foreach(test ${tests})
string(REGEX REPLACE "^.*(test-[^/\\]+\\.lua)$" "\\1" name ${test})
add_test(${name} ${LUA_COMMAND} ${CMAKE_SOURCE_DIR}/test/test.lua ${test})
set_tests_properties(${name} PROPERTIES ENVIRONMENT "LUA_CPATH=${CMAKE_BINARY_DIR}/?.so\;\;")
endforeach()