diff options
author | Andy <drumsetmonkey@gmail.com> | 2019-08-29 13:07:45 -0400 |
---|---|---|
committer | Andy <drumsetmonkey@gmail.com> | 2019-08-29 13:07:45 -0400 |
commit | 4ac4b280abf2ffa28caa5a532353115a3033444f (patch) | |
tree | 2a13d658bb454360b2faf401244bb0321d3460d4 /lib/sol2/cmake/Modules/FindLua | |
parent | e9758416b18b27a65337c28d9641afc0ee89b34b (diff) | |
parent | 7a46fa2dd3dad3f038bf8e7339bc67abca428ae6 (diff) |
Started creating scripting library/namespace and added sol2 for interfacing
Diffstat (limited to 'lib/sol2/cmake/Modules/FindLua')
-rw-r--r-- | lib/sol2/cmake/Modules/FindLua/set_version_vars.cmake | 77 | ||||
-rw-r--r-- | lib/sol2/cmake/Modules/FindLua/version_check.cmake | 28 |
2 files changed, 105 insertions, 0 deletions
diff --git a/lib/sol2/cmake/Modules/FindLua/set_version_vars.cmake b/lib/sol2/cmake/Modules/FindLua/set_version_vars.cmake new file mode 100644 index 0000000..c159221 --- /dev/null +++ b/lib/sol2/cmake/Modules/FindLua/set_version_vars.cmake @@ -0,0 +1,77 @@ +# # # # sol3 +# The MIT License (MIT) +# +# Copyright (c) 2013-2019 Rapptz, ThePhD, and contributors +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +# Uses the Lua version and calculates the names of the include directories and library +# name accordingly. +# +# :: +# _prefix - Prefix added to all variables exposed, e.g. "lua" or "luajit" +# _lua_suffix - Name suffix, typically only used for specifiying luajit, which is "jit" + +function(_lua_set_version_vars _prefix _lua_suffix) + set(LUA_VERSIONS5 5.3 5.2 5.1 5.0) + + if (${_prefix}_FIND_VERSION_EXACT) + if (${_prefix}_FIND_VERSION_COUNT GREATER 1) + set(_${_prefix}_append_versions ${${_prefix}_FIND_VERSION_MAJOR}.${${_prefix}_FIND_VERSION_MINOR}) + endif () + elseif (${_prefix}_FIND_VERSION) + # once there is a different major version supported this should become a loop + if (NOT ${_prefix}_FIND_VERSION_MAJOR GREATER 5) + if (${_prefix}_FIND_VERSION_COUNT EQUAL 1) + set(_${_prefix}_append_versions ${${_prefix}_VERSIONS5}) + else () + foreach (subver IN LISTS ${_prefix}_VERSIONS5) + if (NOT subver VERSION_LESS ${${_prefix}_FIND_VERSION}) + list(APPEND _${_prefix}_append_versions ${subver}) + endif () + endforeach () + endif () + endif () + else () + # once there is a different major version supported this should become a loop + set(_${_prefix}_append_versions ${LUA_VERSIONS5}) + endif () + + list(APPEND _${_prefix}_include_subdirs "include/lua" "include") + + foreach (ver IN LISTS _${_prefix}_append_versions) + string(REGEX MATCH "^([0-9]+)\\.([0-9]+)$" _ver "${ver}") + list(APPEND _${_prefix}_include_subdirs + include/lua${_lua_suffix}${CMAKE_MATCH_1}${CMAKE_MATCH_2} + include/lua${_lua_suffix}${CMAKE_MATCH_1}.${CMAKE_MATCH_2} + include/lua${_lua_suffix}-${CMAKE_MATCH_1}.${CMAKE_MATCH_2} + ) + + # LuaJIT hides itself as Lua lib (maintaining ABI compat) + list(APPEND _${_prefix}_library_names + lua${CMAKE_MATCH_1}${CMAKE_MATCH_2} + lua${CMAKE_MATCH_1}.${CMAKE_MATCH_2} + lua.${CMAKE_MATCH_1}.${CMAKE_MATCH_2} + lua-${CMAKE_MATCH_1}.${CMAKE_MATCH_2} + ) + endforeach () + + set(_${_prefix}_include_subdirs "${_${_prefix}_include_subdirs}" PARENT_SCOPE) + set(_${_prefix}_append_versions "${_${_prefix}_append_versions}" PARENT_SCOPE) + set(_${_prefix}_library_names "${_${_prefix}_library_names}" PARENT_SCOPE) +endfunction(_lua_set_version_vars)
\ No newline at end of file diff --git a/lib/sol2/cmake/Modules/FindLua/version_check.cmake b/lib/sol2/cmake/Modules/FindLua/version_check.cmake new file mode 100644 index 0000000..fa62f43 --- /dev/null +++ b/lib/sol2/cmake/Modules/FindLua/version_check.cmake @@ -0,0 +1,28 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +# Provides a common-mechanic for extracting Lua versions from Lua/LuaJIT headers +macro(_lua_check_header_version _header_file _prefix) + # At least 5.[012] have different ways to express the version + # so all of them need to be tested. Lua 5.2 defines LUA_VERSION + # and LUA_RELEASE as joined by the C preprocessor, so avoid those. + file(STRINGS "${_header_file}" lua_version_strings + REGEX "^#define[ \t]+LUA_(RELEASE[ \t]+\"Lua [0-9]|VERSION([ \t]+\"Lua [0-9]|_[MR])).*") + + string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MAJOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" ${_prefix}_VERSION_MAJOR ";${lua_version_strings};") + if (${_prefix}_VERSION_MAJOR MATCHES "^[0-9]+$") + string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MINOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" "${_prefix}_VERSION_MINOR" ";${lua_version_strings};") + string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_RELEASE[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" "${_prefix}_VERSION_PATCH" ";${lua_version_strings};") + set(${_prefix}_VERSION_STRING "${${_prefix}_VERSION_MAJOR}.${${_prefix}_VERSION_MINOR}.${${_prefix}_VERSION_PATCH}") + else () + string(REGEX REPLACE ".*;#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" ${_prefix}_VERSION_STRING ";${lua_version_strings};") + if (NOT LUA_VERSION_STRING MATCHES "^[0-9.]+$") + string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" ${_prefix}_VERSION_STRING ";${lua_version_strings};") + endif () + string(REGEX REPLACE "^([0-9]+)\\.[0-9.]*$" "\\1" ${_prefix}_VERSION_MAJOR "${${_prefix}_VERSION_STRING}") + string(REGEX REPLACE "^[0-9]+\\.([0-9]+)[0-9.]*$" "\\1" ${_prefix}_VERSION_MINOR "${${_prefix}_VERSION_STRING}") + string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]).*" "\\1" ${_prefix}_VERSION_PATCH "${${_prefix}_VERSION_STRING}") + endif () + + unset(lua_version_strings) +endmacro(_lua_check_header_version)
\ No newline at end of file |