CMakeLists.txt 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # If Lua is installed in a non-standard location, please set the LUA_DIR
  2. # environment variable to point to prefix for the install. Eg:
  3. # Unix: export LUA_DIR=/home/user/pkg
  4. # Windows: set LUA_DIR=c:\lua51
  5. project(lua-cjson C)
  6. cmake_minimum_required(VERSION 2.6)
  7. option(USE_INTERNAL_FPCONV "Use internal strtod() / g_fmt() code for performance")
  8. option(MULTIPLE_THREADS "Support multi-threaded apps with internal fpconv - recommended" ON)
  9. if(NOT CMAKE_BUILD_TYPE)
  10. set(CMAKE_BUILD_TYPE Release CACHE STRING
  11. "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
  12. FORCE)
  13. endif()
  14. find_package(Lua51 REQUIRED)
  15. include_directories(${LUA_INCLUDE_DIR})
  16. if(NOT USE_INTERNAL_FPCONV)
  17. # Use libc number conversion routines (strtod(), sprintf())
  18. set(FPCONV_SOURCES fpconv.c)
  19. else()
  20. # Use internal number conversion routines
  21. add_definitions(-DUSE_INTERNAL_FPCONV)
  22. set(FPCONV_SOURCES g_fmt.c dtoa.c)
  23. include(TestBigEndian)
  24. TEST_BIG_ENDIAN(IEEE_BIG_ENDIAN)
  25. if(IEEE_BIG_ENDIAN)
  26. add_definitions(-DIEEE_BIG_ENDIAN)
  27. endif()
  28. if(MULTIPLE_THREADS)
  29. set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
  30. find_package(Threads REQUIRED)
  31. if(NOT CMAKE_USE_PTHREADS_INIT)
  32. message(FATAL_ERROR
  33. "Pthreads not found - required by MULTIPLE_THREADS option")
  34. endif()
  35. add_definitions(-DMULTIPLE_THREADS)
  36. endif()
  37. endif()
  38. # Handle platforms missing isinf() macro (Eg, some Solaris systems).
  39. include(CheckSymbolExists)
  40. CHECK_SYMBOL_EXISTS(isinf math.h HAVE_ISINF)
  41. if(NOT HAVE_ISINF)
  42. add_definitions(-DUSE_INTERNAL_ISINF)
  43. endif()
  44. set(_MODULE_LINK "${CMAKE_THREAD_LIBS_INIT}")
  45. get_filename_component(_lua_lib_dir ${LUA_LIBRARY} PATH)
  46. if(APPLE)
  47. set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS
  48. "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -undefined dynamic_lookup")
  49. endif()
  50. if(WIN32)
  51. # Win32 modules need to be linked to the Lua library.
  52. set(_MODULE_LINK ${LUA_LIBRARY} ${_MODULE_LINK})
  53. set(_lua_module_dir "${_lua_lib_dir}")
  54. # Windows sprintf()/strtod() handle NaN/inf differently. Not supported.
  55. add_definitions(-DDISABLE_INVALID_NUMBERS)
  56. else()
  57. set(_lua_module_dir "${_lua_lib_dir}/lua/5.1")
  58. endif()
  59. add_library(cjson MODULE lua_cjson.c strbuf.c ${FPCONV_SOURCES})
  60. set_target_properties(cjson PROPERTIES PREFIX "")
  61. target_link_libraries(cjson ${_MODULE_LINK})
  62. install(TARGETS cjson DESTINATION "${_lua_module_dir}")
  63. # vi:ai et sw=4 ts=4: