Skip to content

Commit

Permalink
Tweaks for CMake/CLion builds
Browse files Browse the repository at this point in the history
Fix loading tiles with PREFIX set
Added TILES definitions to CMAKE for tiles builds
Added FindLua.cmake
  • Loading branch information
macrosblackd committed Jul 17, 2015
1 parent 3f1c109 commit c2e14f4
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 13 deletions.
25 changes: 16 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ option(LANGUAGES "Compile localization files for specified languages." ""
option(DYNAMIC_LINKING "Use dynamic linking. Or use static to remove MinGW dependency instead." "ON")
option(LUA_BINARY "Lua binary name or path. You can try use luajit for extra speed" "")
option(GIT_BINARY "Git binary name or path." "")
OPTION(PREFIX "Location of Data,GFX, & Lua directories" "")

include(GetGitRevisionDescription)
git_describe(GIT_VERSION)
Expand Down Expand Up @@ -74,7 +75,7 @@ include(CheckCXXCompilerFlag)
IF (NOT DYNAMIC_LINKING)
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.dll.a")
SET(BUILD_SHARED_LIBRARIES OFF)
check_cxx_compiler_flag (-static HAVE_STATIC_FLAG)
#check_cxx_compiler_flag (-static HAVE_STATIC_FLAG)
IF(HAVE_STATIC_FLAG)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
ENDIF(HAVE_STATIC_FLAG)
Expand All @@ -88,14 +89,15 @@ IF (NOT DYNAMIC_LINKING)
ELSE (NOT DYNAMIC_LINKING)
IF(MINGW)
# Avoid depending on MinGW runtime DLLs
check_cxx_compiler_flag (-static-libgcc HAVE_STATIC_LIBGCC_FLAG)
IF(HAVE_STATIC_LIBGCC_FLAG)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
ENDIF(HAVE_STATIC_LIBGCC_FLAG)
check_cxx_compiler_flag (-static-libstdc++ HAVE_STATIC_LIBSTDCXX_FLAG)
IF(HAVE_STATIC_LIBSTDCXX_FLAG)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
ENDIF(HAVE_STATIC_LIBSTDCXX_FLAG)
SET(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
#check_cxx_compiler_flag (-static-libgcc HAVE_STATIC_LIBGCC_FLAG)
#IF(HAVE_STATIC_LIBGCC_FLAG)
# SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
#ENDIF(HAVE_STATIC_LIBGCC_FLAG)
#check_cxx_compiler_flag (-static-libstdc++ HAVE_STATIC_LIBSTDCXX_FLAG)
#IF(HAVE_STATIC_LIBSTDCXX_FLAG)
# SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
#ENDIF(HAVE_STATIC_LIBSTDCXX_FLAG)
ENDIF(MINGW)
ENDIF (NOT DYNAMIC_LINKING)

Expand Down Expand Up @@ -167,6 +169,10 @@ ELSE (GIT_BINARY)
ENDIF (NOT GIT_FOUND)
ENDIF (GIT_BINARY)

IF (PREFIX)
ADD_DEFINITIONS(-DPREFIX=${PREFIX})
ENDIF (PREFIX)

# Set build types and display info
MESSAGE(STATUS "DYNAMIC_LINKING : ${DYNAMIC_LINKING}\n")
IF(RELEASE)
Expand Down Expand Up @@ -276,6 +282,7 @@ IF(TILES)
"This project requires SDL2_image to be installed to be compiled in graphical mode. Please install the SDL2_image development libraries, or try compiling without the -DTILES=1 for a text only compilation.\nSee INSTALL file for details and more info\n"
)
ENDIF(NOT SDL2_IMAGE_FOUND)
ADD_DEFINITIONS(-DTILES -DSDLTILES)
ENDIF(TILES)

IF(CURSES)
Expand Down
117 changes: 117 additions & 0 deletions CMakeModules/FindLua.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Locate Lua library
# This module defines
# LUA_EXECUTABLE, if found
# LUA_FOUND, if false, do not try to link to Lua
# LUA_LIBRARIES
# LUA_INCLUDE_DIR, where to find lua.h
# LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8)
#
# 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.
# Modified to support Lua 5.2 by LuaDist 2012
#
# 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.)
#
# The required version of Lua can be specified using the
# standard syntax, e.g. FIND_PACKAGE(Lua 5.1)
# Otherwise the module will search for any available Lua implementation

# Always search for non-versioned lua first (recommended)
SET(_POSSIBLE_LUA_INCLUDE include include/lua)
SET(_POSSIBLE_LUA_EXECUTABLE lua)
SET(_POSSIBLE_LUA_LIBRARY lua)

# Determine possible naming suffixes (there is no standard for this)
IF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR)
SET(_POSSIBLE_SUFFIXES "${Lua_FIND_VERSION_MAJOR}${Lua_FIND_VERSION_MINOR}" "${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}" "-${Lua_FIND_VERSION_MAJOR}.${Lua_FIND_VERSION_MINOR}")
ELSE(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR)
SET(_POSSIBLE_SUFFIXES "52" "5.2" "-5.2" "51" "5.1" "-5.1")
ENDIF(Lua_FIND_VERSION_MAJOR AND Lua_FIND_VERSION_MINOR)

