Skip to content

Commit

Permalink
feat: build as static library
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Nov 27, 2023
1 parent 31d3a91 commit 385e920
Show file tree
Hide file tree
Showing 24 changed files with 58 additions and 51 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ jobs:
# run: echo "Some files failed the linting checks!" && exit 1

test:
name: Build on ${{ matrix.machine.os }} (shared=${{ matrix.options.shared }})
needs: formatting
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
options:
- { shared: 'True' }
- { shared: 'True' } # shared library
- { shared: 'False' } # static library
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Code
Expand Down
5 changes: 0 additions & 5 deletions lanelet2_core/src/BasicRegulatoryElements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,6 @@ RegulatoryElementDataPtr constructAllWayStopData(Id id, const AttributeMap& attr
}
} // namespace

static RegisterRegulatoryElement<TrafficLight> regTraffic;
static RegisterRegulatoryElement<RightOfWay> regRightOfWay;
static RegisterRegulatoryElement<TrafficSign> regTrafficSign;
static RegisterRegulatoryElement<SpeedLimit> regSpeedLimit;
static RegisterRegulatoryElement<AllWayStop> regAllWayStop;
#if __cplusplus < 201703L
constexpr char TrafficLight::RuleName[];
constexpr char RightOfWay::RuleName[];
Expand Down
6 changes: 6 additions & 0 deletions lanelet2_core/src/RegulatoryElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ class ToConstVisitor : public RuleParameterVisitor {
} // namespace

static RegisterRegulatoryElement<GenericRegulatoryElement> genRegelem;
static RegisterRegulatoryElement<TrafficLight> regTraffic;
static RegisterRegulatoryElement<RightOfWay> regRightOfWay;
static RegisterRegulatoryElement<TrafficSign> regTrafficSign;
static RegisterRegulatoryElement<SpeedLimit> regSpeedLimit;
static RegisterRegulatoryElement<AllWayStop> regAllWayStop;

#if __cplusplus < 201703L
constexpr char GenericRegulatoryElement::RuleName[];

Expand Down
4 changes: 2 additions & 2 deletions lanelet2_io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ if (NOT BUILD_TESTING STREQUAL OFF)
include(GoogleTest)
file(GLOB PROJECT_SOURCE_FILES_TEST "${CMAKE_CURRENT_SOURCE_DIR}/test/*.cpp")
add_executable("${PROJECT_NAME}_test" ${PROJECT_SOURCE_FILES_TEST})
target_compile_definitions("${PROJECT_NAME}_test" PRIVATE -DPKG_DIR="${CMAKE_CURRENT_LIST_DIR}")
target_link_libraries("${PROJECT_NAME}_test" PRIVATE GTest::gtest_main ${PROJECT_NAME})

if (WIN32)
add_custom_command(TARGET "${PROJECT_NAME}_test" POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_RUNTIME_DLLS:${PROJECT_NAME}_test>" "$<TARGET_FILE_DIR:${PROJECT_NAME}_test>"
COMMAND ${CMAKE_COMMAND} -E copy -t "$<TARGET_FILE_DIR:${PROJECT_NAME}_test>" "$<TARGET_RUNTIME_DLLS:${PROJECT_NAME}_test>"
COMMAND_EXPAND_LISTS)
endif ()

gtest_discover_tests("${PROJECT_NAME}_test")
add_dependencies("${PROJECT_NAME}_test" lanelet2_maps)
endif ()
8 changes: 0 additions & 8 deletions lanelet2_io/src/BinHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,11 @@
#include <fstream>

#include "lanelet2_io/Exceptions.h"
#include "lanelet2_io/io_handlers/Factory.h"
#include "lanelet2_io/io_handlers/Serialize.h"

