Cleaned up the protobuf and mapexport build scripts a lot, and added two more simple proto files to store map geometry information.

develop
Mike Stewart 2012-01-20 11:21:29 -08:00
parent 9b0b0d53f9
commit bf60f5975a
8 changed files with 55 additions and 16 deletions

@ -1,3 +1,6 @@
PROJECT(protobuf)
#Protocol buffers use C++0x hash maps, so we need to look for those. This is a rewrite of stl_hash.m4 in CMake.
IF(CMAKE_COMPILER_IS_GNUCC) IF(CMAKE_COMPILER_IS_GNUCC)
EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} -dumpversion EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} -dumpversion
OUTPUT_VARIABLE GCC_VERSION) OUTPUT_VARIABLE GCC_VERSION)
@ -5,6 +8,7 @@ IF(CMAKE_COMPILER_IS_GNUCC)
LIST(GET GCC_VERSION_COMPONENTS 0 GCC_MAJOR) LIST(GET GCC_VERSION_COMPONENTS 0 GCC_MAJOR)
LIST(GET GCC_VERSION_COMPONENTS 1 GCC_MINOR) LIST(GET GCC_VERSION_COMPONENTS 1 GCC_MINOR)
IF(GCC_MAJOR LESS 4 OR (GCC_MAJOR EQUAL 4 AND GCC_MINOR LESS 2)) IF(GCC_MAJOR LESS 4 OR (GCC_MAJOR EQUAL 4 AND GCC_MINOR LESS 2))
#GCC is too old
SET(STL_HASH_OLD_GCC 1) SET(STL_HASH_OLD_GCC 1)
ENDIF() ENDIF()
@ -12,6 +16,8 @@ IF(CMAKE_COMPILER_IS_GNUCC)
SET(HAVE_HASH_MAP 0) SET(HAVE_HASH_MAP 0)
SET(HASH_MAP_CLASS unordered_map) SET(HASH_MAP_CLASS unordered_map)
#Check for all of the possible combinations of unordered_map and hash_map
FOREACH(header tr1/unordered_map unordered_map) FOREACH(header tr1/unordered_map unordered_map)
FOREACH(namespace std::tr1 std ) FOREACH(namespace std::tr1 std )
IF(HAVE_HASH_MAP EQUAL 0 AND NOT STL_HASH_OLD_GCC) IF(HAVE_HASH_MAP EQUAL 0 AND NOT STL_HASH_OLD_GCC)
@ -193,9 +199,7 @@ google/protobuf/compiler/zip_writer.cc
LIST(APPEND LIBPROTOBUF_FULL_SRCS ${LIBPROTOBUF_LITE_SRCS}) LIST(APPEND LIBPROTOBUF_FULL_SRCS ${LIBPROTOBUF_LITE_SRCS})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
IF (CMAKE_COMPILER_IS_GNUCC AND ${HASH_NAMESPACE} MATCHES ".*tr1.*")
SET(CMAKE_CXX_FLAGS "-std=gnu++98")
ENDIF()
ADD_LIBRARY(protobuf-lite ${LIBPROTOBUF_LITE_SRCS} ${LIBPROTOBUF_LITE_HDRS}) ADD_LIBRARY(protobuf-lite ${LIBPROTOBUF_LITE_SRCS} ${LIBPROTOBUF_LITE_HDRS})
ADD_LIBRARY(protobuf ${LIBPROTOBUF_FULL_SRCS} ${LIBPROTOBUF_FULL_HDRS}) ADD_LIBRARY(protobuf ${LIBPROTOBUF_FULL_SRCS} ${LIBPROTOBUF_FULL_HDRS})
ADD_LIBRARY(protoc ${LIBPROTOC_SRCS} ${LIBPROTOC_HDRS}) ADD_LIBRARY(protoc ${LIBPROTOC_SRCS} ${LIBPROTOC_HDRS})

