Skip to content

Commit

Permalink
feat: add lanelet2_validation
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Nov 21, 2023
1 parent 0195c63 commit 3c9f0d5
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 47 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ project(lanelet2)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED)

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
if (MSVC)
Expand All @@ -20,7 +19,7 @@ add_subdirectory(lanelet2_io)
add_subdirectory(lanelet2_projection)
add_subdirectory(lanelet2_traffic_rules)
add_subdirectory(lanelet2_routing)
#add_subdirectory(lanelet2_validation)
add_subdirectory(lanelet2_validation)
#add_subdirectory(lanelet2_examples)
#add_subdirectory(lanelet2_python)
add_subdirectory(lanelet2_maps)
Expand Down
4 changes: 2 additions & 2 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class Lanelet2Conan(ConanFile):
# 'lanelet2_matching',
'lanelet2_projection',
'lanelet2_traffic_rules',
# 'lanelet2_routing',
# 'lanelet2_validation'
'lanelet2_routing',
'lanelet2_validation'
]

exports_sources = ["CMakeLists.txt"] + [f"{proj}/*" for proj in proj_list]
Expand Down
129 changes: 88 additions & 41 deletions lanelet2_validation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,81 +1,128 @@
set(MRT_PKG_VERSION 4.0.0)
#set(MRT_PKG_VERSION 4.0.0)
# Modify only if you know what you are doing!
cmake_minimum_required(VERSION 3.5.1)
project(lanelet2_validation)

###################
## Find packages ##
###################
find_package(mrt_cmake_modules REQUIRED)
include(UseMrtStdCompilerFlags)
include(GatherDeps)
#find_package(mrt_cmake_modules REQUIRED)
#include(UseMrtStdCompilerFlags)
#include(GatherDeps)

# You can add a custom.cmake in order to add special handling for this package. E.g. you can do:
# list(REMOVE_ITEM DEPENDEND_PACKAGES <package name 1> <package name 2> ...)
# To remove libs which cannot be found automatically. You can also "find_package" other, custom dependencies there.
# You can also set PROJECT_INSTALL_FILES to install files that are not installed by default.
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/custom.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/custom.cmake")
endif()

find_package(AutoDeps REQUIRED COMPONENTS ${DEPENDEND_PACKAGES})

mrt_parse_package_xml()
#if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/custom.cmake")
# include("${CMAKE_CURRENT_SOURCE_DIR}/custom.cmake")
#endif()
#
#find_package(AutoDeps REQUIRED COMPONENTS ${DEPENDEND_PACKAGES})
#
#mrt_parse_package_xml()

########################
## Add python modules ##
########################
# This adds a python module if located under src/{PROJECT_NAME)
mrt_python_module_setup()

mrt_glob_files(PROJECT_PYTHON_SOURCE_FILES_SRC "python_api/*.cpp")
if (PROJECT_PYTHON_SOURCE_FILES_SRC)
# Add a cpp-python api library. Make sure there are no name collisions with python modules in this project
mrt_add_python_api( ${PROJECT_NAME}
FILES ${PROJECT_PYTHON_SOURCE_FILES_SRC}
)
endif()
#mrt_python_module_setup()
#
#mrt_glob_files(PROJECT_PYTHON_SOURCE_FILES_SRC "python_api/*.cpp")
#if (PROJECT_PYTHON_SOURCE_FILES_SRC)
# # Add a cpp-python api library. Make sure there are no name collisions with python modules in this project
# mrt_add_python_api( ${PROJECT_NAME}
# FILES ${PROJECT_PYTHON_SOURCE_FILES_SRC}
# )
#endif()