namespace lanelet {
namespace io_handlers {

namespace {
// register with factories
RegisterParser<BinParser> regParser;
RegisterWriter<BinWriter> regWriter;

} // namespace

void BinWriter::write(const std::string& filename, const LaneletMap& laneletMap, ErrorMessages& /*errors*/,
const io::Configuration& /*params*/) const {
std::ofstream fs(filename, std::ofstream::binary);
Expand Down
8 changes: 8 additions & 0 deletions lanelet2_io/src/Factory.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
#include "lanelet2_io/io_handlers/Factory.h"

#include "lanelet2_io/Exceptions.h"
#include "lanelet2_io/io_handlers/BinHandler.h"
#include "lanelet2_io/io_handlers/OsmHandler.h"

namespace lanelet {
namespace io_handlers {
namespace {
// register with factories
RegisterParser<BinParser> regBinParser;
RegisterWriter<BinWriter> regBinWriter;
RegisterParser<OsmParser> regOsmParser;
RegisterWriter<OsmWriter> regOsmWriter;

std::string format(const std::vector<std::string>& strings, const std::string& delim = ", ") {
std::string formatted;
for (const auto& str : strings) {
Expand Down
2 changes: 0 additions & 2 deletions lanelet2_io/src/OsmHandlerLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ namespace io_handlers {
using Errors = std::vector<std::string>;

namespace {
// register with factories
RegisterParser<OsmParser> regParser;
using traits::to2D;
bool isValid(const LineStrings3d& lss) {
BasicPolygon2d ls(utils::concatenate(lss, [](const auto& elem) { return to2D(elem).basicLineString(); }));
Expand Down
3 changes: 0 additions & 3 deletions lanelet2_io/src/OsmHandlerWrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ namespace io_handlers {

using Errors = std::vector<std::string>;
namespace {
// register with factories
RegisterWriter<OsmWriter> regWriter;

struct UnresolvedRole {
Id relationId{};
Id referencedRoleId{};
Expand Down
3 changes: 2 additions & 1 deletion lanelet2_io/test/TestBinHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <boost/archive/binary_oarchive.hpp>
#include <cstdio>
#include <fstream>
#include <string>

#include "TestSetup.h"
#include "gtest/gtest.h"
Expand Down Expand Up @@ -115,7 +116,7 @@ TEST(BinHandler, explicitIO) { // NOLINT

TEST(BinHandler, fullMap) {
Origin origin({49, 8.4, 0});
std::string filenameIn = "../lanelet2_maps/res/mapping_example.osm";
std::string filenameIn = std::string(PKG_DIR) + "/../lanelet2_maps/res/mapping_example.osm";
auto map = lanelet::load(filenameIn, origin);
auto llt = map->laneletLayer.find(44968);
writeAndLoad(*llt);
Expand Down
2 changes: 1 addition & 1 deletion lanelet2_io/test/TestSimpleUsage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
TEST(lanelet2_io, exampleUsage) { // NOLINT
using namespace lanelet;
Origin origin({49, 8.4, 0});
std::string filenameIn = "../lanelet2_maps/res/mapping_example.osm";
std::string filenameIn = std::string(PKG_DIR) + "/../lanelet2_maps/res/mapping_example.osm";
LaneletMapPtr laneletMap = lanelet::load(filenameIn, origin);

lanelet::test_setup::Tempfile file("file.osm");
Expand Down
2 changes: 1 addition & 1 deletion lanelet2_matching/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ if (NOT BUILD_TESTING STREQUAL OFF)

if (WIN32)
add_custom_command(TARGET "${PROJECT_NAME}_test" POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_RUNTIME_DLLS:${PROJECT_NAME}_test>" "$<TARGET_FILE_DIR:${PROJECT_NAME}_test>"
COMMAND ${CMAKE_COMMAND} -E copy -t "$<TARGET_FILE_DIR:${PROJECT_NAME}_test>" "$<TARGET_RUNTIME_DLLS:${PROJECT_NAME}_test>"
COMMAND_EXPAND_LISTS)
endif ()

Expand Down
2 changes: 1 addition & 1 deletion lanelet2_projection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ if (NOT BUILD_TESTING STREQUAL OFF)

if (WIN32)
add_custom_command(TARGET "${PROJECT_NAME}_test" POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_RUNTIME_DLLS:${PROJECT_NAME}_test>" "$<TARGET_FILE_DIR:${PROJECT_NAME}_test>"
COMMAND ${CMAKE_COMMAND} -E copy -t "$<TARGET_FILE_DIR:${PROJECT_NAME}_test>" "$<TARGET_RUNTIME_DLLS:${PROJECT_NAME}_test>"
COMMAND_EXPAND_LISTS)
endif ()

Expand Down
3 changes: 1 addition & 2 deletions lanelet2_routing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ if (NOT BUILD_TESTING STREQUAL OFF)

if (WIN32)
add_custom_command(TARGET "${PROJECT_NAME}_test" POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_RUNTIME_DLLS:${PROJECT_NAME}_test>" "$<TARGET_FILE_DIR:${PROJECT_NAME}_test>"
COMMAND ${CMAKE_COMMAND} -E copy -t "$<TARGET_FILE_DIR:${PROJECT_NAME}_test>" "$<TARGET_RUNTIME_DLLS:${PROJECT_NAME}_test>"
COMMAND_EXPAND_LISTS)
endif ()

gtest_discover_tests("${PROJECT_NAME}_test")
add_dependencies("${PROJECT_NAME}_test" lanelet2_maps)
endif ()
2 changes: 1 addition & 1 deletion lanelet2_traffic_rules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ if (NOT BUILD_TESTING STREQUAL OFF)

if (WIN32)
add_custom_command(TARGET "${PROJECT_NAME}_test" POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_RUNTIME_DLLS:${PROJECT_NAME}_test>" "$<TARGET_FILE_DIR:${PROJECT_NAME}_test>"
COMMAND ${CMAKE_COMMAND} -E copy -t "$<TARGET_FILE_DIR:${PROJECT_NAME}_test>" "$<TARGET_RUNTIME_DLLS:${PROJECT_NAME}_test>"
COMMAND_EXPAND_LISTS)
endif ()

Expand Down
4 changes: 0 additions & 4 deletions lanelet2_traffic_rules/src/GermanTrafficRules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ namespace lanelet {
namespace traffic_rules {

namespace {
RegisterTrafficRules<GermanVehicle> gvRules(Locations::Germany, Participants::Vehicle);
RegisterTrafficRules<GermanPedestrian> gpRules(Locations::Germany, Participants::Pedestrian);
RegisterTrafficRules<GermanBicycle> gbRules(Locations::Germany, Participants::Bicycle);

Velocity trafficSignToVelocity(const std::string& typeString) {
using namespace lanelet::units::literals;
const static std::map<std::string, Velocity> StrToVelocity{
Expand Down
8 changes: 8 additions & 0 deletions lanelet2_traffic_rules/src/TrafficRulesFactory.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
#include "lanelet2_traffic_rules/TrafficRulesFactory.h"

#include "lanelet2_traffic_rules/GermanTrafficRules.h"

namespace lanelet {

#if __cplusplus < 201703L
constexpr char Locations::Germany[];
#endif

namespace traffic_rules {
namespace {
RegisterTrafficRules<GermanVehicle> gvRules(Locations::Germany, Participants::Vehicle);
RegisterTrafficRules<GermanPedestrian> gpRules(Locations::Germany, Participants::Pedestrian);
RegisterTrafficRules<GermanBicycle> gbRules(Locations::Germany, Participants::Bicycle);
} // namespace

TrafficRulesUPtr TrafficRulesFactory::create(const std::string& location, const std::string& participant,
TrafficRules::Configuration configuration) {
auto& registry = instance().registry_;
Expand Down
4 changes: 2 additions & 2 deletions lanelet2_validation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ if (NOT BUILD_TESTING STREQUAL OFF)
find_package(GTest REQUIRED)
file(GLOB PROJECT_SOURCE_FILES_TEST "${CMAKE_CURRENT_SOURCE_DIR}/test/*.cpp")
add_executable("${PROJECT_NAME}_test" ${PROJECT_SOURCE_FILES_TEST})
target_compile_definitions("${PROJECT_NAME}_test" PRIVATE -DPKG_DIR="${CMAKE_CURRENT_LIST_DIR}")
target_link_libraries("${PROJECT_NAME}_test" PRIVATE GTest::gtest_main ${PROJECT_NAME})

if (WIN32)
add_custom_command(TARGET "${PROJECT_NAME}_test" POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_RUNTIME_DLLS:${PROJECT_NAME}_test>" "$<TARGET_FILE_DIR:${PROJECT_NAME}_test>"
COMMAND ${CMAKE_COMMAND} -E copy -t "$<TARGET_FILE_DIR:${PROJECT_NAME}_test>" "$<TARGET_RUNTIME_DLLS:${PROJECT_NAME}_test>"
COMMAND_EXPAND_LISTS)
endif ()

gtest_discover_tests("${PROJECT_NAME}_test")
add_dependencies("${PROJECT_NAME}_test" lanelet2_maps)
endif ()
17 changes: 17 additions & 0 deletions lanelet2_validation/src/ValidatorFactory.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
#include "lanelet2_validation/ValidatorFactory.h"

#include "lanelet2_validation/validators/mapping/BoolTags.h"
#include "lanelet2_validation/validators/mapping/CurvatureTooBig.h"
#include "lanelet2_validation/validators/mapping/DuplicatedPoints.h"
#include "lanelet2_validation/validators/mapping/MandatoryTags.h"
#include "lanelet2_validation/validators/mapping/PointsTooClose.h"
#include "lanelet2_validation/validators/mapping/UnknownTagValue.h"
#include "lanelet2_validation/validators/mapping/UnknownTags.h"
#include "lanelet2_validation/validators/routing/RoutingGraphIsValid.h"

namespace lanelet {
namespace validation {
namespace {
RegisterMapValidator<BoolTags> regBoolTags;
RegisterMapValidator<UnknownTags> regUnknownTags;
RegisterMapValidator<UnknownTagValue> regUnknownTagValue;
RegisterMapValidator<MandatoryTags> regMandatoryTags;
RegisterMapValidator<CurvatureTooBigChecker> regCurvatureTooBig;
RegisterMapValidator<DuplicatedPointsChecker> regDuplicatedPoints;
RegisterMapValidator<PointsTooCloseChecker> regPointsTooClose;
RegisterRoutingGraphValidator<RoutingGraphIsValid> regRoutingGraphIsValid;

std::vector<std::string> matchSingleRegex(const std::regex& regex, const std::vector<std::string>& toMatch) {
std::vector<std::string> matches;
Expand Down
5 changes: 0 additions & 5 deletions lanelet2_validation/src/validators/CheckTags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ using Values = std::vector<std::string>;
using ValueMap = std::map<std::string, Values>;

namespace {
RegisterMapValidator<BoolTags> regBool;
RegisterMapValidator<UnknownTags> regUnknown;
RegisterMapValidator<UnknownTagValue> regUnknownValue;
RegisterMapValidator<MandatoryTags> regMandatoryTags;

bool startsWith(const std::string& str, const std::string& substr) { // NOLINT
return str.compare(0, substr.size(), substr) == 0;
}
Expand Down
3 changes: 0 additions & 3 deletions lanelet2_validation/src/validators/CurvatureTooBig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

namespace lanelet {
namespace validation {
namespace {
RegisterMapValidator<CurvatureTooBigChecker> reg1;
} // namespace

Issues CurvatureTooBigChecker::operator()(const LaneletMap& map) {
Issues issues;
Expand Down
1 change: 0 additions & 1 deletion lanelet2_validation/src/validators/DuplicatedPoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
namespace lanelet {
namespace validation {
namespace {
RegisterMapValidator<DuplicatedPointsChecker> reg;

template <typename T>
Optional<Id> hasDuplicates(const T& elem) {
Expand Down
3 changes: 0 additions & 3 deletions lanelet2_validation/src/validators/PointsTooClose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

namespace lanelet {
namespace validation {
namespace {
RegisterMapValidator<PointsTooCloseChecker> reg;
} // namespace

Issues PointsTooCloseChecker::operator()(const lanelet::LaneletMap& map) {
Issues issues;
Expand Down
3 changes: 0 additions & 3 deletions lanelet2_validation/src/validators/RoutingGraphIsValid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

namespace lanelet {
namespace validation {
namespace {
RegisterRoutingGraphValidator<RoutingGraphIsValid> reg;
} // namespace

Issues RoutingGraphIsValid::operator()(const routing::RoutingGraph& graph,
const traffic_rules::TrafficRules& /*rules*/) {
Expand Down
7 changes: 5 additions & 2 deletions lanelet2_validation/test/lanelet2_validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
#include <lanelet2_io/io_handlers/Writer.h>
#include <lanelet2_projection/UTM.h>

#include <string>

#include "lanelet2_validation/Cli.h"
#include "lanelet2_validation/Validation.h"

TEST(TestAllValidators, onExampleMap) { // NOLINT
const char* args[] = {"validator", "../lanelet2_maps/res/mapping_example.osm",
std::string exampleMapPath = std::string(PKG_DIR) + "/../lanelet2_maps/res/mapping_example.osm";
const char* args[] = {"validator", exampleMapPath.c_str(),
"--participants", "vehicle",
"--participants", "pedestrian",
"--lat", "49",
Expand All @@ -32,7 +35,7 @@ TEST(Validator, pointsTooClose) { // NOLINT
}

TEST(Validator, curvatureTooBig) { // NOLINT
std::string exampleMapPath = "../lanelet2_maps/res/mapping_example.osm";
std::string exampleMapPath = std::string(PKG_DIR) + "/../lanelet2_maps/res/mapping_example.osm";
using namespace lanelet;
projection::UtmProjector projector(Origin({49, 8.4}));
LaneletMapPtr map = load(exampleMapPath, projector);
Expand Down

0 comments on commit 385e920

Please sign in to comment.