Fix find_package calls for CMake < 3.0

This commit is contained in:
Enno Rehling 2017-03-27 21:10:30 +02:00
parent f8d49e07af
commit a3cdfef668
4 changed files with 235 additions and 35 deletions

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.6)
cmake_minimum_required(VERSION 2.8)
if (WIN32)
FILE(TO_CMAKE_PATH "${CMAKE_MODULE_PATH}" CMAKE_MODULE_PATH )
FILE(TO_CMAKE_PATH "${CMAKE_PREFIX_PATH}" CMAKE_PREFIX_PATH )
@ -12,8 +12,10 @@ enable_testing()
find_package (LibXml2)
find_package (SQLite3)
find_package (Curses)
find_package (Lua REQUIRED)
find_package (ToLua REQUIRED)
find_package (Lua 5.1 REQUIRED)
if (LUA_FOUND)
find_package (ToLua "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}" EXACT REQUIRED)
endif(LUA_FOUND)
add_subdirectory (cJSON)
add_subdirectory (storage)

172
cmake/Modules/FindLua.cmake Normal file
View File

@ -0,0 +1,172 @@
#.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 <lua/lua.h>
#
# 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 <eike@sf-mail.de>
#
# 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)
# this is a function only to have all the variables inside go away automatically
function(set_lua_version_vars)
set(LUA_VERSIONS5 5.3 5.2 5.1 5.0)
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}
)
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}
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)
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)

View File

@ -1,37 +1,63 @@
# Copyright (C) 2007-2009 LuaDist.
# Created by Peter Kapec <kapecp@gmail.com>
# Redistribution and use of this file is allowed according to the terms of the MIT license.
# For details see the COPYRIGHT file distributed with LuaDist.
# Note:
# Searching headers and libraries is very simple and is NOT as powerful as scripts
# distributed with CMake, because LuaDist defines directories to search for.
# Everyone is encouraged to contact the author with improvements. Maybe this file
# becomes part of CMake distribution sometimes.
# - Find sqlite3
# Find the native SQLITE3 headers and libraries.
# - Try to find the SQLite3 library
# Once done this will define
#
# SQLITE3_INCLUDE_DIRS - where to find sqlite3.h, etc.
# SQLITE3_LIBRARIES - List of libraries when using sqlite.
# SQLITE3_FOUND - True if sqlite found.
# SQLITE3_FOUND - System has SQLite3
# SQLITE3_INCLUDE_DIR - The SQLite3 include directory
# SQLITE3_LIBRARIES - The libraries needed to use SQLite3
# SQLITE3_DEFINITIONS - Compiler switches required for using SQLite3
# SQLITE3_EXECUTABLE - The SQLite3 command line shell
# SQLITE3_VERSION_STRING - the version of SQLite3 found (since CMake 2.8.8)
# Look for the header file.
FIND_PATH(SQLITE3_INCLUDE_DIR NAMES sqlite3.h)
#=============================================================================
# Copyright 2006-2009 Kitware, Inc.
# Copyright 2006 Alexander Neundorf <neundorf@kde.org>
#
# 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.)
# Look for the library.
FIND_LIBRARY(SQLITE3_LIBRARY NAMES sqlite)
# use pkg-config to get the directories and then use these values
# in the find_path() and find_library() calls
find_package(PkgConfig QUIET)
PKG_CHECK_MODULES(PC_SQLITE QUIET sqlite3)
set(SQLITE3_DEFINITIONS ${PC_SQLITE_CFLAGS_OTHER})
# Handle the QUIETLY and REQUIRED arguments and set SQLITE3_FOUND to TRUE if all listed variables are TRUE.
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SQLITE3 DEFAULT_MSG SQLITE3_LIBRARY SQLITE3_INCLUDE_DIR)
find_path(SQLITE3_INCLUDE_DIR NAMES sqlite3.h
HINTS
${PC_SQLITE_INCLUDEDIR}
${PC_SQLITE_INCLUDE_DIRS}
)
# Copy the results to the output variables.
IF(SQLITE3_FOUND)
SET(SQLITE3_LIBRARIES ${SQLITE3_LIBRARY})
SET(SQLITE3_INCLUDE_DIRS ${SQLITE3_INCLUDE_DIR})
ELSE(SQLITE3_FOUND)
SET(SQLITE3_LIBRARIES)
SET(SQLITE3_INCLUDE_DIRS)
ENDIF(SQLITE3_FOUND)
find_library(SQLITE3_LIBRARIES NAMES sqlite3
HINTS
${PC_SQLITE_LIBDIR}
${PC_SQLITE_LIBRARY_DIRS}
)
MARK_AS_ADVANCED(SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES)
find_program(SQLITE3_EXECUTABLE sqlite3)
if(PC_SQLITE_VERSION)
set(SQLITE3_VERSION_STRING ${PC_SQLITE_VERSION})
elseif(SQLITE3_INCLUDE_DIR AND EXISTS "${SQLITE3_INCLUDE_DIR}/sqlite3.h")
file(STRINGS "${SQLITE3_INCLUDE_DIR}/sqlite3.h" sqlite3_version_str
REGEX "^#define[\t ]+SQLITE_VERSION[\t ]+\".*\"")
string(REGEX REPLACE "^#define[\t ]+SQLITE_VERSION[\t ]+\"([^\"]*)\".*" "\\1"
SQLITE3_VERSION_STRING "${sqlite3_version_str}")
unset(sqlite3_version_str)
endif()
# handle the QUIETLY and REQUIRED arguments and set SQLITE3_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SQLite3
REQUIRED_VARS SQLITE3_LIBRARIES SQLITE3_INCLUDE_DIR
VERSION_VAR SQLITE3_VERSION_STRING)
mark_as_advanced(SQLITE3_INCLUDE_DIR SQLITE3_LIBRARIES SQLITE3_EXECUTABLE)

View File

@ -10,6 +10,7 @@ ROOT=$(git rev-parse --show-toplevel)
MACHINE=`$CC -dumpmachine`
[ -z $MACHINE ] && MACHINE=`uname -m`
BIN_DIR="$ROOT/build-$MACHINE-$CC-$BUILD"
rm -rf $BIN_DIR
mkdir -p $BIN_DIR
rm -f $BUILD
ln -sf $BIN_DIR $BUILD
@ -31,7 +32,6 @@ fi
DEST=$(dirname $ROOT)/server
ARGS=" -DCMAKE_BUILD_TYPE=$BUILD \
-DCMAKE_LIBRARY_PATH=$LIBRARY_PATH \
-DCMAKE_INCLUDE_PATH=$INCLUDE_PATH \
-DCMAKE_PREFIX_PATH=$PREFIX_PATH \
-DCMAKE_INSTALL_PREFIX=$DEST"