Skip to content

Commit

Permalink
Use GNU paths on linux
Browse files Browse the repository at this point in the history
CorsixTH now looks for data files in a directory specified in CMake.
On unix systems (other than apple) GNU paths are now used.
  • Loading branch information
TheCycoONE committed Feb 1, 2018
1 parent f9f2720 commit a58814c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 45 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Expand Up @@ -116,6 +116,8 @@ if(USE_PRECOMPILED_DEPS)
include(PrecompiledDeps)
endif()

include(GNUInstallDirs)

# Include individual projects
message("")
# We always build CorsixTH otherwise we would miss the generated header
Expand Down
31 changes: 22 additions & 9 deletions CorsixTH/CMakeLists.txt
Expand Up @@ -14,6 +14,17 @@ elseif(MSVC)
add_definitions(/D "_BIND_TO_CURRENT_VCLIBS_VERSION=1")
endif()

if(MSVC)
set(CORSIX_TH_DATADIR CorsixTH)
set(CORSIX_TH_INTERPRETER_PATH CorsixTH.lua)
elseif(APPLE)
set(CORSIX_TH_DATADIR ${FULL_PRODUCT_NAME}/Contents/Resources/)
set(CORSIX_TH_INTERPRETER_PATH ${CORSIX_TH_DATADIR}/CorsixTH.lua)
else()
set(CORSIX_TH_DATADIR ${CMAKE_INSTALL_DATADIR}/corsix-th)
set(CORSIX_TH_INTERPRETER_PATH ${CMAKE_INSTALL_FULL_DATADIR}/corsix-th/CorsixTH.lua)
endif()

# Modify the config.h based upon our selection of options
configure_file(${CMAKE_SOURCE_DIR}/CorsixTH/Src/config.h.in ${CMAKE_BINARY_DIR}/CorsixTH/Src/config.h)
include_directories(${CMAKE_BINARY_DIR}/CorsixTH/Src/)
Expand All @@ -39,8 +50,6 @@ file(GLOB_RECURSE corsixth_source_files

# Declaration of the executable
if(APPLE)
add_definitions(-DIS_CORSIXTH_APP)

set(corsixth_icon_file ${CMAKE_SOURCE_DIR}/CorsixTH/Icon.icns)
set_source_files_properties(
${corsixth_icon_file}
Expand All @@ -57,8 +66,8 @@ if(APPLE)
#Add an extra step at the end of the build process to copy the resources into the bundle.
add_custom_command(TARGET CorsixTH
POST_BUILD
COMMAND rsync -rv --include-from ${CMAKE_SOURCE_DIR}/CorsixTH/RequiredResources.txt ${CMAKE_SOURCE_DIR}/CorsixTH/ \${TARGET_BUILD_DIR}/\${FULL_PRODUCT_NAME}/Contents/MacOS
COMMAND rsync -rv ${CMAKE_SOURCE_DIR}/CorsixTH/Icon.icns \${TARGET_BUILD_DIR}/\${FULL_PRODUCT_NAME}/Contents/Resources/
COMMAND rsync -rv --include-from ${CMAKE_SOURCE_DIR}/CorsixTH/RequiredResources.txt ${CMAKE_SOURCE_DIR}/CorsixTH/ \${TARGET_BUILD_DIR}/\${CORSIX_TH_DATADIR}
COMMAND rsync -rv ${CMAKE_SOURCE_DIR}/CorsixTH/Icon.icns \${TARGET_BUILD_DIR}/\${CORSIX_TH_DATADIR}
)

target_link_libraries(CorsixTH SDL2main)
Expand Down Expand Up @@ -192,6 +201,7 @@ elseif(MSVC)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CorsixTH.vcxproj.user.in ${CMAKE_CURRENT_BINARY_DIR}/CorsixTH.vcxproj.user @ONLY)
endif()


# Declaration of the install process
if(APPLE)
#Just use the prefix as it's sufficient to just set the prefix to /Applications on Mac.
Expand All @@ -204,11 +214,14 @@ if(APPLE)
FIXUP_BUNDLE(${CMAKE_INSTALL_PREFIX}/CorsixTH.app \"\" \"\")
")
else()
install(TARGETS CorsixTH RUNTIME DESTINATION CorsixTH)
install(DIRECTORY Campaigns Lua Levels DESTINATION CorsixTH)
install(DIRECTORY Bitmap DESTINATION CorsixTH
if(MSVC)
install(TARGETS CorsixTH RUNTIME DESTINATION ${CORSIX_TH_DATADIR})
else()
install(TARGETS CorsixTH RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
install(DIRECTORY Campaigns Lua Levels DESTINATION ${CORSIX_TH_DATADIR})
install(DIRECTORY Bitmap DESTINATION ${CORSIX_TH_DATADIR}
FILES_MATCHING REGEX ".*\\.(tab|pal|dat|png)$"
PATTERN "*.svn" EXCLUDE
)
install(FILES CorsixTH.lua ../LICENSE.txt CorsixTH.ico DESTINATION CorsixTH )
install(FILES CorsixTH.lua ../LICENSE.txt CorsixTH.ico DESTINATION ${CORSIX_TH_DATADIR})
endif()
2 changes: 2 additions & 0 deletions CorsixTH/Src/config.h.in
Expand Up @@ -23,6 +23,8 @@ SOFTWARE.
#ifndef CORSIX_TH_CONFIG_H_
#define CORSIX_TH_CONFIG_H_

#cmakedefine CORSIX_TH_INTERPRETER_PATH "@CORSIX_TH_INTERPRETER_PATH@"

/** Windows Platform SDK usage **/
// When compiling on Windows, the platform SDK should be used. However, when
// using the SDL rendering engine, the platform SDK is not used for anything
Expand Down
40 changes: 4 additions & 36 deletions CorsixTH/Src/main.cpp
Expand Up @@ -128,46 +128,14 @@ int CorsixTH_lua_main_no_eval(lua_State *L)
}
}

// Code to try several variations on finding CorsixTH.lua:
// CorsixTH.lua
// CorsixTH/CorsixTH.lua
// ../CorsixTH.lua
// ../CorsixTH/CorsixTH.lua
// ../../CorsixTH.lua
// ../../CorsixTH/CorsixTH.lua
// ../../../CorsixTH.lua
// ../../../CorsixTH/CorsixTH.lua
// It is simpler to write this in Lua than in C.
const char sLuaCorsixTHLua[] =
"local name, sep, code = \"CorsixTH.lua\", package.config:sub(1, 1)\n"
"local root = (... or \"\"):match(\"^(.*[\"..sep..\"])\") or \"\"\n"
#ifdef __APPLE__ // Darrell: Search inside the bundle first.
// There's probably a better way of doing this.
#if defined(IS_CORSIXTH_APP)
"code = loadfile(\"CorsixTH.app/Contents/Resources/\"..name)\n"
"if code then return code end\n"
#endif
#endif
"for num_dotdot = 0, 3 do\n"
" for num_dir = 0, 1 do\n"
" code = loadfile(root..(\"..\"..sep):rep(num_dotdot)..\n"
" (\"CorsixTH\"..sep):rep(num_dir)..name)\n"
" if code then return code end \n"
" end \n"
"end \n"
"return loadfile(name)";

// return assert(loadfile"CorsixTH.lua")(...)
if(!bGotScriptFile)
{
lua_getglobal(L, "assert");
luaL_loadbuffer(L, sLuaCorsixTHLua, std::strlen(sLuaCorsixTHLua),
"@main.cpp (l_main bootstrap)");
if(lua_gettop(L) == 2)
lua_pushnil(L);
else
lua_pushvalue(L, 1);
lua_getglobal(L, "loadfile");
lua_pushstring(L, CORSIX_TH_INTERPRETER_PATH);
bGotScriptFile = true;
}

lua_call(L, 1, 2);
lua_call(L, 2, 1);
lua_insert(L, 1);
Expand Down

0 comments on commit a58814c

Please sign in to comment.