diff --git a/test/ws/flake.nix b/test/ws/flake.nix new file mode 100644 index 0000000..794d289 --- /dev/null +++ b/test/ws/flake.nix @@ -0,0 +1,33 @@ +{ + inputs = { + nix-ros-overlay.url = "github:lopsided98/nix-ros-overlay/master"; + nixpkgs.follows = "nix-ros-overlay/nixpkgs"; # IMPORTANT!!! + }; + outputs = { self, nix-ros-overlay, nixpkgs }: + nix-ros-overlay.inputs.flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ nix-ros-overlay.overlays.default ]; + }; + in { + devShells.default = pkgs.mkShell { + name = "Example project"; + packages = [ + pkgs.colcon + # ... other non-ROS packages + (with pkgs.rosPackages.humble; buildEnv { + paths = [ + ros-core + ament-cmake-core + # ... other ROS packages + ]; + }) + ]; + }; + }); + nixConfig = { + extra-substituters = [ "https://ros.cachix.org" ]; + extra-trusted-public-keys = [ "ros.cachix.org-1:dSyZxI8geDCJrwgvCOHDoAfOm5sV1wCPjBkKL+38Rvo=" ]; + }; +} diff --git a/test/ws/src/library/CMakeLists.txt b/test/ws/src/library/CMakeLists.txt new file mode 100644 index 0000000..c54c4b5 --- /dev/null +++ b/test/ws/src/library/CMakeLists.txt @@ -0,0 +1,60 @@ +cmake_minimum_required(VERSION 3.8) +project(library) + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +# find dependencies +find_package(ament_cmake REQUIRED) +find_package(ament_cmake_ros REQUIRED) +# uncomment the following section in order to fill in +# further dependencies manually. +# find_package( REQUIRED) + +add_library(library src/library.cpp) +add_library(library::library ALIAS library) +target_compile_features(library PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17 +target_include_directories(library PUBLIC + $ + $) + +# Causes the visibility macros to use dllexport rather than dllimport, +# which is appropriate when building the dll but not consuming it. +target_compile_definitions(library PRIVATE "LIBRARY_BUILDING_LIBRARY") + +install( + DIRECTORY include/ + DESTINATION include/${PROJECT_NAME} +) +install( + TARGETS library + EXPORT export_${PROJECT_NAME} + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin +) + +if(BUILD_TESTING) + find_package(ament_lint_auto REQUIRED) + # the following line skips the linter which checks for copyrights + # comment the line when a copyright and license is added to all source files + set(ament_cmake_copyright_FOUND TRUE) + # the following line skips cpplint (only works in a git repo) + # comment the line when this package is in a git repo and when + # a copyright and license is added to all source files + set(ament_cmake_cpplint_FOUND TRUE) + ament_lint_auto_find_test_dependencies() +endif() + +ament_export_include_directories( + "include/${PROJECT_NAME}" +) +ament_export_libraries( + library +) +ament_export_targets( + export_${PROJECT_NAME} +) + +ament_package() diff --git a/test/ws/src/library/include/library/library.hpp b/test/ws/src/library/include/library/library.hpp new file mode 100644 index 0000000..21f34e5 --- /dev/null +++ b/test/ws/src/library/include/library/library.hpp @@ -0,0 +1,19 @@ +#ifndef LIBRARY__LIBRARY_HPP_ +#define LIBRARY__LIBRARY_HPP_ + +#include "library/visibility_control.h" + +namespace library +{ + +class Library +{ +public: + Library(); + + virtual ~Library(); +}; + +} // namespace library + +#endif // LIBRARY__LIBRARY_HPP_ diff --git a/test/ws/src/library/include/library/visibility_control.h b/test/ws/src/library/include/library/visibility_control.h new file mode 100644 index 0000000..bfdfd04 --- /dev/null +++ b/test/ws/src/library/include/library/visibility_control.h @@ -0,0 +1,35 @@ +#ifndef LIBRARY__VISIBILITY_CONTROL_H_ +#define LIBRARY__VISIBILITY_CONTROL_H_ + +// This logic was borrowed (then namespaced) from the examples on the gcc wiki: +// https://gcc.gnu.org/wiki/Visibility + +#if defined _WIN32 || defined __CYGWIN__ + #ifdef __GNUC__ + #define LIBRARY_EXPORT __attribute__ ((dllexport)) + #define LIBRARY_IMPORT __attribute__ ((dllimport)) + #else + #define LIBRARY_EXPORT __declspec(dllexport) + #define LIBRARY_IMPORT __declspec(dllimport) + #endif + #ifdef LIBRARY_BUILDING_LIBRARY + #define LIBRARY_PUBLIC LIBRARY_EXPORT + #else + #define LIBRARY_PUBLIC LIBRARY_IMPORT + #endif + #define LIBRARY_PUBLIC_TYPE LIBRARY_PUBLIC + #define LIBRARY_LOCAL +#else + #define LIBRARY_EXPORT __attribute__ ((visibility("default"))) + #define LIBRARY_IMPORT + #if __GNUC__ >= 4 + #define LIBRARY_PUBLIC __attribute__ ((visibility("default"))) + #define LIBRARY_LOCAL __attribute__ ((visibility("hidden"))) + #else + #define LIBRARY_PUBLIC + #define LIBRARY_LOCAL + #endif + #define LIBRARY_PUBLIC_TYPE +#endif + +#endif // LIBRARY__VISIBILITY_CONTROL_H_ diff --git a/test/ws/src/library/package.xml b/test/ws/src/library/package.xml new file mode 100644 index 0000000..07594eb --- /dev/null +++ b/test/ws/src/library/package.xml @@ -0,0 +1,19 @@ + + + + library + 0.0.0 + Library for testing ros2nix + Michal Sojka + MIT + + ament_cmake_ros + zlib + + ament_lint_auto + ament_lint_common + + + ament_cmake + + diff --git a/test/ws/src/library/src/library.cpp b/test/ws/src/library/src/library.cpp new file mode 100644 index 0000000..3a9878b --- /dev/null +++ b/test/ws/src/library/src/library.cpp @@ -0,0 +1,15 @@ +#include "library/library.hpp" +#include "zlib.h" + +namespace library +{ + +Library::Library() +{ +} + +Library::~Library() +{ +} + +} // namespace library diff --git a/test/ws/src/ros_node/CMakeLists.txt b/test/ws/src/ros_node/CMakeLists.txt new file mode 100644 index 0000000..29a0a62 --- /dev/null +++ b/test/ws/src/ros_node/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required(VERSION 3.8) +project(ros_node) + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +# find dependencies +find_package(ament_cmake REQUIRED) +find_package(library REQUIRED) + +add_executable(node src/node.cpp) +target_include_directories(node PUBLIC + $ + $) +target_compile_features(node PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17 +ament_target_dependencies( + node + "library" +) + +install(TARGETS node + DESTINATION lib/${PROJECT_NAME}) + +if(BUILD_TESTING) + find_package(ament_lint_auto REQUIRED) + # the following line skips the linter which checks for copyrights + # comment the line when a copyright and license is added to all source files + set(ament_cmake_copyright_FOUND TRUE) + # the following line skips cpplint (only works in a git repo) + # comment the line when this package is in a git repo and when + # a copyright and license is added to all source files + set(ament_cmake_cpplint_FOUND TRUE) + ament_lint_auto_find_test_dependencies() +endif() + +ament_package() diff --git a/test/ws/src/ros_node/package.xml b/test/ws/src/ros_node/package.xml new file mode 100644 index 0000000..ced8585 --- /dev/null +++ b/test/ws/src/ros_node/package.xml @@ -0,0 +1,20 @@ + + + + ros_node + 0.0.0 + ROS node for testing ros2nix + Michal Sojka + MIT + + ament_cmake + + library + + ament_lint_auto + ament_lint_common + + + ament_cmake + + diff --git a/test/ws/src/ros_node/src/node.cpp b/test/ws/src/ros_node/src/node.cpp new file mode 100644 index 0000000..baab39d --- /dev/null +++ b/test/ws/src/ros_node/src/node.cpp @@ -0,0 +1,12 @@ +#include +#include + +int main(int argc, char ** argv) +{ + (void) argc; + (void) argv; + library::Library dummy; + + printf("hello world package package\n"); + return 0; +}