CMakeLists.txt 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. project(lua CXX)
  2. set(LUA_VERSION_MAJOR 5)
  3. set(LUA_VERSION_MINOR 1)
  4. set(LUA_VERSION_PATCH 4)
  5. set(LUA_VERSION "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}.${LUA_VERSION_PATCH}")
  6. set(COMMON_CFLAGS)
  7. set(COMMON_LDFLAGS)
  8. set(LIBS)
  9. if(APPLE)
  10. set(DEFAULT_POSIX TRUE)
  11. set(DEFAULT_DLOPEN OFF)
  12. set(COMMON_CFLAGS "${COMMON_CFLAGS} -DLUA_USE_MACOSX")
  13. elseif(UNIX OR CYGWIN)
  14. set(DEFAULT_POSIX TRUE)
  15. elseif(WIN32)
  16. set(LUA_WIN TRUE)
  17. set(COMMON_CFLAGS "${COMMON_CFLAGS} -DLUA_BUILD_AS_DLL")
  18. else()
  19. set(DEFAULT_ANSI TRUE)
  20. endif()
  21. if(MSVC)
  22. set(COMMON_CFLAGS "${COMMON_CFLAGS} -D_CRT_SECURE_NO_WARNINGS")
  23. endif()
  24. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  25. set(COMMON_LDFLAGS "${COMMON_LDFLAGS} -Wl,-E -lm")
  26. set(DEFAULT_DLOPEN ON)
  27. endif()
  28. option(LUA_USE_DLOPEN "Enable dlopen support." ${DEFAULT_DLOPEN})
  29. mark_as_advanced(LUA_USE_DLOPEN)
  30. option(LUA_ANSI "Disable non-ANSI features." ${DEFAULT_ANSI})
  31. mark_as_advanced(LUA_ANSI)
  32. if(LUA_USE_DLOPEN)
  33. set(COMMON_CFLAGS "${COMMON_CFLAGS} -DLUA_USE_DLOPEN")
  34. if(NOT APPLE)
  35. set(COMMON_LDFLAGS "${COMMON_LDFLAGS} -ldl ")
  36. endif(NOT APPLE)
  37. endif(LUA_USE_DLOPEN)
  38. if(DEFAULT_POSIX)
  39. set(COMMON_CFLAGS "${COMMON_CFLAGS} -DLUA_USE_POSIX")
  40. endif(DEFAULT_POSIX)
  41. if(LUA_ANSI)
  42. set(COMMON_CFLAGS "${COMMON_CFLAGS} -DLUA_ANSI")
  43. endif(LUA_ANSI)
  44. # Standard flags to use
  45. if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|(Apple)?Clang")
  46. set(COMMON_CFLAGS "${COMMON_CFLAGS} -pipe -Wall -Wextra -Wshadow -W -pedantic")
  47. endif()
  48. # COMMON_CFLAGS has no effect without this line
  49. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_CFLAGS}")
  50. add_subdirectory(src)