Make wire_autogen have all symbols defined internally

Previously WireCmd.h/cpp that is used in wire_autogen wasn't included in
the sources, causing a link error on some platforms.

With WireCmd.* moved in the EXTRA_SOURCES, the nxt_wire target didn't
contain any non-header file and caused a link error on OSX. Fix it by
properly splitting the declaration and implementation of
TerribleCommandBuffer in a .h and .cpp file.
This commit is contained in:
Corentin Wallez 2017-05-30 18:06:38 -04:00 committed by Corentin Wallez
parent 40fb17dddc
commit b38ff68b88
4 changed files with 64 additions and 32 deletions

View File

@ -27,7 +27,7 @@ endif()
function(Generate) function(Generate)
set(oneValueArgs LIB_NAME LIB_TYPE PRINT_NAME EXECUTABLE) set(oneValueArgs LIB_NAME LIB_TYPE PRINT_NAME EXECUTABLE)
set(multiValueArgs COMMAND_LINE_ARGS EXTRA_DEPS SOURCE) set(multiValueArgs COMMAND_LINE_ARGS EXTRA_DEPS EXTRA_SOURCES)
cmake_parse_arguments(G "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) cmake_parse_arguments(G "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
execute_process( execute_process(
@ -57,7 +57,7 @@ function(Generate)
) )
add_library(${G_LIB_NAME} ${G_LIB_TYPE} add_library(${G_LIB_NAME} ${G_LIB_TYPE}
${G_SOURCE} ${G_EXTRA_SOURCES}
${OUTPUTS} ${OUTPUTS}
) )
endfunction() endfunction()

View File

@ -23,6 +23,9 @@ Generate(
COMMAND_LINE_ARGS COMMAND_LINE_ARGS
${GENERATOR_COMMON_ARGS} ${GENERATOR_COMMON_ARGS}
-T wire -T wire
EXTRA_SOURCES
${WIRE_DIR}/WireCmd.cpp
${WIRE_DIR}/WireCmd.h
) )
target_include_directories(wire_autogen PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories(wire_autogen PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(wire_autogen PUBLIC ${GENERATED_DIR}) target_include_directories(wire_autogen PUBLIC ${GENERATED_DIR})
@ -31,9 +34,9 @@ SetCXX14(wire_autogen)
SetPic(wire_autogen) SetPic(wire_autogen)
add_library(nxt_wire STATIC add_library(nxt_wire STATIC
${WIRE_DIR}/TerribleCommandBuffer.cpp
${WIRE_DIR}/TerribleCommandBuffer.h ${WIRE_DIR}/TerribleCommandBuffer.h
${WIRE_DIR}/WireCmd.cpp ${WIRE_DIR}/Wire.h
${WIRE_DIR}/WireCmd.h
) )
target_link_libraries(nxt_wire wire_autogen) target_link_libraries(nxt_wire wire_autogen)
SetCXX14(nxt_wire) SetCXX14(nxt_wire)

View File

@ -0,0 +1,52 @@
// Copyright 2017 The NXT Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "TerribleCommandBuffer.h"
namespace nxt {
namespace wire {
TerribleCommandBuffer::TerribleCommandBuffer() {
}
TerribleCommandBuffer::TerribleCommandBuffer(CommandHandler* handler) : handler(handler) {
}
void TerribleCommandBuffer::SetHandler(CommandHandler* handler) {
this->handler = handler;
}
void* TerribleCommandBuffer::GetCmdSpace(size_t size) {
if (size > sizeof(buffer)) {
return nullptr;
}
uint8_t* result = &buffer[offset];
offset += size;
if (offset > sizeof(buffer)) {
Flush();
return GetCmdSpace(size);
}
return result;
}
void TerribleCommandBuffer::Flush() {
handler->HandleCommands(buffer, offset);
offset = 0;
}
}
}

View File

@ -24,36 +24,13 @@ namespace wire {
class TerribleCommandBuffer : public CommandSerializer { class TerribleCommandBuffer : public CommandSerializer {
public: public:
TerribleCommandBuffer() { TerribleCommandBuffer();
} TerribleCommandBuffer(CommandHandler* handler);
TerribleCommandBuffer(CommandHandler* handler) : handler(handler) { void SetHandler(CommandHandler* handler);
}
void SetHandler(CommandHandler* handler) { void* GetCmdSpace(size_t size) override;
this->handler = handler; void Flush() override;
}
void* GetCmdSpace(size_t size) {
if (size > sizeof(buffer)) {
return nullptr;
}
uint8_t* result = &buffer[offset];
offset += size;
if (offset > sizeof(buffer)) {
Flush();
return GetCmdSpace(size);
}
return result;
}
void Flush() {
handler->HandleCommands(buffer, offset);
offset = 0;
}
private: private:
CommandHandler* handler = nullptr; CommandHandler* handler = nullptr;