# Set up possible search names and locations
FOREACH(_SUFFIX ${_POSSIBLE_SUFFIXES})
LIST(APPEND _POSSIBLE_LUA_INCLUDE "include/lua${_SUFFIX}")
LIST(APPEND _POSSIBLE_LUA_EXECUTABLE "lua${_SUFFIX}")
LIST(APPEND _POSSIBLE_LUA_LIBRARY "lua${_SUFFIX}")
ENDFOREACH(_SUFFIX)

# Find the lua executable
FIND_PROGRAM(LUA_EXECUTABLE
NAMES ${_POSSIBLE_LUA_EXECUTABLE}
)

# Find the lua header
FIND_PATH(LUA_INCLUDE_DIR lua.h
HINTS
$ENV{LUA_DIR}
PATH_SUFFIXES ${_POSSIBLE_LUA_INCLUDE}
PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
)

# Find the lua library
FIND_LIBRARY(LUA_LIBRARY
NAMES ${_POSSIBLE_LUA_LIBRARY}
HINTS
$ENV{LUA_DIR}
PATH_SUFFIXES lib64 lib
PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw
/opt/local
/opt/csw
/opt
)

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)

# Determine Lua version
IF(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
FILE(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"")

STRING(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}")
UNSET(lua_version_str)
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_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY LUA_EXECUTABLE)
2 changes: 1 addition & 1 deletion src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ int cata_tiles::load_tileset(std::string path, int R, int G, int B)
{
std::string img_path = path;
#ifdef PREFIX // use the PREFIX path over the current directory
img_path = (FILENAMES["datadir"] + "/" + img_path);
img_path = (FILENAMES["base_path"] + "/" + img_path);
#endif
/** reinit tile_atlas */
SDL_Surface *tile_atlas = IMG_Load(img_path.c_str());
Expand Down
6 changes: 3 additions & 3 deletions src/path_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ void PATH_INFO::set_standard_filenames(void)
{
// Special: data_dir lua_dir and gfx_dir
if (!FILENAMES["base_path"].empty()) {
update_pathname("datadir", FILENAMES["base_path"] + "share/cataclysm-dda/");
update_pathname("gfxdir", FILENAMES["datadir"] + "gfx/");
update_pathname("luadir", FILENAMES["datadir"] + "lua/");
update_pathname("datadir", FILENAMES["base_path"] + "data/");
update_pathname("gfxdir", FILENAMES["base_path"] + "gfx/");
update_pathname("luadir", FILENAMES["base_path"] +"lua/");
} else {
update_pathname("datadir", "data/");
update_pathname("gfxdir", "gfx/");
Expand Down

0 comments on commit c2e14f4

Please sign in to comment.