From 82439d6ca2211c4c80c50beee8ac198094510982 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Sun, 15 May 2011 16:19:41 -0300 Subject: [PATCH] cmake changes for cross compiling --- CMakeLists.txt | 4 ++-- cmake/FindGMP.cmake | 27 ++++++--------------- cmake/FindLua51.cmake | 44 ++++++++++++++++++++++++++++++++++ cmake/FindPhysFS.cmake | 31 ++++++++++++++++++++++++ cmake/FindYamlCpp.cmake | 45 +++++++---------------------------- cmake/cmake-mingw32-toolchain | 3 ++- 6 files changed, 95 insertions(+), 59 deletions(-) create mode 100644 cmake/FindLua51.cmake create mode 100644 cmake/FindPhysFS.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c5d6b0fe..a78da57f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(otclient) +# setup custom cmake modules path SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}") # find needed packages @@ -26,7 +27,6 @@ IF(CMAKE_COMPILER_IS_GNUCXX) SET(CMAKE_CXX_FLAGS_DEBUG "-O1 -g -ggdb -fno-inline") SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wl,-s") SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") - SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -Wl,--as-needed") ENDIF(CMAKE_COMPILER_IS_GNUCXX) INCLUDE_DIRECTORIES( @@ -131,6 +131,6 @@ TARGET_LINK_LIBRARIES(otclient ${LUA_LIBRARIES} ${YAMLCPP_LIBRARY} ${PHYSFS_LIBRARY} - ${GMP_LIBRARIES} + ${GMP_LIBRARY} ${ZLIB_LIBRARY} ${ADDITIONAL_LIBRARIES}) diff --git a/cmake/FindGMP.cmake b/cmake/FindGMP.cmake index 17d175c6..a8686c1e 100644 --- a/cmake/FindGMP.cmake +++ b/cmake/FindGMP.cmake @@ -1,23 +1,10 @@ # Try to find the GMP librairies -# GMP_FOUND - system has GMP lib +# GMP_FOUND - system has GMP # GMP_INCLUDE_DIR - the GMP include directory -# GMP_LIBRARIES - Libraries needed to use GMP +# GMP_LIBRARY - the GMP library -# Copyright (c) 2006, Laurent Montel, -# -# Redistribution and use is allowed according to the terms of the BSD license. -# For details see the accompanying COPYING-CMAKE-SCRIPTS file. - - -if (GMP_INCLUDE_DIR AND GMP_LIBRARIES) - # Already in cache, be silent - set(GMP_FIND_QUIETLY TRUE) -endif (GMP_INCLUDE_DIR AND GMP_LIBRARIES) - -find_path(GMP_INCLUDE_DIR NAMES gmp.h ) -find_library(GMP_LIBRARIES NAMES gmp libgmp) - -include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(GMP DEFAULT_MSG GMP_INCLUDE_DIR GMP_LIBRARIES) - -mark_as_advanced(GMP_INCLUDE_DIR GMP_LIBRARIES) +FIND_PATH(GMP_INCLUDE_DIR NAMES gmp.h) +FIND_LIBRARY(GMP_LIBRARY NAMES libgmp.a gmp) +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GMP DEFAULT_MSG GMP_LIBRARY GMP_INCLUDE_DIR) +MARK_AS_ADVANCED(GMP_LIBRARY GMP_INCLUDE_DIR) diff --git a/cmake/FindLua51.cmake b/cmake/FindLua51.cmake new file mode 100644 index 00000000..b66a35a2 --- /dev/null +++ b/cmake/FindLua51.cmake @@ -0,0 +1,44 @@ +# Locate Lua library +# This module defines +# LUA51_FOUND, if false, do not try to link to Lua +# LUA_LIBRARIES +# LUA_INCLUDE_DIR, where to find lua.h +# +# 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. +# +# 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.) + +FIND_PATH(LUA_INCLUDE_DIR NAMES lua.h PATH_SUFFIXES lua51 lua5.1) +FIND_LIBRARY(LUA_LIBRARY NAMES liblua51.a liblua5.1.a liblua-5.1.a liblua.a lua51 lua5.1 lua-5.1 lua) + +IF(LUA_LIBRARY) + # include the math library for Unix + IF(UNIX AND NOT APPLE) + FIND_LIBRARY(LUA_MATH_LIBRARY m) + SET( LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries") + # For Windows and Mac, don't need to explicitly include the math library + ELSE(UNIX AND NOT APPLE) + SET( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries") + ENDIF(UNIX AND NOT APPLE) +ENDIF(LUA_LIBRARY) + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua51 DEFAULT_MSG LUA_LIBRARIES LUA_INCLUDE_DIR) +MARK_AS_ADVANCED(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY) + diff --git a/cmake/FindPhysFS.cmake b/cmake/FindPhysFS.cmake new file mode 100644 index 00000000..e7a5e9b8 --- /dev/null +++ b/cmake/FindPhysFS.cmake @@ -0,0 +1,31 @@ +# Locate PhysFS library +# This module defines +# PHYSFS_LIBRARY, the name of the library to link against +# PHYSFS_FOUND, if false, do not try to link to PHYSFS +# PHYSFS_INCLUDE_DIR, where to find physfs.h +# +# $PHYSFSDIR is an environment variable that would +# correspond to the ./configure --prefix=$PHYSFSDIR +# used in building PHYSFS. +# +# Created by Eric Wing. + +#============================================================================= +# Copyright 2005-2009 Kitware, Inc. +# +# 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.) + +FIND_PATH(PHYSFS_INCLUDE_DIR physfs.h PATH_SUFFIXES physfs) +FIND_LIBRARY(PHYSFS_LIBRARY NAMES libphysfs.a physfs) +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(PhysFS DEFAULT_MSG PHYSFS_LIBRARY PHYSFS_INCLUDE_DIR) +MARK_AS_ADVANCED(PHYSFS_LIBRARY PHYSFS_INCLUDE_DIR) + diff --git a/cmake/FindYamlCpp.cmake b/cmake/FindYamlCpp.cmake index ab2f846c..e2b40709 100644 --- a/cmake/FindYamlCpp.cmake +++ b/cmake/FindYamlCpp.cmake @@ -1,37 +1,10 @@ -# - Try to find yaml-cpp -# Once done, this will define -# -# YAMLCPP_LIBRARY, link these to use yaml-cpp -# YAMLCPP_FOUND - system has yaml-cpp -# YAMLCPP_INCLUDE_DIR, the yaml-cpp include directories +# Try to find yaml-cpp +# YAMLCPP_FOUND - system has yaml-cpp +# YAMLCPP_INCLUDE_DIR - the yaml-cpp include directory +# YAMLCPP_LIBRARY - the yaml-cpp library -FIND_PATH(YAMLCPP_INCLUDE_DIR yaml-cpp/yaml.h -HINTS -PATH_SUFFIXES include/yaml-cpp include -PATHS -~/Library/Frameworks -/Library/Frameworks -/usr/local -/usr -/sw # Fink -/opt/local # DarwinPorts -/opt/csw # Blastwave -/opt -) - -FIND_LIBRARY(YAMLCPP_LIBRARY -NAMES yaml-cpp -PATH_SUFFIXES lib64 lib -PATHS -~/Library/Frameworks -/Library/Frameworks -/usr/local -/usr -/sw -/opt/local -/opt/csw -/opt -) - -INCLUDE("${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake") -FIND_PACKAGE_HANDLE_STANDARD_ARGS(YamlCpp DEFAULT_MSG YAMLCPP_LIBRARY YAMLCPP_INCLUDE_DIR) \ No newline at end of file +FIND_PATH(YAMLCPP_INCLUDE_DIR NAMES yaml.h PATH_SUFFIXES yaml-cpp) +FIND_LIBRARY(YAMLCPP_LIBRARY NAMES libyaml-cpp.a yaml-cpp) +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(YamlCpp DEFAULT_MSG YAMLCPP_LIBRARY YAMLCPP_INCLUDE_DIR) +MARK_AS_ADVANCED(YAMLCPP_LIBRARY YAMLCPP_INCLUDE_DIR) \ No newline at end of file diff --git a/cmake/cmake-mingw32-toolchain b/cmake/cmake-mingw32-toolchain index 45e3467d..434243a2 100644 --- a/cmake/cmake-mingw32-toolchain +++ b/cmake/cmake-mingw32-toolchain @@ -5,4 +5,5 @@ SET(CMAKE_RC_COMPILER i486-mingw32-windres) SET(CMAKE_FIND_ROOT_PATH /usr/i486-mingw32) SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) \ No newline at end of file +SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -static-libgcc -static-libstdc++") \ No newline at end of file