@ -910,7 +910,7 @@ bool CommandLineInterface::InterpretArgument(const string& name,
cerr << disk_path << ": warning: directory does not exist." << endl; cerr << disk_path << ": warning: directory does not exist." << endl;
} }
proto_path_.push_back(make_pair<string, string>(virtual_path, disk_path)); proto_path_.push_back(make_pair<string, string>(virtual_path.c_str(), disk_path.c_str()));
} }
} else if (name == "-o" || name == "--descriptor_set_out") { } else if (name == "-o" || name == "--descriptor_set_out") {

@ -0,0 +1 @@
proto/*.pb.*

@ -1,12 +1,11 @@
PROJECT(mapexport) PROJECT(mapexport)
SET(MAPEXPORT_SOURCE_DIR ${dfhack_SOURCE_DIR}/plugins/mapexport)
include_directories ( include_directories (
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
${dfhack_SOURCE_DIR}/library/depends/protobuf/ ${dfhack_SOURCE_DIR}/library/depends/protobuf/
) )
#Generated protobuf files and the headers they will require #The protobuf sources we generate will require these headers
SET(PROJECT_HDRS SET(PROJECT_HDRS
${dfhack_SOURCE_DIR}/library/depends/protobuf/google/protobuf/stubs/once.h ${dfhack_SOURCE_DIR}/library/depends/protobuf/google/protobuf/stubs/once.h
${dfhack_SOURCE_DIR}/library/depends/protobuf/google/protobuf/stubs/common.h ${dfhack_SOURCE_DIR}/library/depends/protobuf/google/protobuf/stubs/common.h
@ -15,23 +14,33 @@ ${dfhack_SOURCE_DIR}/library/depends/protobuf/google/protobuf/wire_format_lite_i
${dfhack_SOURCE_DIR}/library/depends/protobuf/google/protobuf/generated_message_util.h ${dfhack_SOURCE_DIR}/library/depends/protobuf/google/protobuf/generated_message_util.h
${dfhack_SOURCE_DIR}/library/depends/protobuf/google/protobuf/repeated_field.h ${dfhack_SOURCE_DIR}/library/depends/protobuf/google/protobuf/repeated_field.h
${dfhack_SOURCE_DIR}/library/depends/protobuf/google/protobuf/extension_set.h ${dfhack_SOURCE_DIR}/library/depends/protobuf/google/protobuf/extension_set.h
proto/Tile.pb.h
) )
SET(PROJECT_SRCS SET(PROJECT_SRCS
mapexport.cpp mapexport.cpp
proto/Tile.pb.cc
) )
SET(PROJECT_PROTOS
${CMAKE_CURRENT_SOURCE_DIR}/proto/Tile.proto
${CMAKE_CURRENT_SOURCE_DIR}/proto/Block.proto
${CMAKE_CURRENT_SOURCE_DIR}/proto/Map.proto
)
#Create new lists of what sources and headers protoc will output after we invoke it
STRING(REPLACE ".proto" ".pb.cc;" PROJECT_PROTO_SRCS ${PROJECT_PROTOS})
STRING(REPLACE ".proto" ".pb.h;" PROJECT_PROTO_HDRS ${PROJECT_PROTOS})
LIST(APPEND PROJECT_HDRS ${PROJECT_PROTO_HDRS})
LIST(APPEND PROJECT_SRCS ${PROJECT_PROTO_SRCS})
SET_SOURCE_FILES_PROPERTIES( ${PROJECT_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE) SET_SOURCE_FILES_PROPERTIES( ${PROJECT_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE)
LIST(APPEND PROJECT_SRCS ${PROJECT_HDRS}) LIST(APPEND PROJECT_SRCS ${PROJECT_HDRS})
FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/proto) #Generate sources from our proto files and store them in the source tree
ADD_CUSTOM_COMMAND( ADD_CUSTOM_COMMAND(
OUTPUT proto/Tile.pb.cc proto/Tile.pb.h OUTPUT ${PROJECT_PROTO_SRCS} ${PROJECT_PROTO_HDRS}
COMMAND protoc-bin -I=${CMAKE_CURRENT_SOURCE_DIR}/proto --cpp_out=${CMAKE_CURRENT_BINARY_DIR}/proto ${CMAKE_CURRENT_SOURCE_DIR}/proto/Tile.proto COMMAND protoc-bin -I=${CMAKE_CURRENT_SOURCE_DIR}/proto --cpp_out=${CMAKE_CURRENT_SOURCE_DIR}/proto ${PROJECT_PROTOS}
DEPENDS protoc-bin ${CMAKE_CURRENT_SOURCE_DIR}/proto/Tile.proto DEPENDS protoc-bin ${PROJECT_PROTOS}
) )
DFHACK_PLUGIN(mapexport ${PROJECT_SRCS} ${PROJECT_HDRS} LINK_LIBRARIES protobuf-lite) DFHACK_PLUGIN(mapexport ${PROJECT_SRCS} ${PROJECT_HDRS} LINK_LIBRARIES protobuf-lite)

@ -2,7 +2,8 @@
#include <Console.h> #include <Console.h>
#include <Export.h> #include <Export.h>
#include <PluginManager.h> #include <PluginManager.h>
#include "proto/Tile.pb.h"
#include "proto/Map.pb.h"
using namespace DFHack; using namespace DFHack;
DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & parameters); DFhackCExport command_result mapexport (Core * c, std::vector <std::string> & parameters);

@ -0,0 +1,12 @@
package dfproto;
option optimize_for = LITE_RUNTIME;
import "Tile.proto";
message Block
{
required uint32 x = 1;
required uint32 y = 2;
required uint32 z = 3;
repeated Tile tiles = 4;
}

@ -0,0 +1,12 @@
package dfproto;
option optimize_for = LITE_RUNTIME;
import "Block.proto";
message Map
{
required uint32 x_size = 1;
required uint32 y_size = 2;
required uint32 z_size = 3;
repeated Block blocks = 4;
}