From 229a87a620eb5800e5dadc772af783473315ffa1 Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Mon, 15 Nov 2021 22:58:02 +0000 Subject: [PATCH 1/4] Remove unused variables in ecc --- Sources/Ecc/Main.cpp | 1 - Sources/Ecc/Parser.y | 1 - 2 files changed, 2 deletions(-) diff --git a/Sources/Ecc/Main.cpp b/Sources/Ecc/Main.cpp index 558ae58..b5ab5c2 100644 --- a/Sources/Ecc/Main.cpp +++ b/Sources/Ecc/Main.cpp @@ -178,7 +178,6 @@ void ReplaceFileRL(const char *strOld, const char *strNew) // process each charachter for(int ich=0;ich Date: Mon, 15 Nov 2021 23:05:14 +0000 Subject: [PATCH 2/4] Delete unused Sources/Ecc/unistd.h It's not clear why this was added. It looks like a compatibility hack for Windows, but we include io.h directly on Windows anyway. Having this file present breaks building ecc separately on UNIX. --- Sources/Ecc/unistd.h | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 Sources/Ecc/unistd.h diff --git a/Sources/Ecc/unistd.h b/Sources/Ecc/unistd.h deleted file mode 100644 index c9c1cb0..0000000 --- a/Sources/Ecc/unistd.h +++ /dev/null @@ -1,16 +0,0 @@ -/* Copyright (c) 2002-2012 Croteam Ltd. -This program is free software; you can redistribute it and/or modify -it under the terms of version 2 of the GNU General Public License as published by -the Free Software Foundation - - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ - -#include From bd68934e328140e5f1d147225e0de26e1822dee3 Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Mon, 15 Nov 2021 22:59:34 +0000 Subject: [PATCH 3/4] Swap PLATFORM_* macros for standard ones in ecc This simplifies the standalone CMakeLists.txt file arriving in the next commit. _WIN32 is defined by MVSC and the MinGW toolchain for all relevant Windows versions. We don't need to explicitly check for UNIX because it's the only non-Windows case we care about. --- Sources/Ecc/Main.h | 2 +- Sources/Ecc/StdH.h | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Sources/Ecc/Main.h b/Sources/Ecc/Main.h index 143bf05..5a7d34f 100644 --- a/Sources/Ecc/Main.h +++ b/Sources/Ecc/Main.h @@ -15,7 +15,7 @@ with this program; if not, write to the Free Software Foundation, Inc., /* rcg10042001 */ -#ifdef PLATFORM_WIN32 +#ifdef _WIN32 #define alloca _alloca #endif diff --git a/Sources/Ecc/StdH.h b/Sources/Ecc/StdH.h index ea0cdca..606c882 100644 --- a/Sources/Ecc/StdH.h +++ b/Sources/Ecc/StdH.h @@ -21,11 +21,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include -#ifdef PLATFORM_WIN32 +#ifdef _WIN32 #include -#endif - -#ifdef PLATFORM_UNIX +#else #include #include #include From c09d18623e10e72cb9bb77d919d4166e8ab1447d Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Mon, 15 Nov 2021 22:48:06 +0000 Subject: [PATCH 4/4] Allow ecc to be built independently using its own CMakeLists.txt file This makes cross-compiling easier, and saves having to build once each for TFE and TSE. I considered using CMake's import/export feature, but there's little point when you're only importing one binary target. Pointing the ECC variable at the ecc binary itself is simpler. I copied the minimum CMake version of 2.8.7 from the parent project. To be confident this would actually work, I tested building under CentOS 7 with CMake 2.8.12. --- Sources/CMakeLists.txt | 41 ++++++---------------------- Sources/Ecc/CMakeLists.txt | 18 ++++++++++++ Sources/Ecc/Parser.y | 4 +-- Sources/Ecc/Scanner.l | 7 ++--- Sources/cmake/ParserAndScanner.cmake | 25 +++++++++++++++++ 5 files changed, 57 insertions(+), 38 deletions(-) create mode 100644 Sources/Ecc/CMakeLists.txt create mode 100644 Sources/cmake/ParserAndScanner.cmake diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt index 6947016..558a2c1 100755 --- a/Sources/CMakeLists.txt +++ b/Sources/CMakeLists.txt @@ -20,8 +20,9 @@ if(NOT COMMAND add_compile_options) endfunction() endif() -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") include(CheckCXXCompilerFlag) +include(ParserAndScanner) # ssam expects the libs to be in Debug/ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Debug) @@ -312,40 +313,16 @@ else() include_directories(External/libvorbis/include) endif() -# We build ECC, then use it to generate C++ code for the game entities... -macro(add_parser_and_scanner _PARSER _SCANNER) - add_custom_command( - OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/${_SCANNER}.cpp" - MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/${_SCANNER}.l" - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" - COMMAND flex - ARGS -o${_SCANNER}.cpp ${_SCANNER}.l - ) - - add_custom_command( - OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/${_PARSER}.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/${_PARSER}.hpp" - MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/${_PARSER}.y" - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" - COMMAND bison - ARGS -o${_PARSER}.cpp ${_PARSER}.y -d - ) - - add_custom_command( - OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/${_PARSER}.h" - MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/${_PARSER}.hpp" - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" - COMMAND ${CMAKE_COMMAND} - ARGS -E copy ${_PARSER}.hpp ${_PARSER}.h - ) -endmacro() - # Build ECC from source if there wasn't a prebuilt-one specified on the command line. # Normally we build it here, but we might need a prebuilt, native binary if # we're cross-compiling the rest of the game. -if(NOT ECC) - add_parser_and_scanner("Ecc/Parser" "Ecc/Scanner") - add_executable(ecc Ecc/Main.cpp Ecc/Parser.cpp Ecc/Parser.h Ecc/Scanner.cpp) - set(ECC "ecc") +if(ECC) + # Use given ecc. +elseif(CMAKE_CROSSCOMPILING) + message(FATAL_ERROR "ECC variable must point to native ecc binary when cross-compiling.") +else() + add_subdirectory(Ecc) + set(ECC ecc) endif() macro(entity _NAME) diff --git a/Sources/Ecc/CMakeLists.txt b/Sources/Ecc/CMakeLists.txt new file mode 100644 index 0000000..8113cf6 --- /dev/null +++ b/Sources/Ecc/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 2.8.7) +project(Ecc) + +if(MSVC) + add_compile_options(/W4) +else() + add_compile_options(-Wall) +endif() + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake") +include(ParserAndScanner) + +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_parser_and_scanner("Parser" "Scanner") +add_executable(ecc Main.cpp Parser.cpp Parser.h Scanner.cpp) diff --git a/Sources/Ecc/Parser.y b/Sources/Ecc/Parser.y index 2286d21..5f3000e 100644 --- a/Sources/Ecc/Parser.y +++ b/Sources/Ecc/Parser.y @@ -1,7 +1,7 @@ %{ // rcg10042001 Changed to specify Ecc directory... -#include "Ecc/StdH.h" -#include "Ecc/Main.h" +#include "StdH.h" +#include "Main.h" // turn off over-helpful bit of bison... --ryan. #ifdef __GNUC__ diff --git a/Sources/Ecc/Scanner.l b/Sources/Ecc/Scanner.l index 554b7e6..795f27e 100644 --- a/Sources/Ecc/Scanner.l +++ b/Sources/Ecc/Scanner.l @@ -1,8 +1,7 @@ %{ -// rcg10042001 Changed to specify Ecc directory... -#include "Ecc/StdH.h" -#include "Ecc/Main.h" -#include "Ecc/Parser.h" +#include "StdH.h" +#include "Main.h" +#include "Parser.h" #define YY_NEVER_INTERACTIVE 1 diff --git a/Sources/cmake/ParserAndScanner.cmake b/Sources/cmake/ParserAndScanner.cmake new file mode 100644 index 0000000..a2051ed --- /dev/null +++ b/Sources/cmake/ParserAndScanner.cmake @@ -0,0 +1,25 @@ +macro(add_parser_and_scanner _PARSER _SCANNER) + add_custom_command( + OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/${_SCANNER}.cpp" + MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/${_SCANNER}.l" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + COMMAND flex + ARGS -o${_SCANNER}.cpp ${_SCANNER}.l + ) + + add_custom_command( + OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/${_PARSER}.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/${_PARSER}.hpp" + MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/${_PARSER}.y" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + COMMAND bison + ARGS -o${_PARSER}.cpp ${_PARSER}.y -d + ) + + add_custom_command( + OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/${_PARSER}.h" + MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/${_PARSER}.hpp" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + COMMAND ${CMAKE_COMMAND} + ARGS -E copy ${_PARSER}.hpp ${_PARSER}.h + ) +endmacro()