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.
This commit is contained in:
James Le Cuirot 2021-11-15 22:48:06 +00:00
parent bd68934e32
commit c09d18623e
No known key found for this signature in database
GPG Key ID: 1226415D00DD3137
5 changed files with 57 additions and 38 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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__

View File

@ -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

View File

@ -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()