From ad19e35a5fa25c2f3ced2fbf78d08600c99bcf0e Mon Sep 17 00:00:00 2001 From: mathusummut Date: Fri, 29 Mar 2019 01:07:58 +0100 Subject: [PATCH] Added FindLUA and CurlGetConfig --- mk/cmake/Modules/CurlGetConfig.cmake | 63 +++++++++ mk/cmake/Modules/FindLUA.cmake | 195 +++++++++++++++++++++++++++ 2 files changed, 258 insertions(+) create mode 100644 mk/cmake/Modules/CurlGetConfig.cmake create mode 100644 mk/cmake/Modules/FindLUA.cmake diff --git a/mk/cmake/Modules/CurlGetConfig.cmake b/mk/cmake/Modules/CurlGetConfig.cmake new file mode 100644 index 000000000..22e3a0c83 --- /dev/null +++ b/mk/cmake/Modules/CurlGetConfig.cmake @@ -0,0 +1,63 @@ +# +# Curl Get Config +# +# IF we are using a system that supports curl-config use it. +# + +IF(CURL_FOUND) + IF(UNIX) + IF(UNIX AND APPLE AND NOT CMAKE_CURL_CONFIG) + FIND_PROGRAM(CMAKE_CURL_CONFIG curl-config + PATHS /opt/local + PATH_SUFFIXES bin NO_DEFAULT_PATH) + ENDIF() + IF(NOT CMAKE_CURL_CONFIG) + FIND_PROGRAM(CMAKE_CURL_CONFIG curl-config + PATHS + ~/Library/Frameworks + /Library/Frameworks + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt + PATH_SUFFIXES bin) + ENDIF() + MARK_AS_ADVANCED(CMAKE_CURL_CONFIG) + + IF(CMAKE_CURL_CONFIG) + IF(STATIC_CURL) + # run the curl-config program to get --static-libs + execute_process(COMMAND ${CMAKE_CURL_CONFIG} --static-libs + OUTPUT_VARIABLE CURL_STATIC_LIBS + RESULT_VARIABLE RET + OUTPUT_STRIP_TRAILING_WHITESPACE) + ELSE() + SET(RET 1) + ENDIF() + + IF(RET EQUAL 0 AND CURL_STATIC_LIBS) + MESSAGE(STATUS "curl-config: ${CMAKE_CURL_CONFIG}, #1 , using CURL static libs: [${CURL_STATIC_LIBS}]") + SET(CURL_LIBRARIES "-Bstatic ${CURL_STATIC_LIBS}") + ELSE() + execute_process(COMMAND ${CMAKE_CURL_CONFIG} --libs + OUTPUT_VARIABLE CURL_DYNAMIC_LIBS + RESULT_VARIABLE RET2 + OUTPUT_STRIP_TRAILING_WHITESPACE) + + IF(RET2 EQUAL 0 AND CURL_DYNAMIC_LIBS) + MESSAGE(STATUS "curl-config: ${CMAKE_CURL_CONFIG}, #2 RET = ${RET}, using CURL dynamic libs: ${CURL_DYNAMIC_LIBS}") + SET(CURL_LIBRARIES "${CURL_DYNAMIC_LIBS}") + ELSE() + MESSAGE(STATUS "curl-config: ${CMAKE_CURL_CONFIG}, #3 RET = ${RET}/${RET2}, using CURL libs found by cmake: ${CURL_LIBRARIES}") + ENDIF() + ENDIF() + ENDIF() + ENDIF() + IF(CURL_VERSION_STRING AND "${CURL_VERSION_STRING}" VERSION_LESS "${CURL_MIN_VERSION_MG}") + MESSAGE(STATUS "(please visit http://curl.haxx.se/libcurl/ to find a newer version)") + MESSAGE(FATAL_ERROR " CURL version = [${CURL_VERSION_STRING}] we require AT LEAST [7.16.4]") + ENDIF() +ELSE() + SET(CURL_LIBRARIES) + SET(CURL_INCLUDE_DIRS) +ENDIF() \ No newline at end of file diff --git a/mk/cmake/Modules/FindLUA.cmake b/mk/cmake/Modules/FindLUA.cmake new file mode 100644 index 000000000..f0ed387b2 --- /dev/null +++ b/mk/cmake/Modules/FindLUA.cmake @@ -0,0 +1,195 @@ +#.rst: +# FindLua +# ------- +# +# +# +# Locate Lua library This module defines +# +# :: +# +# LUA_FOUND - if false, do not try to link to Lua +# LUA_LIBRARIES - both lua and lualib +# LUA_INCLUDE_DIR - where to find lua.h +# LUA_VERSION_STRING - the version of Lua found +# LUA_VERSION_MAJOR - the major version of Lua +# LUA_VERSION_MINOR - the minor version of Lua +# LUA_VERSION_PATCH - the patch version of Lua +# +# +# +# Note that the expected include convention is +# +# :: +# +# #include "lua.h" +# +# and not +# +# :: +# +# #include +# +# This is because, the lua location is not standardized and may exist in +# locations other than lua/ + +#============================================================================= +# Copyright 2007-2009 Kitware, Inc. +# Copyright 2013 Rolf Eike Beer +# Copyright 2015 filux +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +unset(_lua_include_subdirs) +unset(_lua_library_names) + +IF("${FORCE_LUA_VERSION}" STREQUAL "OFF") + IF(DEFINED ALL_LUA_VERSIONS_IN_ORDER) + SET(LUA_VERSIONS5 "${ALL_LUA_VERSIONS_IN_ORDER}") + ELSE() + SET(LUA_VERSIONS5 5.3 5.2 5.1 5.0) + ENDIF() +ELSE() + SET(LUA_VERSIONS5 "${FORCE_LUA_VERSION}") +ENDIF() + +# this is a function only to have all the variables inside go away automatically +function(set_lua_version_vars) + if (Lua_FIND_VERSION_EXACT) + if (Lua_FIND_VERSION_COUNT GREATER 1) + set(lua_append_versions ${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}) + endif () + elseif (Lua_FIND_VERSION) + # once there is a different major version supported this should become a loop + if (NOT Lua_FIND_VERSION_MAJOR GREATER 5) + if (Lua_FIND_VERSION_COUNT EQUAL 1) + set(lua_append_versions ${LUA_VERSIONS5}) + else () + foreach (subver IN LISTS LUA_VERSIONS5) + if (NOT subver VERSION_LESS ${Lua_FIND_VERSION}) + list(APPEND lua_append_versions ${subver}) + endif () + endforeach () + endif () + endif () + else () + # once there is a different major version supported this should become a loop + set(lua_append_versions ${LUA_VERSIONS5}) + endif () + + foreach (ver IN LISTS lua_append_versions) + string(REGEX MATCH "^([0-9]+)\\.([0-9]+)$" _ver "${ver}") + list(APPEND _lua_include_subdirs + include/lua${CMAKE_MATCH_1}${CMAKE_MATCH_2} + include/lua${CMAKE_MATCH_1}.${CMAKE_MATCH_2} + include/lua-${CMAKE_MATCH_1}.${CMAKE_MATCH_2} + ) + IF(STATIC_LUA) + list(APPEND _lua_library_names + liblua${CMAKE_MATCH_1}${CMAKE_MATCH_2}.a + liblua${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.a + liblua-${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.a + lua${CMAKE_MATCH_1}${CMAKE_MATCH_2}.a + lua${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.a + lua-${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.a + ) + ENDIF() + list(APPEND _lua_library_names + lua${CMAKE_MATCH_1}${CMAKE_MATCH_2} + lua${CMAKE_MATCH_1}.${CMAKE_MATCH_2} + lua-${CMAKE_MATCH_1}.${CMAKE_MATCH_2} + ) + endforeach () + + set(_lua_include_subdirs "${_lua_include_subdirs}" PARENT_SCOPE) + set(_lua_library_names "${_lua_library_names}" PARENT_SCOPE) +endfunction(set_lua_version_vars) + +set_lua_version_vars() + +find_path(LUA_INCLUDE_DIR lua.h + HINTS + ENV LUA_DIR + PATH_SUFFIXES ${_lua_include_subdirs} include/lua include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) +unset(_lua_include_subdirs) + +IF(STATIC_LUA AND APPLE) + # at least in mac ports, static lib is without numbers in name + SET(_lua_library_names lua.a liblua.a ${_lua_library_names}) +ENDIF() + +find_library(LUA_LIBRARY + NAMES ${_lua_library_names} lua + HINTS + ENV LUA_DIR + PATH_SUFFIXES lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /sw + /opt/local + /opt/csw + /opt +) +unset(_lua_library_names) + +if (LUA_LIBRARY) + # include the math library for Unix + if (UNIX AND NOT APPLE AND NOT BEOS) + find_library(LUA_MATH_LIBRARY m) + set(LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}") + # For Windows and Mac, don't need to explicitly include the math library + else () + set(LUA_LIBRARIES "${LUA_LIBRARY}") + endif () +endif () + +if (LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h") + # 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 "${LUA_INCLUDE_DIR}/lua.h" 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" LUA_VERSION_MAJOR ";${lua_version_strings};") + if (LUA_VERSION_MAJOR MATCHES "^[0-9]+$") + string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_MINOR[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_MINOR ";${lua_version_strings};") + string(REGEX REPLACE ".*;#define[ \t]+LUA_VERSION_RELEASE[ \t]+\"([0-9])\"[ \t]*;.*" "\\1" LUA_VERSION_PATCH ";${lua_version_strings};") + set(LUA_VERSION_STRING "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}.${LUA_VERSION_PATCH}") + else () + string(REGEX REPLACE ".*;#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([0-9.]+)\"[ \t]*;.*" "\\1" LUA_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" LUA_VERSION_STRING ";${lua_version_strings};") + endif () + string(REGEX REPLACE "^([0-9]+)\\.[0-9.]*$" "\\1" LUA_VERSION_MAJOR "${LUA_VERSION_STRING}") + string(REGEX REPLACE "^[0-9]+\\.([0-9]+)[0-9.]*$" "\\1" LUA_VERSION_MINOR "${LUA_VERSION_STRING}") + string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]).*" "\\1" LUA_VERSION_PATCH "${LUA_VERSION_STRING}") + endif () + + unset(lua_version_strings) +endif() + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if +# all listed variables are TRUE +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua + REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR + VERSION_VAR LUA_VERSION_STRING) + +mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARY LUA_MATH_LIBRARY) \ No newline at end of file