############################
## Read source code files ##
############################
mrt_glob_files_recurse(PROJECT_HEADER_FILES_INC "include/*.h" "include/*.hpp" "include/*.cuh")
mrt_glob_files(PROJECT_SOURCE_FILES_INC "src/*.h" "src/*.hpp" "src/*.cuh")
mrt_glob_files_recurse(PROJECT_SOURCE_FILES_SRC "src/*.cpp" "src/*.cu")
#mrt_glob_files_recurse(PROJECT_HEADER_FILES_INC "include/*.h" "include/*.hpp" "include/*.cuh")
#mrt_glob_files(PROJECT_SOURCE_FILES_INC "src/*.h" "src/*.hpp" "src/*.cuh")
#mrt_glob_files_recurse(PROJECT_SOURCE_FILES_SRC "src/*.cpp" "src/*.cu")
file(GLOB_RECURSE PROJECT_SOURCE_FILES_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")

###########
## Build ##
###########
# Declare a cpp library
mrt_add_library(${PROJECT_NAME}
INCLUDES ${PROJECT_HEADER_FILES_INC} ${PROJECT_SOURCE_FILES_INC}
SOURCES ${PROJECT_SOURCE_FILES_SRC}
)
#mrt_add_library(${PROJECT_NAME}
# INCLUDES ${PROJECT_HEADER_FILES_INC} ${PROJECT_SOURCE_FILES_INC}
# SOURCES ${PROJECT_SOURCE_FILES_SRC}
# )
find_package(Boost REQUIRED)
add_library(${PROJECT_NAME} SHARED ${PROJECT_SOURCE_FILES_SRC})
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(${PROJECT_NAME} PUBLIC lanelet2_core lanelet2_io lanelet2_traffic_rules lanelet2_projection lanelet2_routing Boost::program_options)

# Add executables in "tools"
glob_folders(TOOL_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/tools")
if (TOOL_DIRECTORIES)
# Found subfolders, add executable for each subfolder
foreach(TOOL_DIR ${TOOL_DIRECTORIES})
mrt_add_executable(${TOOL_DIR} FOLDER "tools/${TOOL_DIR}")
endforeach()
else()
#glob_folders(TOOL_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/tools")
#if (TOOL_DIRECTORIES)
# # Found subfolders, add executable for each subfolder
# foreach(TOOL_DIR ${TOOL_DIRECTORIES})
# mrt_add_executable(${TOOL_DIR} FOLDER "tools/${TOOL_DIR}")
# endforeach()
#else()
# # No subfolder found, add executable and python modules for tools folder
# mrt_add_executable(${PROJECT_NAME} FOLDER "tools")
#endif()

set(TOOL_TARGETS)
file(GLOB TOOL_DIRECTORIES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/tools" "${CMAKE_CURRENT_SOURCE_DIR}/tools/*")
foreach (TOOL_DIR ${TOOL_DIRECTORIES})
if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/tools/${TOOL_DIR}")
file(GLOB TOOL_SOURCES_FILES "${CMAKE_CURRENT_SOURCE_DIR}/tools/${TOOL_DIR}/*.cpp")
add_executable(${TOOL_DIR} ${TOOL_SOURCES_FILES})
target_link_libraries(${TOOL_DIR} PUBLIC lanelet2_validation)
list(APPEND TOOL_TARGETS ${TOOL_DIR})
endif ()
endforeach ()

if (NOT TOOL_TARGETS)
# No subfolder found, add executable and python modules for tools folder
mrt_add_executable(${PROJECT_NAME} FOLDER "tools")
endif()
file(GLOB TOOL_SOURCES_FILES "${CMAKE_CURRENT_SOURCE_DIR}/tools/*.cpp")
add_executable("${PROJECT_NAME}_tool" ${TOOL_SOURCES_FILES})
target_link_libraries("${PROJECT_NAME}_tool" PUBLIC lanelet2_validation)
list(APPEND TOOL_TARGETS "${PROJECT_NAME}_tool")
endif ()


#############
## Install ##
#############
# Install all targets, headers by default and scripts and other files if specified (folders or files).
# This command also exports libraries and config files for dependent packages and this supersedes catkin_package.
mrt_install(PROGRAMS scripts FILES res data ${PROJECT_INSTALL_FILES})
#mrt_install(PROGRAMS scripts FILES res data ${PROJECT_INSTALL_FILES})
install(TARGETS ${PROJECT_NAME} ${EXECUTABLE_TARGETS}
ARCHIVE DESTINATION ${PROJECT_INSTALL_FILES}
LIBRARY DESTINATION ${PROJECT_INSTALL_FILES}
RUNTIME DESTINATION ${PROJECT_INSTALL_FILES})

#############
## Testing ##
#############
# Add test targets for cpp and python tests
if (CATKIN_ENABLE_TESTING)
mrt_add_tests(test)
mrt_add_nosetests(test)
endif()
#if (CATKIN_ENABLE_TESTING)
# mrt_add_tests(test)
# mrt_add_nosetests(test)
#endif ()

if (LANELET2_ENABLE_TESTING)
include(GoogleTest)
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_link_libraries("${PROJECT_NAME}_test" PRIVATE GTest::gtest_main ${PROJECT_NAME})

add_custom_command(TARGET "${PROJECT_NAME}_test" POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:lanelet2_core>" "$<TARGET_FILE_DIR:${PROJECT_NAME}_test>"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:lanelet2_io>" "$<TARGET_FILE_DIR:${PROJECT_NAME}_test>"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:lanelet2_traffic_rules>" "$<TARGET_FILE_DIR:${PROJECT_NAME}_test>"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:lanelet2_projection>" "$<TARGET_FILE_DIR:${PROJECT_NAME}_test>"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:lanelet2_routing>" "$<TARGET_FILE_DIR:${PROJECT_NAME}_test>")

gtest_discover_tests("${PROJECT_NAME}_test")
add_dependencies("${PROJECT_NAME}_test" lanelet2_maps)
endif ()
4 changes: 2 additions & 2 deletions lanelet2_validation/test/lanelet2_validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "lanelet2_validation/Validation.h"

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

TEST(Validator, curvatureTooBig) { // NOLINT
std::string exampleMapPath = "../../lanelet2_maps/res/mapping_example.osm";
std::string exampleMapPath = "../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 3c9f0d5

Please sign in to comment.