CMakeLists.txt 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. project(lua C)
  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(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
  7. set(COMMON_CFLAGS)
  8. set(COMMON_LDFLAGS)
  9. set(LIBS)
  10. if(APPLE)
  11. set(DEFAULT_POSIX TRUE)
  12. set(DEFAULT_DLOPEN OFF)
  13. set(COMMON_CFLAGS "${COMMON_CFLAGS} -DLUA_USE_MACOSX")
  14. elseif(UNIX OR CYGWIN)
  15. set(DEFAULT_POSIX TRUE)
  16. elseif(WIN32)
  17. set(LUA_WIN TRUE)
  18. set(COMMON_CFLAGS "${COMMON_CFLAGS} -DLUA_BUILD_AS_DLL")
  19. else()
  20. set(DEFAULT_ANSI TRUE)
  21. endif()
  22. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  23. set(COMMON_LDFLAGS "${COMMON_LDFLAGS} -Wl,-E -lm")
  24. set(DEFAULT_DLOPEN ON)
  25. endif()
  26. option(LUA_USE_DLOPEN "Enable dlopen support." ${DEFAULT_DLOPEN})
  27. mark_as_advanced(LUA_USE_DLOPEN)
  28. option(LUA_ANSI "Disable non-ANSI features." ${DEFAULT_ANSI})
  29. mark_as_advanced(LUA_ANSI)
  30. if(LUA_USE_DLOPEN)
  31. set(COMMON_CFLAGS "${COMMON_CFLAGS} -DLUA_USE_DLOPEN")
  32. if(NOT APPLE)
  33. set(COMMON_LDFLAGS "${COMMON_LDFLAGS} -ldl ")
  34. endif(NOT APPLE)
  35. endif(LUA_USE_DLOPEN)
  36. if(DEFAULT_POSIX)
  37. set(COMMON_CFLAGS "${COMMON_CFLAGS} -DLUA_USE_POSIX")
  38. endif(DEFAULT_POSIX)
  39. if(LUA_ANSI)
  40. set(COMMON_CFLAGS "${COMMON_CFLAGS} -DLUA_ANSI")
  41. endif(LUA_ANSI)
  42. # COMMON_CFLAGS has no effect without this line
  43. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_CFLAGS}")
  44. # Standard flags to use for each build type.
  45. if(CMAKE_COMPILER_IS_GNUCC)
  46. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pipe -Wall -Wextra -Wshadow -W -pedantic -std=gnu99")
  47. set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2")
  48. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g")
  49. set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_PROFILE} -O1 -g")
  50. set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_WITHDEBINFO} -O2 -g")
  51. endif(CMAKE_COMPILER_IS_GNUCC)
  52. add_subdirectory(src build)