From 2487f7fa11a9c3c6d24948b4abc9a0e5468d1b1d Mon Sep 17 00:00:00 2001 From: Mark Pulford Date: Tue, 13 Dec 2011 23:39:57 +1030 Subject: Add support for building via CMake --- CMakeLists.txt | 47 +++++++++++++++++++++++++++++++++++++++++++++++ runtests.sh | 10 ++++++++++ 2 files changed, 57 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..bfb28cc --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,47 @@ +# If Lua is installed in a non-standard location, please set the LUA_DIR +# environment variable to point to prefix for the install. Eg: +# Unix: export LUA_DIR=/home/user/pkg +# Windows: set LUA_DIR=c:\lua51 + +project(lua_cjson C) +cmake_minimum_required(VERSION 2.6) + +set(CMAKE_BUILD_TYPE Release) + +find_package(Lua51 REQUIRED) +include_directories(${LUA_INCLUDE_DIR}) + +# Use thread-safe POSIX.1-2008 uselocale() where available, otherwise +# fall back to ANSI C setlocale(). +include(CheckFunctionExists) +CHECK_FUNCTION_EXISTS(uselocale HAVE_USELOCALE) +if(HAVE_USELOCALE) + add_definitions(-DUSE_POSIX_USELOCALE) +else() + add_definitions(-DUSE_POSIX_SETLOCALE) +endif() + +# Handle platforms missing isinf() macro (Eg, some Solaris systems). +include(CheckSymbolExists) +CHECK_SYMBOL_EXISTS(isinf math.h HAVE_ISINF) +if(NOT HAVE_ISINF) + add_definitions(-DUSE_INTERNAL_ISINF) +endif() + +if(APPLE) + set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS + "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -undefined dynamic_lookup") +endif() + +get_filename_component(_lua_lib_dir ${LUA_LIBRARY} PATH) +if(WIN32) + set(_lua_module_dir "${_lua_lib_dir}") +else() + set(_lua_module_dir "${_lua_lib_dir}/lua/5.1") +endif() + +add_library(cjson MODULE lua_cjson.c strbuf.c) +set_target_properties(cjson PROPERTIES PREFIX "") +install(TARGETS cjson DESTINATION "${_lua_module_dir}") + +# vi:ai et sw=4 ts=4: diff --git a/runtests.sh b/runtests.sh index f273385..c520be0 100755 --- a/runtests.sh +++ b/runtests.sh @@ -54,6 +54,16 @@ do_tests make clean rm -f tests/cjson.so +echo "===== Testing Cmake build =====" +mkdir build +cd build +cmake .. +make +cd .. +cp build/cjson.so tests +do_tests +rm -rf build tests/cjson.so + if [ "$PLATFORM" = "Linux" ] then echo "===== Testing RPM build =====" -- cgit v1.2.3-55-g6feb