forked from neoxic/lua-mongo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
55 lines (46 loc) · 1.9 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
cmake_minimum_required(VERSION 3.0)
project(lua-mongo)
set(USE_LUA_VERSION "" CACHE STRING "Build for Lua version 'X.Y' (or 'jit' for LuaJIT).")
if(USE_LUA_VERSION MATCHES "^[0-9]\\.[0-9]$")
set(ver ${USE_LUA_VERSION})
string(REGEX REPLACE "\\." "" ver2 ${USE_LUA_VERSION})
set(lua lua-${ver} lua${ver} lua${ver2})
elseif(USE_LUA_VERSION MATCHES "^(jit|)$")
set(lua lua${USE_LUA_VERSION})
set(ver 5.1)
else()
message(FATAL_ERROR "Unrecognized Lua version '${USE_LUA_VERSION}'")
endif()
find_package(libmongoc-1.0 1.13 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)
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 ${MONGOC_LIBRARIES})
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_CURRENT_SOURCE_DIR}/test/test.lua ${test})
endforeach()