From 8a5f397f266db179cf504664229a5d03b304ffbb Mon Sep 17 00:00:00 2001 From: a dinosaur Date: Wed, 7 Sep 2022 00:11:11 +1000 Subject: [PATCH] MSVC build fix & buildsystem overhaul --- .gitignore | 11 +- CMakeLists.txt | 57 ++--- README.md | 2 +- ext/base64/CMakeLists.txt | 5 + {src => ext/base64}/base64.cpp | 0 {inc => ext/base64}/base64.h | 0 ext/miniz/CMakeLists.txt | 4 + {inc => ext/miniz}/miniz.h | 0 ext/rapidxml/CMakeLists.txt | 4 + {inc => ext}/rapidxml/license.txt | 0 {inc => ext}/rapidxml/rapidxml.hpp | 0 {inc => ext}/rapidxml/rapidxml_iterators.hpp | 0 {inc => ext}/rapidxml/rapidxml_print.hpp | 0 {inc => ext}/rapidxml/rapidxml_utils.hpp | 0 ext/ultragetopt/CMakeLists.txt | 22 ++ {src => ext/ultragetopt}/ultragetopt.c | 0 {inc => ext/ultragetopt}/ultragetopt.h | 0 src/CMakeLists.txt | 11 + src/XGetopt.cpp | 212 ------------------- src/tmx2gba.cpp | 2 +- src/tmxlayer.cpp | 2 +- src/tmxobject.cpp | 2 +- src/tmxreader.cpp | 4 +- src/tmxreader.h | 2 +- src/tmxtileset.cpp | 2 +- tmx2gba.sln | 22 -- tmx2gba.vcxproj | 93 -------- tmx2gba.vcxproj.filters | 75 ------- 28 files changed, 85 insertions(+), 447 deletions(-) create mode 100644 ext/base64/CMakeLists.txt rename {src => ext/base64}/base64.cpp (100%) rename {inc => ext/base64}/base64.h (100%) create mode 100644 ext/miniz/CMakeLists.txt rename {inc => ext/miniz}/miniz.h (100%) create mode 100644 ext/rapidxml/CMakeLists.txt rename {inc => ext}/rapidxml/license.txt (100%) rename {inc => ext}/rapidxml/rapidxml.hpp (100%) rename {inc => ext}/rapidxml/rapidxml_iterators.hpp (100%) rename {inc => ext}/rapidxml/rapidxml_print.hpp (100%) rename {inc => ext}/rapidxml/rapidxml_utils.hpp (100%) create mode 100644 ext/ultragetopt/CMakeLists.txt rename {src => ext/ultragetopt}/ultragetopt.c (100%) rename {inc => ext/ultragetopt}/ultragetopt.h (100%) create mode 100644 src/CMakeLists.txt delete mode 100644 src/XGetopt.cpp delete mode 100644 tmx2gba.sln delete mode 100644 tmx2gba.vcxproj delete mode 100644 tmx2gba.vcxproj.filters diff --git a/.gitignore b/.gitignore index b65c3f4..b429a02 100644 --- a/.gitignore +++ b/.gitignore @@ -27,7 +27,7 @@ *.out *.app -# VS rubbish. +# VS rubbish Debug/ Release/ *.opensdf @@ -35,7 +35,14 @@ Release/ *.v12.suo *.vcxproj.user -# Some files I used for testing. +# CLion Rubbish +.idea/ + +# CMake Rubbish +build/ +cmake-build-*/ + +# Some files I used for testing *.tmx *.raw plains.png diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d0dfdd..d2acd86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,42 +1,29 @@ -# tmx2gba - CMakeLists.txt -# Copyright (C) 2018 Nicholas Curtis (a dinosaur) -# -# This software is provided 'as-is', without any express or implied -# warranty. In no event will the authors be held liable for any damages -# arising from the use of this software. -# -# Permission is granted to anyone to use this software for any purpose, -# including commercial applications, and to alter it and redistribute it -# freely, subject to the following restrictions: -# -# 1. The origin of this software must not be misrepresented; you must not -# claim that you wrote the original software. If you use this software -# in a product, an acknowledgment in the product documentation would be -# appreciated but is not required. -# 2. Altered source versions must be plainly marked as such, and must not be -# misrepresented as being the original software. -# 3. This notice may not be removed or altered from any source distribution. - -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.1 FATAL_ERROR) project(tmx2gba) +# C++11 & C99 set(CMAKE_CXX_STANDARD 11) +set(CMAKE_C_STANDARD 99) -include_directories(inc) -set(SOURCES - src/tmx2gba.cpp - src/tmxlayer.cpp src/tmxlayer.h - src/tmxobject.cpp src/tmxobject.h - src/tmxreader.cpp src/tmxreader.h - src/tmxtileset.cpp src/tmxtileset.h +# Enable strong warnings +if (MSVC) + string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(REPLACE "/W3" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") +else() + add_compile_options(-Wall) +endif() - src/ultragetopt.c inc/ultragetopt.h - src/base64.cpp inc/base64.h - inc/miniz.h +# Libraries +add_subdirectory(ext/base64) +add_subdirectory(ext/miniz) +add_subdirectory(ext/rapidxml) +add_subdirectory(ext/ultragetopt) - inc/rapidxml/rapidxml.hpp - inc/rapidxml/rapidxml_iterators.hpp - inc/rapidxml/rapidxml_print.hpp - inc/rapidxml/rapidxml_utils.hpp) +# Main tmx2gba sources +add_subdirectory(src) -add_executable(tmx2gba ${SOURCES}) +if (MSVC) + # Default to tmx2gba as startup project when generating Solutions + set_property(DIRECTORY ${CMAKE_SOURCE_DIR} + PROPERTY VS_STARTUP_PROJECT tmx2gba) +endif() diff --git a/README.md b/README.md index db243f5..e5bbd98 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ sudo cp tmx2gba $DEVKITPRO/tools/bin/tmx2gba [ultragetopt](https://github.com/kevinoid/ultragetopt) is licensed under the MIT license. ``` - Copyright (C) 2015-2019 Nicholas Curtis (a dinosaur) + Copyright (C) 2015-2022 a dinosaur This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages diff --git a/ext/base64/CMakeLists.txt b/ext/base64/CMakeLists.txt new file mode 100644 index 0000000..e4b5ba6 --- /dev/null +++ b/ext/base64/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(base64 + base64.cpp base64.h) +add_library(External::base64 ALIAS base64) +target_include_directories(base64 + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/base64.cpp b/ext/base64/base64.cpp similarity index 100% rename from src/base64.cpp rename to ext/base64/base64.cpp diff --git a/inc/base64.h b/ext/base64/base64.h similarity index 100% rename from inc/base64.h rename to ext/base64/base64.h diff --git a/ext/miniz/CMakeLists.txt b/ext/miniz/CMakeLists.txt new file mode 100644 index 0000000..7e5d92a --- /dev/null +++ b/ext/miniz/CMakeLists.txt @@ -0,0 +1,4 @@ +add_library(miniz INTERFACE) +add_library(External::miniz ALIAS miniz) +target_include_directories(miniz + INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/inc/miniz.h b/ext/miniz/miniz.h similarity index 100% rename from inc/miniz.h rename to ext/miniz/miniz.h diff --git a/ext/rapidxml/CMakeLists.txt b/ext/rapidxml/CMakeLists.txt new file mode 100644 index 0000000..e72f336 --- /dev/null +++ b/ext/rapidxml/CMakeLists.txt @@ -0,0 +1,4 @@ +add_library(rapidxml INTERFACE) +add_library(External::rapidxml ALIAS rapidxml) +target_include_directories(rapidxml + INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/inc/rapidxml/license.txt b/ext/rapidxml/license.txt similarity index 100% rename from inc/rapidxml/license.txt rename to ext/rapidxml/license.txt diff --git a/inc/rapidxml/rapidxml.hpp b/ext/rapidxml/rapidxml.hpp similarity index 100% rename from inc/rapidxml/rapidxml.hpp rename to ext/rapidxml/rapidxml.hpp diff --git a/inc/rapidxml/rapidxml_iterators.hpp b/ext/rapidxml/rapidxml_iterators.hpp similarity index 100% rename from inc/rapidxml/rapidxml_iterators.hpp rename to ext/rapidxml/rapidxml_iterators.hpp diff --git a/inc/rapidxml/rapidxml_print.hpp b/ext/rapidxml/rapidxml_print.hpp similarity index 100% rename from inc/rapidxml/rapidxml_print.hpp rename to ext/rapidxml/rapidxml_print.hpp diff --git a/inc/rapidxml/rapidxml_utils.hpp b/ext/rapidxml/rapidxml_utils.hpp similarity index 100% rename from inc/rapidxml/rapidxml_utils.hpp rename to ext/rapidxml/rapidxml_utils.hpp diff --git a/ext/ultragetopt/CMakeLists.txt b/ext/ultragetopt/CMakeLists.txt new file mode 100644 index 0000000..15e1c0e --- /dev/null +++ b/ext/ultragetopt/CMakeLists.txt @@ -0,0 +1,22 @@ +include(CheckIncludeFile) +include(CheckFunctionExists) + +check_include_file(strings.h HAVE_STRINGS_H) +check_function_exists(strcasecmp HAVE_STRCASECMP) +check_function_exists(_stricmp HAVE__STRICMP) +check_function_exists(strncasecmp HAVE_STRNCASECMP) +check_function_exists(_strnicmp HAVE__STRNICMP) + +add_library(ultragetopt + ultragetopt.c ultragetopt.h) +add_library(External::ultragetopt ALIAS ultragetopt) + +target_include_directories(ultragetopt + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + +target_compile_definitions(ultragetopt PRIVATE + $<$:HAVE_STRINGS_H=1> + $<$:HAVE_STRCASECMP=1> + $<$:HAVE__STRICMP=1> + $<$:HAVE_STRNCASECMP=1> + $<$:HAVE__STRNICMP=1>) diff --git a/src/ultragetopt.c b/ext/ultragetopt/ultragetopt.c similarity index 100% rename from src/ultragetopt.c rename to ext/ultragetopt/ultragetopt.c diff --git a/inc/ultragetopt.h b/ext/ultragetopt/ultragetopt.h similarity index 100% rename from inc/ultragetopt.h rename to ext/ultragetopt/ultragetopt.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..32fde96 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,11 @@ +add_executable(tmx2gba + tmx2gba.cpp + tmxlayer.cpp tmxlayer.h + tmxobject.cpp tmxobject.h + tmxreader.cpp tmxreader.h + tmxtileset.cpp tmxtileset.h) +target_link_libraries(tmx2gba + External::base64 + External::miniz + External::rapidxml + External::ultragetopt) diff --git a/src/XGetopt.cpp b/src/XGetopt.cpp deleted file mode 100644 index aeee4a7..0000000 --- a/src/XGetopt.cpp +++ /dev/null @@ -1,212 +0,0 @@ -// XGetopt.cpp Version 1.2 -// -// Author: Hans Dietrich -// hdietrich2@hotmail.com -// -// Description: -// XGetopt.cpp implements getopt(), a function to parse command lines. -// -// History -// Version 1.2 - 2003 May 17 -// - Added Unicode support -// -// Version 1.1 - 2002 March 10 -// - Added example to XGetopt.cpp module header -// -// This software is released into the public domain. -// You are free to use it in any way you like. -// -// This software is provided "as is" with no expressed -// or implied warranty. I accept no liability for any -// damage or loss of business that this software may cause. -// -/////////////////////////////////////////////////////////////////////////////// - - -/////////////////////////////////////////////////////////////////////////////// -// if you are not using precompiled headers then include these lines: -#include -#include -/////////////////////////////////////////////////////////////////////////////// - - -#include "XGetopt.h" - - -/////////////////////////////////////////////////////////////////////////////// -// -// X G e t o p t . c p p -// -// -// NAME -// getopt -- parse command line options -// -// SYNOPSIS -// int getopt(int argc, char *argv[], char *optstring) -// -// extern char *optarg; -// extern int optind; -// -// DESCRIPTION -// The getopt() function parses the command line arguments. Its -// arguments argc and argv are the argument count and array as -// passed into the application on program invocation. In the case -// of Visual C++ programs, argc and argv are available via the -// variables __argc and __argv (double underscores), respectively. -// getopt returns the next option letter in argv that matches a -// letter in optstring. (Note: Unicode programs should use -// __targv instead of __argv. Also, all character and string -// literals should be enclosed in _T( ) ). -// -// optstring is a string of recognized option letters; if a letter -// is followed by a colon, the option is expected to have an argument -// that may or may not be separated from it by white space. optarg -// is set to point to the start of the option argument on return from -// getopt. -// -// Option letters may be combined, e.g., "-ab" is equivalent to -// "-a -b". Option letters are case sensitive. -// -// getopt places in the external variable optind the argv index -// of the next argument to be processed. optind is initialized -// to 0 before the first call to getopt. -// -// When all options have been processed (i.e., up to the first -// non-option argument), getopt returns EOF, optarg will point -// to the argument, and optind will be set to the argv index of -// the argument. If there are no non-option arguments, optarg -// will be set to nullptr. -// -// The special option "--" may be used to delimit the end of the -// options; EOF will be returned, and "--" (and everything after it) -// will be skipped. -// -// RETURN VALUE -// For option letters contained in the string optstring, getopt -// will return the option letter. getopt returns a question mark (?) -// when it encounters an option letter not included in optstring. -// EOF is returned when processing is finished. -// -// BUGS -// 1) Long options are not supported. -// 2) The GNU double-colon extension is not supported. -// 3) The environment variable POSIXLY_CORRECT is not supported. -// 4) The + syntax is not supported. -// 5) The automatic permutation of arguments is not supported. -// 6) This implementation of getopt() returns EOF if an error is -// encountered, instead of -1 as the latest standard requires. -// -// EXAMPLE -// BOOL CMyApp::ProcessCommandLine(int argc, char *argv[]) -// { -// int c; -// -// while ((c = getopt(argc, argv, _T("aBn:"))) != EOF) -// { -// switch (c) -// { -// case _T('a'): -// TRACE(_T("option a\n")); -// // -// // set some flag here -// // -// break; -// -// case _T('B'): -// TRACE( _T("option B\n")); -// // -// // set some other flag here -// // -// break; -// -// case _T('n'): -// TRACE(_T("option n: value=%d\n"), atoi(optarg)); -// // -// // do something with value here -// // -// break; -// -// case _T('?'): -// TRACE(_T("ERROR: illegal option %s\n"), argv[optind-1]); -// return FALSE; -// break; -// -// default: -// TRACE(_T("WARNING: no handler for option %c\n"), c); -// return FALSE; -// break; -// } -// } -// // -// // check for non-option args here -// // -// return TRUE; -// } -// -/////////////////////////////////////////////////////////////////////////////// - -char *optarg; // global argument pointer -char *next; -int optind = 0; // global argv index - -int getopt(int argc, char *argv[], char *optstring) -{ - if (optind == 0) - next = nullptr; - - optarg = nullptr; - - if (next == nullptr || *next == '\0') - { - if (optind == 0) - optind++; - - if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0') - { - optarg = nullptr; - if (optind < argc) - optarg = argv[optind]; - return EOF; - } - - if (strcmp(argv[optind], "--") == 0) - { - optind++; - optarg = nullptr; - if (optind < argc) - optarg = argv[optind]; - return EOF; - } - - next = argv[optind]; - next++; // skip past - - optind++; - } - - char c = *next++; - char *cp = strchr(optstring, c); - - if (cp == nullptr || c == ':') - return '?'; - - cp++; - if (*cp == ':') - { - if (*next != '\0') - { - optarg = next; - next = nullptr; - } - else if (optind < argc) - { - optarg = argv[optind]; - optind++; - } - else - { - return '?'; - } - } - - return c; -} diff --git a/src/tmx2gba.cpp b/src/tmx2gba.cpp index 98157ae..744826e 100644 --- a/src/tmx2gba.cpp +++ b/src/tmx2gba.cpp @@ -1,6 +1,6 @@ /* tmx2gba.cpp - Copyright (C) 2015-2019 Nicholas Curtis (a dinosaur) + Copyright (C) 2015-2022 a dinosaur This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages diff --git a/src/tmxlayer.cpp b/src/tmxlayer.cpp index 3d6c523..e17e87f 100644 --- a/src/tmxlayer.cpp +++ b/src/tmxlayer.cpp @@ -1,6 +1,6 @@ /* tmxlayer.cpp - Copyright (C) 2015 Nicholas Curtis + Copyright (C) 2015 a dinosaur This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages diff --git a/src/tmxobject.cpp b/src/tmxobject.cpp index 32b2cc1..b0e5d76 100644 --- a/src/tmxobject.cpp +++ b/src/tmxobject.cpp @@ -1,6 +1,6 @@ /* tmxobject.cpp - Copyright (C) 2015 Nicholas Curtis + Copyright (C) 2015 a dinosaur This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages diff --git a/src/tmxreader.cpp b/src/tmxreader.cpp index 43d0920..82f147e 100644 --- a/src/tmxreader.cpp +++ b/src/tmxreader.cpp @@ -1,6 +1,6 @@ /* tmxreader.cpp - Copyright (C) 2015 Nicholas Curtis + Copyright (C) 2015 a dinosaur This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/tmxreader.h b/src/tmxreader.h index f5c8d9a..c9e89b8 100644 --- a/src/tmxreader.h +++ b/src/tmxreader.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include class CTmxTileset; class CTmxLayer; diff --git a/src/tmxtileset.cpp b/src/tmxtileset.cpp index bbee519..d4254f3 100644 --- a/src/tmxtileset.cpp +++ b/src/tmxtileset.cpp @@ -1,6 +1,6 @@ /* tmxtileset.cpp - Copyright (C) 2015 Nicholas Curtis + Copyright (C) 2015 a dinosaur This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages diff --git a/tmx2gba.sln b/tmx2gba.sln deleted file mode 100644 index 4b2db6e..0000000 --- a/tmx2gba.sln +++ /dev/null @@ -1,22 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.40629.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tmx2gba", "tmx2gba.vcxproj", "{F8167A3B-4B77-4449-B730-F19ECB133A08}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {F8167A3B-4B77-4449-B730-F19ECB133A08}.Debug|Win32.ActiveCfg = Debug|Win32 - {F8167A3B-4B77-4449-B730-F19ECB133A08}.Debug|Win32.Build.0 = Debug|Win32 - {F8167A3B-4B77-4449-B730-F19ECB133A08}.Release|Win32.ActiveCfg = Release|Win32 - {F8167A3B-4B77-4449-B730-F19ECB133A08}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/tmx2gba.vcxproj b/tmx2gba.vcxproj deleted file mode 100644 index 985fd4e..0000000 --- a/tmx2gba.vcxproj +++ /dev/null @@ -1,93 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {F8167A3B-4B77-4449-B730-F19ECB133A08} - tmx2gba - - - - Application - true - v140 - MultiByte - - - Application - false - v140 - true - MultiByte - - - - - - - - - - - - - - - Level4 - Disabled - true - inc\ - - - true - - - - - Level4 - MaxSpeed - true - true - true - inc\ - - - true - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/tmx2gba.vcxproj.filters b/tmx2gba.vcxproj.filters deleted file mode 100644 index a54aa2f..0000000 --- a/tmx2gba.vcxproj.filters +++ /dev/null @@ -1,75 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - \ No newline at end of file