CMakeLists.txt 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. if(LOVR)
  15. set(LUA_LIBRARY ${LOVR_LUA})
  16. else()
  17. find_package(Lua51 REQUIRED)
  18. include_directories(${LUA_INCLUDE_DIR})
  19. endif()
  20. if(NOT USE_INTERNAL_FPCONV)
  21. # Use libc number conversion routines (strtod(), sprintf())
  22. set(FPCONV_SOURCES fpconv.c)
  23. else()
  24. # Use internal number conversion routines
  25. add_definitions(-DUSE_INTERNAL_FPCONV)
  26. set(FPCONV_SOURCES g_fmt.c dtoa.c)
  27. include(TestBigEndian)
  28. TEST_BIG_ENDIAN(IEEE_BIG_ENDIAN)
  29. if(IEEE_BIG_ENDIAN)
  30. add_definitions(-DIEEE_BIG_ENDIAN)
  31. endif()
  32. if(MULTIPLE_THREADS)
  33. set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
  34. find_package(Threads REQUIRED)
  35. if(NOT CMAKE_USE_PTHREADS_INIT)
  36. message(FATAL_ERROR
  37. "Pthreads not found - required by MULTIPLE_THREADS option")
  38. endif()
  39. add_definitions(-DMULTIPLE_THREADS)
  40. endif()
  41. endif()
  42. # Handle platforms missing isinf() macro (Eg, some Solaris systems).
  43. include(CheckSymbolExists)
  44. CHECK_SYMBOL_EXISTS(isinf math.h HAVE_ISINF)
  45. if(NOT HAVE_ISINF)
  46. add_definitions(-DUSE_INTERNAL_ISINF)
  47. endif()
  48. set(_MODULE_LINK "${CMAKE_THREAD_LIBS_INIT}")
  49. if(APPLE)
  50. set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS
  51. "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -undefined dynamic_lookup")
  52. endif()
  53. if(WIN32)
  54. # Win32 modules need to be linked to the Lua library.
  55. set(_MODULE_LINK ${LUA_LIBRARY} ${_MODULE_LINK})
  56. # Windows sprintf()/strtod() handle NaN/inf differently. Not supported.
  57. add_definitions(-DDISABLE_INVALID_NUMBERS)
  58. endif()
  59. if(MSVC)
  60. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  61. add_definitions(-Dstrncasecmp=_strnicmp)
  62. if(MSVC_VERSION VERSION_LESS 1900)
  63. add_definitions(-Dinline=__inline)
  64. add_definitions(-Dsnprintf=_snprintf)
  65. endif()
  66. endif()
  67. add_library(cjson MODULE lua_cjson.c strbuf.c ${FPCONV_SOURCES})
  68. set_target_properties(cjson PROPERTIES PREFIX "")
  69. target_link_libraries(cjson ${_MODULE_LINK})
  70. # vi:ai et sw=4 ts=4: