Skip to content

Commit

Permalink
Merge pull request #193 from Wargus/topic/fix-compilations
Browse files Browse the repository at this point in the history
fix compilation with older versions of libstdc++ and libc++
  • Loading branch information
timfel authored Jul 15, 2021
2 parents 04d84f7 + c022e22 commit 7059ae7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 27 deletions.
60 changes: 46 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

project(war1gus)
cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.10)
cmake_policy(VERSION 3.10..3.20.2)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 17)

if(EXISTS ${WIN32_CMAKE_PREFIX_PATH})
list(APPEND CMAKE_PREFIX_PATH "${WIN32_CMAKE_PREFIX_PATH}")
Expand All @@ -41,29 +43,59 @@ set(war1tool_HDRS xmi2mid.h scale2x.h)
find_package(PNG REQUIRED)
find_package(ZLIB REQUIRED)

include_directories(${PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIRS})
set(war1tool_LIBS ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})

add_executable(war1tool ${war1tool_SRCS} ${war1tool_HDRS})
target_link_libraries(war1tool ${war1tool_LIBS})
install(TARGETS war1tool DESTINATION "bin")

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_GNUC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g -ggdb -std=c99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -ggdb -std=c++17")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g -ggdb")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -ggdb")
endif()

if (WIN32 AND MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE=1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")
set_target_properties(war1tool PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
if(WIN32 AND MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE=1)
else()
include(CheckCXXSourceCompiles)
set(FS_SRC "
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
int main(int argc, char **argv) {
fs::path p = fs::path(\".\");
if (fs::absolute(p).is_absolute()) {
return 0;
} else {
return 1;
}
}
")
check_cxx_source_compiles("${FS_SRC}" HAS_17_FS)
if(NOT HAS_17_FS)
set(CMAKE_REQUIRED_LIBRARIES stdc++fs)
check_cxx_source_compiles("${FS_SRC}" HAS_EXP_17_FS_WITH_STDC)
if(HAS_EXP_17_FS_WITH_STDC)
set(war1gus_LIBS ${war1gus_LIBS} stdc++fs)
set(war1tool_LIBS ${war1tool_LIBS} stdc++fs)
else()
set(CMAKE_REQUIRED_LIBRARIES c++fs)
check_cxx_source_compiles("${FS_SRC}" HAS_EXP_17_FS_WITH_CLIB)
if(HAS_EXP_17_FS_WITH_CLIB)
set(war1gus_LIBS ${war1gus_LIBS} c++fs)
set(war1tool_LIBS ${war1tool_LIBS} c++fs)
else()
message(FATAL_ERROR "I don't know how to compile with C++17 filesystem support on your system")
endif()
endif()
endif()
endif()

if(WIN32 AND MSVC AND NOT CMAKE_PREFIX_PATH)
# use a default
set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../dependencies)
endif()

include_directories(${PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIRS})
set(war1tool_LIBS ${war1tool_LIBS} ${PNG_LIBRARIES} ${ZLIB_LIBRARIES})

add_executable(war1tool ${war1tool_SRCS} ${war1tool_HDRS})
target_link_libraries(war1tool ${war1tool_LIBS})
install(TARGETS war1tool DESTINATION "bin")

# Launcher

find_package(Stratagus)
Expand Down
26 changes: 13 additions & 13 deletions war1tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1659,10 +1659,10 @@ void EncodeFLC(flcfile *file, const char *iflc, int speed, int stillImage, int u

// delete the last png, it's the first frame again (for looping)
int last = -1;
std::filesystem::path last_png;
std::filesystem::directory_iterator videosDir(std::filesystem::path(Dir) / VIDEO_PATH);
fs::path last_png;
fs::directory_iterator videosDir(fs::path(Dir) / VIDEO_PATH);
std::regex pattern("[a-zA-Z0-9]+\\-([0-9]+)");
for(auto& direntry: std::filesystem::directory_iterator(std::filesystem::path(Dir) / VIDEO_PATH)) {
for(auto& direntry: fs::directory_iterator(fs::path(Dir) / VIDEO_PATH)) {
if (direntry.is_regular_file()) {
auto& direntry_path = direntry.path();
if (direntry_path.extension() == ".png") {
Expand All @@ -1679,11 +1679,11 @@ void EncodeFLC(flcfile *file, const char *iflc, int speed, int stillImage, int u
}
}
if (last >= 0) {
std::filesystem::remove(last_png);
fs::remove(last_png);
}

const char *to_video;
std::filesystem::path output = std::filesystem::path(Dir) / VIDEO_PATH / flc;
fs::path output = fs::path(Dir) / VIDEO_PATH / flc;
if (uncompressed) {
to_video =
"%s -y -r %d -i \"%s-%%04d.png\" -codec:v huffyuv "
Expand All @@ -1696,7 +1696,7 @@ void EncodeFLC(flcfile *file, const char *iflc, int speed, int stillImage, int u
"-vf scale=640:-1 \"%s\"";
output.replace_extension(".ogv");
}
std::filesystem::create_directories(output.parent_path());
fs::create_directories(output.parent_path());

cmdlen = strlen(to_video) + 1 /*fps*/ + strlen(encoder) + strlen(Dir) + strlen(flc) +
strlen(VIDEO_PATH) + output.string().size();
Expand All @@ -1719,15 +1719,15 @@ void EncodeFLC(flcfile *file, const char *iflc, int speed, int stillImage, int u
}
std::string stillFilename = stillFilenameStream.str();

std::filesystem::path output = std::filesystem::path(Dir) / GRAPHIC_PATH / flc;
fs::path output = fs::path(Dir) / GRAPHIC_PATH / flc;
output.replace_extension(".png");
std::filesystem::create_directories(output.parent_path());
std::filesystem::copy_file(stillFilename, output, std::filesystem::copy_options::overwrite_existing);
fs::create_directories(output.parent_path());
fs::copy_file(stillFilename, output, fs::copy_options::overwrite_existing);
}

for(auto& direntry: std::filesystem::directory_iterator(std::filesystem::path(Dir) / VIDEO_PATH)) {
for(auto& direntry: fs::directory_iterator(fs::path(Dir) / VIDEO_PATH)) {
if (direntry.is_regular_file() && direntry.path().extension() == ".png") {
std::filesystem::remove(direntry);
fs::remove(direntry);
}
}
}
Expand Down Expand Up @@ -3971,8 +3971,8 @@ int main(int argc, char** argv)
}

#ifdef WIN32
std::filesystem::path exepath(argv[0]);
exepath = std::filesystem::absolute(exepath);
fs::path exepath(argv[0]);
exepath = fs::absolute(exepath);
_wchdir(exepath.parent_path().wstring().c_str());
#endif

Expand Down

0 comments on commit 7059ae7

Please sign in to comment.