| 1 |
# Build for LuaBind |
| 2 |
# Ryan Pavlik <[email protected]> |
| 3 |
# http://academic.cleardefinition.com/ |
| 4 |
# Iowa State University HCI Graduate Program/VRAC |
| 5 |
|
| 6 |
cmake_minimum_required(VERSION 3.5) |
| 7 |
set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required |
| 8 |
project(LuaBind) |
| 9 |
set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 10 |
|
| 11 |
include(CheckCXXCompilerFlag) |
| 12 |
include (GNUInstallDirs) |
| 13 |
|
| 14 |
if(NOT LUABIND_LIBRARY_VERSION) |
| 15 |
set(LUABIND_LIBRARY_VERSION_MAJOR "0") |
| 16 |
set(LUABIND_LIBRARY_VERSION_MINOR "9") |
| 17 |
set(LUABIND_LIBRARY_VERSION_PATCH "1") |
| 18 |
set(LUABIND_LIBRARY_VERSION |
| 19 |
"${LUABIND_LIBRARY_VERSION_MAJOR}.${LUABIND_LIBRARY_VERSION_MINOR}.${LUABIND_LIBRARY_VERSION_PATCH}") |
| 20 |
else() |
| 21 |
string(REGEX MATCHALL "[^.]+" VERSION ${LUABIND_LIBRARY_VERSION}) |
| 22 |
list (GET VERSION 0 LUABIND_LIBRARY_VERSION_MAJOR) |
| 23 |
list (GET VERSION 1 LUABIND_LIBRARY_VERSION_MINOR) |
| 24 |
list (GET VERSION 2 LUABIND_LIBRARY_VERSION_PATCH) |
| 25 |
endif() |
| 26 |
set(CPACK_PACKAGE_VERSION_MAJOR "${LUABIND_LIBRARY_VERSION_MAJOR}") |
| 27 |
set(CPACK_PACKAGE_VERSION_MINOR "${LUABIND_LIBRARY_VERSION_MINOR}") |
| 28 |
set(CPACK_PACKAGE_VERSION_PATCH "${LUABIND_LIBRARY_VERSION_PATCH}") |
| 29 |
set(CPACK_PACKAGE_VERSION "${LUABIND_LIBRARY_VERSION}") |
| 30 |
|
| 31 |
list(APPEND CMAKE_MODULE_PATH |
| 32 |
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules") |
| 33 |
|
| 34 |
if(NOT Boost_FOUND) |
| 35 |
set(Boost_USE_STATIC_LIBS ON) |
| 36 |
set(Boost_USE_MULTITHREADED ON) |
| 37 |
set(Boost_USE_STATIC_RUNTIME OFF) |
| 38 |
find_package(Boost REQUIRED) |
| 39 |
endif() |
| 40 |
|
| 41 |
if(NOT LUA_FOUND AND NOT LUA51_FOUND AND NOT LUA52_FOUND) |
| 42 |
set(LUABIND_LUA_VERSION "" CACHE STRING |
| 43 |
"51 or 52; empty to use 51 if 52 cannot be found and 52 otherwise.") |
| 44 |
|
| 45 |
if(LUABIND_LUA_VERSION) |
| 46 |
find_package("Lua${LUABIND_LUA_VERSION}" REQUIRED) |
| 47 |
else() |
| 48 |
find_package(Lua52) |
| 49 |
if(NOT LUA52_FOUND) |
| 50 |
find_package(Lua51) |
| 51 |
if(NOT LUA51_FOUND) |
| 52 |
message(FATAL_ERROR "Neither Lua 5.1 nor 5.2 could be found.") |
| 53 |
endif() |
| 54 |
endif() |
| 55 |
endif() |
| 56 |
set(LUA_INCLUDE_DIRS "${LUA_INCLUDE_DIR}") |
| 57 |
endif() |
| 58 |
|
| 59 |
if(NOT MSVC) |
| 60 |
check_cxx_compiler_flag(-std=c++11 LUABIND_HAS_CXX11) |
| 61 |
if (LUABIND_HAS_CXX11) |
| 62 |
set (LUABIND_CXX11_COMPILER_FLAGS "-std=c++11") |
| 63 |
else() |
| 64 |
message("Compiler does not support -std=c++11 flag, C++11 disabled.") |
| 65 |
endif() |
| 66 |
elseif(MSVC_VERSION GREATER 1699) # 1700 = VS 11 (2012) |
| 67 |
set (LUABIND_HAS_CXX11 ON) |
| 68 |
else() |
| 69 |
set (LUABIND_HAS_CXX11 OFF) |
| 70 |
message("MSVC < 11 (2012) detected, C++11 disabled.") |
| 71 |
endif() |
| 72 |
|
| 73 |
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) |
| 74 |
# We are the top-level project |
| 75 |
option(LUABIND_INSTALL "Install the LuaBind library and headers" ON) |
| 76 |
option(LUABIND_APPEND_VERSION_SUFFIX "Append a version suffix to the library name (like luabind09)?" ON) |
| 77 |
option(LUABIND_NO_ERROR_CHECKING "Build so that all the Lua code is expected only to make legal calls?" OFF) |
| 78 |
option(LUABIND_NO_EXCEPTIONS "Disable all usage of try, catch, and throw?" OFF) |
| 79 |
option(LUABIND_CPLUSPLUS_LUA "Was Lua built as C++?" OFF) |
| 80 |
option(LUABIND_DYNAMIC_LINK "Build luabind as a shared library?" OFF) |
| 81 |
option(LUABIND_NOT_THREADSAFE "Permit the use of static variables, thus making Luabind usable only from one of your system threads." OFF) |
| 82 |
option(LUABIND_ENABLE_WARNINGS "Enable extra warnings during the build of the library and tests" ON) |
| 83 |
if (LUABIND_HAS_CXX11) |
| 84 |
option(LUABIND_USE_CXX11 "Build Luabind using C++11 features?" ON) |
| 85 |
else() |
| 86 |
set(LUABIND_USE_CXX11 OFF) |
| 87 |
endif() |
| 88 |
|
| 89 |
if(Boost_VERSION LESS 104700) |
| 90 |
set(LUABIND_USE_NOEXCEPT_DEF OFF) |
| 91 |
# 1900 = VS 14 (2015) |
| 92 |
if (LUABIND_CXX11_DEFAULT AND NOT MSVC OR MSVC_VERSION GREATER 1899) |
| 93 |
set(LUABIND_USE_NOEXCEPT_DEF ON) |
| 94 |
endif() |
| 95 |
option(LUABIND_USE_NOEXCEPT "If your compiler is C++11 compliant, but you're using old Boost, you need to set this." ${LUABIND_USE_NOEXCEPT_DEF}) |
| 96 |
unset(LUABIND_USE_NOEXCEPT_DEF) |
| 97 |
endif() |
| 98 |
|
| 99 |
if(LUABIND_USE_CXX11 AND NOT LUABIND_HAS_CXX11) |
| 100 |
# The compiler supports no C++11 |
| 101 |
set(LUABIND_USE_CXX11 OFF CACHE BOOL "Build Luabind using C++11 features?" FORCE) |
| 102 |
endif() |
| 103 |
|
| 104 |
if(LUABIND_USE_CXX11) |
| 105 |
option(LUABIND_NO_SCOPED_ENUM "Indicates that your compiler and standard library lacks scoped enums and std::underlying_type" OFF) |
| 106 |
set(LUABIND_NO_STD_SHARED_PTR OFF) |
| 107 |
else() |
| 108 |
# No CXX11, can't have scoped enum |
| 109 |
# TODO is this right? |
| 110 |
#set(LUABIND_NO_SCOPED_ENUM ON CACHE INTERNAL "" FORCE) |
| 111 |
option(LUABIND_NO_STD_SHARED_PTR "Indicates that your standard library lacks C++11 shared_ptr in std namespace" ON) |
| 112 |
endif() |
| 113 |
|
| 114 |
endif() |
| 115 |
|
| 116 |
if(LUABIND_NO_STD_SHARED_PTR) |
| 117 |
add_definitions(-DLUABIND_NO_STD_SHARED_PTR) |
| 118 |
endif() |
| 119 |
|
| 120 |
if(LUABIND_USE_CXX11) |
| 121 |
add_definitions(-DLUABIND_USE_CXX11) |
| 122 |
endif() |
| 123 |
|
| 124 |
# Configure the build info header |
| 125 |
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/luabind") |
| 126 |
configure_file(build_information.hpp.cmake_in "${CMAKE_CURRENT_BINARY_DIR}/luabind/build_information.hpp") |
| 127 |
|
| 128 |
# Set up the build |
| 129 |
set(BUILD_SHARED_LIBS ${LUABIND_DYNAMIC_LINK}) |
| 130 |
|
| 131 |
if(LUABIND_USE_CXX11 AND LUABIND_CXX11_COMPILER_FLAGS) |
| 132 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LUABIND_CXX11_COMPILER_FLAGS}") |
| 133 |
elseif(NOT LUABIND_USE_CXX11 AND NOT MSVC) |
| 134 |
check_cxx_compiler_flag(-std=c++98 LUABIND_HAS_CXX98FLAG) |
| 135 |
if (LUABIND_HAS_CXX98FLAG) |
| 136 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++98") |
| 137 |
endif() |
| 138 |
endif() |
| 139 |
|
| 140 |
# Test and enable warning flags if desired, as well as other compiler flag |
| 141 |
macro(_luabind_add_flag _flag _var) |
| 142 |
check_cxx_compiler_flag(${_flag} ${_var}) |
| 143 |
if(${_var}) |
| 144 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flag}") |
| 145 |
endif() |
| 146 |
endmacro() |
| 147 |
|
| 148 |
if(MSVC) |
| 149 |
# multi-process compile |
| 150 |
_luabind_add_flag(/MP SUPPORTS_MP_FLAG) |
| 151 |
if(LUABIND_ENABLE_WARNINGS) |
| 152 |
# Warning level 4 |
| 153 |
_luabind_add_flag(/W4 SUPPORTS_W4_FLAG) |
| 154 |
|
| 155 |
# Disable incorrect warning C4709 |
| 156 |
# ("comma operator within array index expression") |
| 157 |
_luabind_add_flag(/wd4709 SUPPORTS_WD4709_FLAG) |
| 158 |
|
| 159 |
IF (MSVC_VERSION GREATER 1899) # 1900 = MSVC 14 (2015) |
| 160 |
# Disable overly pendantic warning C4459 "declaration of 'var' hides |
| 161 |
# global declaration" which is issued a lot for 'result' which is |
| 162 |
# globally declared for policies. See also |
| 163 |
# https://connect.microsoft.com/VisualStudio/feedback/details/1355600/. |
| 164 |
_luabind_add_flag(/wd4459 SUPPORTS_WD4459_FLAG) |
| 165 |
|
| 166 |
# Disable warning C4913 "user defined binary operator ',' exists but |
| 167 |
# no overload could convert all operands, default built-in binary |
| 168 |
# operator ',' used" which is triggered even when no comma is |
| 169 |
# involved at all, refering to the 'T const& x, |
| 170 |
# operator_void_return' overload in luabind::detail. |
| 171 |
_luabind_add_flag(/wd4913 SUPPORTS_WD4913_FLAG) |
| 172 |
endif() |
| 173 |
endif() |
| 174 |
else() |
| 175 |
|
| 176 |
set(possible_flags) |
| 177 |
if(BUILD_SHARED_LIBS) |
| 178 |
list(APPEND possible_flags fvisibility=hidden) |
| 179 |
endif() |
| 180 |
if(LUABIND_ENABLE_WARNINGS) |
| 181 |
list(APPEND possible_flags |
| 182 |
Wall |
| 183 |
Wextra |
| 184 |
Wno-deprecated-declarations # auto_ptr is OK for now |
| 185 |
Wno-unused-macros |
| 186 |
Wlogical-op |
| 187 |
Wmissing-declarations |
| 188 |
Wsign-conversion |
| 189 |
pedantic |
| 190 |
Wcast-align |
| 191 |
Wcast-qual |
| 192 |
Wctor-dtor-privacy |
| 193 |
Winit-self |
| 194 |
Wdisabled-optimizations |
| 195 |
Wformat=2 |
| 196 |
Wmissing-include-dirs |
| 197 |
Wold-style-cast |
| 198 |
Woverloaded-virtual |
| 199 |
Wredundant-decls |
| 200 |
Wshadow |
| 201 |
Wsign-promo |
| 202 |
Wstrict-null-sentinel |
| 203 |
Wstrict-overflow=5) |
| 204 |
|
| 205 |
|
| 206 |
if(LUABIND_USE_CXX11) |
| 207 |
list(APPEND possible_flags Wnoexcept) |
| 208 |
endif() |
| 209 |
|
| 210 |
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| 211 |
list(APPEND possible_flags |
| 212 |
Weverything |
| 213 |
Wno-unused-local-typedef |
| 214 |
Wno-shadow |
| 215 |
Wno-undef |
| 216 |
Wno-global-constructors |
| 217 |
Wno-weak-vtables |
| 218 |
Wno-padded |
| 219 |
Wno-exit-time-destructors |
| 220 |
Wno-missing-noreturn) |
| 221 |
|
| 222 |
if(LUABIND_USE_CXX11) |
| 223 |
list(APPEND possible_flags |
| 224 |
Wno-zero-as-nullpointer |
| 225 |
Wno-c++98-compat |
| 226 |
Wno-c++98-compat-pedantic) |
| 227 |
else() |
| 228 |
list(APPEND possible_flags |
| 229 |
Wno-c++11-long-long) |
| 230 |
endif() |
| 231 |
|
| 232 |
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT LUABIND_USE_CXX11) |
| 233 |
list(APPEND possible_flags Wno-long-long) |
| 234 |
endif() |
| 235 |
|
| 236 |
endif() |
| 237 |
|
| 238 |
if(possible_flags) |
| 239 |
foreach(_flag ${possible_flags}) |
| 240 |
string(REGEX REPLACE [-+=] _ sanitized_flag ${_flag}) |
| 241 |
_luabind_add_flag(-${_flag} SUPPORTS_${sanitized_flag}_FLAG) |
| 242 |
endforeach() |
| 243 |
endif() |
| 244 |
endif() |
| 245 |
|
| 246 |
include_directories(BEFORE |
| 247 |
"${CMAKE_CURRENT_SOURCE_DIR}" |
| 248 |
"${CMAKE_CURRENT_BINARY_DIR}") |
| 249 |
include_directories(AFTER SYSTEM |
| 250 |
${Boost_INCLUDE_DIRS} |
| 251 |
${LUA_INCLUDE_DIRS}) |
| 252 |
|
| 253 |
add_subdirectory(src) |
| 254 |
|
| 255 |
# Set up testing and documentation, only if we are the top-level project. |
| 256 |
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) |
| 257 |
include(CTest) |
| 258 |
if(BUILD_TESTING) |
| 259 |
add_subdirectory(test) |
| 260 |
endif() |
| 261 |
add_subdirectory(doc) |
| 262 |
endif() |
| 263 |
|
| 264 |
if(LUABIND_INSTALL) |
| 265 |
if(WIN32 AND NOT CYGWIN) |
| 266 |
set(INSTALL_CMAKE_DIR CMake) |
| 267 |
set(INSTALL_CMAKE_DIR_LUA CMake) |
| 268 |
else() |
| 269 |
set(INSTALL_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake") |
| 270 |
set(INSTALL_CMAKE_DIR_LUA "${CMAKE_INSTALL_LIBDIR}/cmake") |
| 271 |
endif() |
| 272 |
install(FILES "cmake/Modules/FindLuabind.cmake" DESTINATION ${INSTALL_CMAKE_DIR}) |
| 273 |
install(FILES "cmake/Modules/FindLua52.cmake" DESTINATION ${INSTALL_CMAKE_DIR_LUA}) |
| 274 |
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/luabind/build_information.hpp" DESTINATION include/luabind) |
| 275 |
endif() |