diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e238fb2..bbb08099 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,9 @@ project(arbitration_graphs LANGUAGES CXX ) +# In order to properly support the GUI, we have to decide on an install path upfront (instead of letting CPack decide) +set(CMAKE_INSTALL_PREFIX "/usr") + # Select project features set(BUILD_GUI "TRUE" CACHE STRING "Compile the project with the WebApp GUI") set(BUILD_TESTS "FALSE" CACHE STRING "Compile the project with all unit tests") @@ -75,7 +78,6 @@ target_link_libraries(${PROJECT_NAME} INTERFACE util_caching ${YAML_CPP_LIBRARIES} ) -set(INSTALL_TARGETS ${PROJECT_NAME}) ################### @@ -122,16 +124,32 @@ endif() ## Install ## ############# -install(TARGETS ${INSTALL_TARGETS} - EXPORT ${PROJECT_NAME}Targets - LIBRARY DESTINATION lib COMPONENT Runtime - ARCHIVE DESTINATION lib COMPONENT Development - RUNTIME DESTINATION bin COMPONENT Runtime - PUBLIC_HEADER DESTINATION include COMPONENT Development - BUNDLE DESTINATION bin COMPONENT Runtime -) -install(EXPORT ${PROJECT_NAME}Targets DESTINATION lib/cmake/${PROJECT_NAME}) +install(TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}Targets + COMPONENT core + LIBRARY DESTINATION lib COMPONENT Runtime + ARCHIVE DESTINATION lib COMPONENT Development + RUNTIME DESTINATION bin COMPONENT Runtime + PUBLIC_HEADER DESTINATION include COMPONENT Development + BUNDLE DESTINATION bin COMPONENT Runtime) +install(EXPORT ${PROJECT_NAME}Targets + DESTINATION lib/cmake/${PROJECT_NAME} + COMPONENT core) install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" - DESTINATION lib/cmake/${PROJECT_NAME}) -install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include) \ No newline at end of file + DESTINATION lib/cmake/${PROJECT_NAME} + COMPONENT core) +install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ + DESTINATION include + COMPONENT core + PATTERN "gui" EXCLUDE) + + +############### +## Packaging ## +############### + +include(cpack_config) +include(CPack) + +message(STATUS "Components to pack: ${CPACK_COMPONENTS_ALL}") \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 3ecb8e8b..83420625 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,6 @@ RUN apt-get update && \ apt-get install -y \ build-essential \ cmake \ - git \ libgoogle-glog-dev \ libgtest-dev \ libyaml-cpp-dev && \ @@ -17,25 +16,21 @@ RUN apt-get update && \ RUN apt-get update && \ apt-get install -y \ libasio-dev \ - unzip \ - wget &&\ + zlib1g-dev &&\ apt-get clean -# Install Crow (C++ REST/WebSocket server) -RUN cd /tmp && \ - wget https://github.com/CrowCpp/Crow/releases/download/v1.2.0/Crow-1.2.0.zip && \ - unzip Crow-*.zip -d /tmp && \ - cp -r /tmp/Crow-*/* /usr/local && \ - rm -r Crow-* - -# Install util_caching -RUN git clone https://github.com/KIT-MRT/util_caching.git /tmp/util_caching && \ - mkdir /tmp/util_caching/build && \ - cd /tmp/util_caching/build && \ - cmake .. && \ - cmake --build . && \ - cmake --install . && \ - rm -rf /tmp/util_caching + +# Install Crow (C++ REST/WebSocket server) and util_caching + +# `ADD` downloads the Crow and util_caching debian releases and adds them to the docker image +# This "bloats" the image. But otherwise, we'd have to installing wget and ca-certificates +# temporarily to download and install the package in one docker layer… +ADD https://github.com/CrowCpp/Crow/releases/download/v1.2.0/Crow-1.2.0-Linux.deb /tmp/debfiles/ +ADD https://github.com/KIT-MRT/util_caching/releases/latest/download/libutil-caching-dev.deb /tmp/debfiles/ + +# Install Crow and util_caching from release debian package +RUN dpkg -i /tmp/debfiles/*.deb && \ + rm -rf /tmp/debfiles @@ -52,11 +47,13 @@ FROM base AS install # Install arbitration_graphs COPY CMakeLists.txt /tmp/arbitration_graphs/ +COPY LICENSE /tmp/arbitration_graphs/ +COPY README.md /tmp/arbitration_graphs/ +COPY version /tmp/arbitration_graphs/ COPY cmake /tmp/arbitration_graphs/cmake COPY gui /tmp/arbitration_graphs/gui COPY include /tmp/arbitration_graphs/include COPY test /tmp/arbitration_graphs/test -COPY version /tmp/arbitration_graphs/version RUN mkdir /tmp/arbitration_graphs/build && \ cd /tmp/arbitration_graphs/build && \ diff --git a/README.md b/README.md index 8bc935ea..0c89b9ee 100644 --- a/README.md +++ b/README.md @@ -153,3 +153,20 @@ Run all unit tests with CTest: cmake --build . --target test ``` + +### Serving the WebApp GUI + +The GUI consists of +- a web server with static WebApp files, see [`gui/app`](./gui/app) +- a websocket server providing the arbitration graph state to the WebApp + +In order to serve the WebApp files, their location must be known to the executable running the web server. +By default (and without further setup), we support these locations: +- the install path, i.e. `/opt/share/arbitration_graphs` +- the current source path for local builds, i.e. `/home/blinky/arbitration_graphs/gui/app/arbitration_graphs` (only works, if no installation has been found) + +If you intend to override these, please use the `APP_DIRECTORY` environment variable to define the WebApp path: + +``` +APP_DIRECTORY=/my/custom/app/path my_awesome_executable +``` \ No newline at end of file diff --git a/cmake/cpack_config.cmake b/cmake/cpack_config.cmake new file mode 100644 index 00000000..35ce67b1 --- /dev/null +++ b/cmake/cpack_config.cmake @@ -0,0 +1,42 @@ +# CPACK_PACKAGE_NAME and CPACK_PACKAGE_DESCRIPTION_SUMMARY are loaded from package variables +set(CPACK_PACKAGE_VENDOR "Karlsruhe Institute of Technology") +set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/KIT-MRT/arbitration_graphs") + +set(CPACK_VERBATIM_VARIABLES YES) + +set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME}) +set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_BINARY_DIR}/packages") + +set(CPACK_DEBIAN_PACKAGE_MAINTAINER "https://github.com/orzechow") + +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") +set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") + + +set(CPACK_GENERATOR "TGZ;ZIP;DEB") + +set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}") +set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) + +set(CPACK_COMPONENTS_GROUPING ONE_PER_GROUP) +set(CPACK_DEB_COMPONENT_INSTALL YES) +set(CPACK_ARCHIVE_COMPONENT_INSTALL YES) + +set(CPACK_DEBIAN_PACKAGE_SECTION "libdevel") +set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "all") + + +# Rename packages to kebab case +set(CPACK_DEBIAN_CORE_PACKAGE_NAME "libarbitration-graphs-core-dev") +set(CPACK_DEBIAN_GUI_PACKAGE_NAME "libarbitration-graphs-gui-dev") + +# Component-specific dependencies (make sure to use upper-case!) +set(CPACK_DEBIAN_CORE_PACKAGE_DEPENDS "libgoogle-glog-dev, libyaml-cpp-dev, libutil-caching-dev") +set(CPACK_DEBIAN_GUI_PACKAGE_DEPENDS "libarbitration-graphs-core-dev, Crow, zlib1g-dev") + +# Use fixed debian file names +set(CPACK_DEBIAN_CORE_FILE_NAME "${CPACK_DEBIAN_CORE_PACKAGE_NAME}.deb") +set(CPACK_DEBIAN_GUI_FILE_NAME "${CPACK_DEBIAN_GUI_PACKAGE_NAME}.deb") + +# Use CMAKE_INSTALL_PREFIX for CPack install paths aswell +set(CPACK_SET_DESTDIR true) diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt index 016eabaa..bbdc0040 100644 --- a/demo/CMakeLists.txt +++ b/demo/CMakeLists.txt @@ -49,7 +49,7 @@ endif() set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/") find_package(arbitration_graphs REQUIRED) find_package(EnTT_Pacman REQUIRED) -find_package(Glog) +find_package(Glog REQUIRED) find_package(SDL2 REQUIRED) find_package(util_caching REQUIRED) find_package(Yaml-cpp REQUIRED) @@ -59,7 +59,7 @@ find_package(Yaml-cpp REQUIRED) ## Build ## ########### -add_library(${PROJECT_NAME} STATIC +add_library(${PROJECT_NAME} SHARED src/astar.cpp src/avoid_ghost_behavior.cpp src/change_dot_cluster_behavior.cpp @@ -75,12 +75,15 @@ target_include_directories(${PROJECT_NAME} PRIVATE include ${SDL2_INCLUDE_DIR} ) -target_link_libraries(${PROJECT_NAME} PRIVATE +target_link_libraries(${PROJECT_NAME} PUBLIC arbitration_graphs - EnTT_Pacman + + glog::glog util_caching - ${SDL2_LIBRARY} ${YAML_CPP_LIBRARIES} + + EnTT_Pacman + ${SDL2_LIBRARY} ) add_executable(${PROJECT_NAME}_exe @@ -93,10 +96,24 @@ target_include_directories(${PROJECT_NAME}_exe PRIVATE ) target_link_libraries(${PROJECT_NAME}_exe PRIVATE ${PROJECT_NAME} - EnTT_Pacman - util_caching - ${SDL2_LIBRARY} - ${YAML_CPP_LIBRARIES} +) + + +################### +## Cmake Package ## +################### + +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + VERSION 0.1 + COMPATIBILITY AnyNewerVersion +) +include(CMakePackageConfigHelpers) +configure_package_config_file( + "${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION lib/cmake/${PROJECT_NAME} ) @@ -110,3 +127,27 @@ if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR ARBITRATION_GRAPHS_DEMO_CMAKE_BU AND BUILD_TESTS) add_subdirectory(test) endif() + + +############# +## Install ## +############# + +install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_exe + EXPORT ${PROJECT_NAME}Targets + COMPONENT demo + LIBRARY DESTINATION lib COMPONENT Runtime + ARCHIVE DESTINATION lib COMPONENT Development + RUNTIME DESTINATION bin COMPONENT Runtime + PUBLIC_HEADER DESTINATION include COMPONENT Development + BUNDLE DESTINATION bin COMPONENT Runtime) +install(EXPORT ${PROJECT_NAME}Targets + DESTINATION lib/cmake/${PROJECT_NAME} + COMPONENT demo) +install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + DESTINATION lib/cmake/${PROJECT_NAME} + COMPONENT demo) +install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ + DESTINATION include + COMPONENT demo) diff --git a/demo/Dockerfile b/demo/Dockerfile index 559a6087..1fc477ee 100644 --- a/demo/Dockerfile +++ b/demo/Dockerfile @@ -8,6 +8,7 @@ RUN apt-get update && \ apt-get install -y --no-install-recommends \ build-essential \ cmake \ + git \ libsdl2-dev && \ apt-get clean diff --git a/demo/cmake/arbitration_graphs_pacman_demoConfig.cmake.in b/demo/cmake/arbitration_graphs_pacman_demoConfig.cmake.in new file mode 100644 index 00000000..ff0fa672 --- /dev/null +++ b/demo/cmake/arbitration_graphs_pacman_demoConfig.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") +check_required_components("@PROJECT_NAME@") \ No newline at end of file diff --git a/demo/include/demo/types.hpp b/demo/include/demo/types.hpp index 75e18ec0..d1ae4ef2 100644 --- a/demo/include/demo/types.hpp +++ b/demo/include/demo/types.hpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include #include diff --git a/demo/include/utils/pacman_wrapper.hpp b/demo/include/utils/pacman_wrapper.hpp index f89f7422..0c5b2c93 100644 --- a/demo/include/utils/pacman_wrapper.hpp +++ b/demo/include/utils/pacman_wrapper.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include diff --git a/demo/src/pacman_wrapper.cpp b/demo/src/pacman_wrapper.cpp index 35c24d6f..d42b9ae5 100644 --- a/demo/src/pacman_wrapper.cpp +++ b/demo/src/pacman_wrapper.cpp @@ -1,6 +1,6 @@ #include "utils/pacman_wrapper.hpp" -#include +#include #include #include diff --git a/demo/test/CMakeLists.txt b/demo/test/CMakeLists.txt index 199d7415..14e4cece 100644 --- a/demo/test/CMakeLists.txt +++ b/demo/test/CMakeLists.txt @@ -1,9 +1,63 @@ +cmake_minimum_required(VERSION 3.22) + + +###################### +## Project settings ## +###################### + +# We support building this as top-level project, e.g. in order to test the lib installation +project(arbitration_graphs_demo_tests + LANGUAGES CXX +) + + +############### +## C++ setup ## +############### + +# Only do these if this is the main project, and not if it is included through add_subdirectory +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + # Require C++17 + set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + + # Let's ensure -std=c++xx instead of -std=g++xx + set(CMAKE_CXX_EXTENSIONS OFF) + + # Let's nicely support folders in IDEs + set_property(GLOBAL PROPERTY USE_FOLDERS ON) + + # Allow clangd and others to properly understand this C++ project + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + + # Testing only available if this is the main project + # Note this needs to be done in the main CMakeLists + # since it calls enable_testing, which must be in the + # main CMakeLists. + include(CTest) +endif() + + ################### ## Find packages ## ################### find_package(GTest) +# Find installed lib and its dependencies, if this is build as top-level project +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/") + + find_package(arbitration_graphs_pacman_demo REQUIRED) + + find_package(arbitration_graphs REQUIRED) + find_package(EnTT_Pacman REQUIRED) + find_package(Glog REQUIRED) + find_package(SDL2 REQUIRED) + find_package(util_caching REQUIRED) + find_package(Yaml-cpp REQUIRED) +endif() + ########### ## Build ## @@ -11,29 +65,30 @@ find_package(GTest) if(GTEST_FOUND) file(GLOB_RECURSE _tests CONFIGURE_DEPENDS "*.cpp" "*.cc") + list(FILTER _tests EXCLUDE REGEX "${CMAKE_CURRENT_BINARY_DIR}") foreach(_test ${_tests}) get_filename_component(_test_name ${_test} NAME_WE) # make sure we add only one -test to the target string(REGEX REPLACE "-test" "" TEST_TARGET_NAME ${_test_name}) - set(TEST_TARGET_NAME ${PROJECT_NAME}-gtest-${TEST_TARGET_NAME}) + set(TEST_TARGET_NAME arbitration_graphs_pacman_demo-gtest-${TEST_TARGET_NAME}) message(STATUS - "Adding gtest unittest \"${TEST_TARGET_NAME}\" with working dir ${PROJECT_SOURCE_DIR}/${TEST_FOLDER} \n _test: ${_test}" + "Adding gtest unittest \"${TEST_TARGET_NAME}\" with working dir ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_FOLDER} \n _test: ${_test}" ) add_executable(${TEST_TARGET_NAME} ${_test}) target_include_directories(${TEST_TARGET_NAME} PRIVATE - $ - $ + $ + $ ${SDL2_INCLUDE_DIR} ) target_link_libraries(${TEST_TARGET_NAME} PUBLIC ${GTEST_BOTH_LIBRARIES} pthread - ${PROJECT_NAME} + arbitration_graphs_pacman_demo arbitration_graphs EnTT_Pacman util_caching diff --git a/demo/test/cmake/modules/FindSDL2.cmake b/demo/test/cmake/modules/FindSDL2.cmake new file mode 100644 index 00000000..d3603af1 --- /dev/null +++ b/demo/test/cmake/modules/FindSDL2.cmake @@ -0,0 +1,172 @@ +# This module defines +# SDL2_LIBRARY, the name of the library to link against +# SDL2_FOUND, if false, do not try to link to SDL2 +# SDL2_INCLUDE_DIR, where to find SDL.h +# +# This module responds to the the flag: +# SDL2_BUILDING_LIBRARY +# If this is defined, then no SDL2main will be linked in because +# only applications need main(). +# Otherwise, it is assumed you are building an application and this +# module will attempt to locate and set the the proper link flags +# as part of the returned SDL2_LIBRARY variable. +# +# Don't forget to include SDLmain.h and SDLmain.m your project for the +# OS X framework based version. (Other versions link to -lSDL2main which +# this module will try to find on your behalf.) Also for OS X, this +# module will automatically add the -framework Cocoa on your behalf. +# +# +# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration +# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library +# (SDL2.dll, libsdl2.so, SDL2.framework, etc). +# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again. +# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value +# as appropriate. These values are used to generate the final SDL2_LIBRARY +# variable, but when these values are unset, SDL2_LIBRARY does not get created. +# +# +# $SDL2DIR is an environment variable that would +# correspond to the ./configure --prefix=$SDL2DIR +# used in building SDL2. +# l.e.galup 9-20-02 +# +# Modified by Eric Wing. +# Added code to assist with automated building by using environmental variables +# and providing a more controlled/consistent search behavior. +# Added new modifications to recognize OS X frameworks and +# additional Unix paths (FreeBSD, etc). +# Also corrected the header search path to follow "proper" SDL guidelines. +# Added a search for SDL2main which is needed by some platforms. +# Added a search for threads which is needed by some platforms. +# Added needed compile switches for MinGW. +# +# On OSX, this will prefer the Framework version (if found) over others. +# People will have to manually change the cache values of +# SDL2_LIBRARY to override this selection or set the CMake environment +# CMAKE_INCLUDE_PATH to modify the search paths. +# +# Note that the header path has changed from SDL2/SDL.h to just SDL.h +# This needed to change because "proper" SDL convention +# is #include "SDL.h", not . This is done for portability +# reasons because not all systems place things in SDL2/ (see FreeBSD). + +#============================================================================= +# Copyright 2003-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# message("") + +SET(SDL2_SEARCH_PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt + ${SDL2_PATH} +) + +FIND_PATH(SDL2_INCLUDE_DIR SDL.h + HINTS + $ENV{SDL2DIR} + PATH_SUFFIXES include/SDL2 include + PATHS ${SDL2_SEARCH_PATHS} +) + +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(PATH_SUFFIXES lib64 lib/x64 lib) +else() + set(PATH_SUFFIXES lib/x86 lib) +endif() + +FIND_LIBRARY(SDL2_LIBRARY_TEMP + NAMES SDL2 + HINTS + $ENV{SDL2DIR} + PATH_SUFFIXES ${PATH_SUFFIXES} + PATHS ${SDL2_SEARCH_PATHS} +) + +IF(NOT SDL2_BUILDING_LIBRARY) + IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") + # Non-OS X framework versions expect you to also dynamically link to + # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms + # seem to provide SDL2main for compatibility even though they don't + # necessarily need it. + FIND_LIBRARY(SDL2MAIN_LIBRARY + NAMES SDL2main + HINTS + $ENV{SDL2DIR} + PATH_SUFFIXES ${PATH_SUFFIXES} + PATHS ${SDL2_SEARCH_PATHS} + ) + ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") +ENDIF(NOT SDL2_BUILDING_LIBRARY) + +# SDL2 may require threads on your system. +# The Apple build may not need an explicit flag because one of the +# frameworks may already provide it. +# But for non-OSX systems, I will use the CMake Threads package. +IF(NOT APPLE) + FIND_PACKAGE(Threads) +ENDIF(NOT APPLE) + +# MinGW needs an additional link flag, -mwindows +# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -mwindows +IF(MINGW) + SET(MINGW32_LIBRARY mingw32 "-mwindows" CACHE STRING "mwindows for MinGW") +ENDIF(MINGW) + +IF(SDL2_LIBRARY_TEMP) + # For SDL2main + IF(NOT SDL2_BUILDING_LIBRARY) + IF(SDL2MAIN_LIBRARY) + SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP}) + ENDIF(SDL2MAIN_LIBRARY) + ENDIF(NOT SDL2_BUILDING_LIBRARY) + + # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa. + # CMake doesn't display the -framework Cocoa string in the UI even + # though it actually is there if I modify a pre-used variable. + # I think it has something to do with the CACHE STRING. + # So I use a temporary variable until the end so I can set the + # "real" variable in one-shot. + IF(APPLE) + SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa") + ENDIF(APPLE) + + # For threads, as mentioned Apple doesn't need this. + # In fact, there seems to be a problem if I used the Threads package + # and try using this line, so I'm just skipping it entirely for OS X. + IF(NOT APPLE) + SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT}) + ENDIF(NOT APPLE) + + # For MinGW library + IF(MINGW) + SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP}) + ENDIF(MINGW) + + # Set the final string here so the GUI reflects the final state. + SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found") + # Set the temp variable to INTERNAL so it is not seen in the CMake GUI + SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "") +ENDIF(SDL2_LIBRARY_TEMP) + +# message("") + +INCLUDE(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR) diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index 045baf89..a87c113b 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -3,17 +3,19 @@ cmake_minimum_required(VERSION 3.22) -################ -## Crow setup ## -################ +############### +## GUI setup ## +############### # Pass install data directory to the Crow web server, # as the Web App files will be located there include(GNUInstallDirs) -set(CMAKE_CROW_STATIC_DIRECTORY ${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}) -message("Install directory for WebApp GUI: CROW_STATIC_DIRECTORY=${CMAKE_CROW_STATIC_DIRECTORY}") +set(INSTALL_APP_DIRECTORY ${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}) +set(LOCAL_APP_DIRECTORY ${CMAKE_SOURCE_DIR}/gui/app/${PROJECT_NAME}) +message(STATUS "Install directory for WebApp GUI: INSTALL_APP_DIRECTORY=${INSTALL_APP_DIRECTORY}") +message(STATUS "Local directory for WebApp GUI: LOCAL_APP_DIRECTORY=${LOCAL_APP_DIRECTORY}") configure_file ( "${PROJECT_SOURCE_DIR}/gui/include/arbitration_graphs/gui/crow_config.hpp.in" "${PROJECT_BINARY_DIR}/include/arbitration_graphs/gui/crow_config.hpp" @@ -49,12 +51,24 @@ target_link_libraries(${PROJECT_NAME}_gui INTERFACE ## Install ## ############# -set(INSTALL_TARGETS ${INSTALL_TARGETS} ${PROJECT_NAME}_gui PARENT_SCOPE) -install(DIRECTORY htmlroot/ DESTINATION ${CMAKE_CROW_STATIC_DIRECTORY}) -install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION include - PATTERN "*.in" EXCLUDE -) -install(DIRECTORY ${CMAKE_BINARY_DIR}/include/ DESTINATION include) +install(TARGETS ${PROJECT_NAME}_gui + EXPORT ${PROJECT_NAME}_guiTargets + COMPONENT gui + LIBRARY DESTINATION lib COMPONENT Runtime + ARCHIVE DESTINATION lib COMPONENT Development + RUNTIME DESTINATION bin COMPONENT Runtime + PUBLIC_HEADER DESTINATION include COMPONENT Development + BUNDLE DESTINATION bin COMPONENT Runtime) +install(DIRECTORY app/ + TYPE DATA + COMPONENT gui) +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ + DESTINATION include + COMPONENT gui + PATTERN "*.in" EXCLUDE) +install(DIRECTORY ${CMAKE_BINARY_DIR}/include/ + DESTINATION include + COMPONENT gui) ############# diff --git a/gui/htmlroot/arbitrator_option.js b/gui/app/arbitration_graphs/arbitrator_option.js similarity index 100% rename from gui/htmlroot/arbitrator_option.js rename to gui/app/arbitration_graphs/arbitrator_option.js diff --git a/gui/htmlroot/example.yaml b/gui/app/arbitration_graphs/example.yaml similarity index 100% rename from gui/htmlroot/example.yaml rename to gui/app/arbitration_graphs/example.yaml diff --git a/gui/htmlroot/example_nested.yaml b/gui/app/arbitration_graphs/example_nested.yaml similarity index 100% rename from gui/htmlroot/example_nested.yaml rename to gui/app/arbitration_graphs/example_nested.yaml diff --git a/gui/htmlroot/example_nested_mixed_costs.yaml b/gui/app/arbitration_graphs/example_nested_mixed_costs.yaml similarity index 100% rename from gui/htmlroot/example_nested_mixed_costs.yaml rename to gui/app/arbitration_graphs/example_nested_mixed_costs.yaml diff --git a/gui/htmlroot/example_nested_negative_costs.yaml b/gui/app/arbitration_graphs/example_nested_negative_costs.yaml similarity index 100% rename from gui/htmlroot/example_nested_negative_costs.yaml rename to gui/app/arbitration_graphs/example_nested_negative_costs.yaml diff --git a/gui/htmlroot/icons.js b/gui/app/arbitration_graphs/icons.js similarity index 100% rename from gui/htmlroot/icons.js rename to gui/app/arbitration_graphs/icons.js diff --git a/gui/htmlroot/index.css b/gui/app/arbitration_graphs/index.css similarity index 100% rename from gui/htmlroot/index.css rename to gui/app/arbitration_graphs/index.css diff --git a/gui/htmlroot/index.html b/gui/app/arbitration_graphs/index.html similarity index 100% rename from gui/htmlroot/index.html rename to gui/app/arbitration_graphs/index.html diff --git a/gui/htmlroot/index.js b/gui/app/arbitration_graphs/index.js similarity index 100% rename from gui/htmlroot/index.js rename to gui/app/arbitration_graphs/index.js diff --git a/gui/htmlroot/inline_style.js b/gui/app/arbitration_graphs/inline_style.js similarity index 100% rename from gui/htmlroot/inline_style.js rename to gui/app/arbitration_graphs/inline_style.js diff --git a/gui/htmlroot/svg.css b/gui/app/arbitration_graphs/svg.css similarity index 100% rename from gui/htmlroot/svg.css rename to gui/app/arbitration_graphs/svg.css diff --git a/gui/htmlroot/svg_filters.xml b/gui/app/arbitration_graphs/svg_filters.xml similarity index 100% rename from gui/htmlroot/svg_filters.xml rename to gui/app/arbitration_graphs/svg_filters.xml diff --git a/gui/htmlroot/thirdparty/browser_detect.js b/gui/app/arbitration_graphs/thirdparty/browser_detect.js similarity index 100% rename from gui/htmlroot/thirdparty/browser_detect.js rename to gui/app/arbitration_graphs/thirdparty/browser_detect.js diff --git a/gui/htmlroot/thirdparty/fontawesome-free/LICENSE.txt b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/LICENSE.txt similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/LICENSE.txt rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/LICENSE.txt diff --git a/gui/htmlroot/thirdparty/fontawesome-free/attribution.js b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/attribution.js similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/attribution.js rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/attribution.js diff --git a/gui/htmlroot/thirdparty/fontawesome-free/css/all.css b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/all.css similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/css/all.css rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/all.css diff --git a/gui/htmlroot/thirdparty/fontawesome-free/css/all.min.css b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/all.min.css similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/css/all.min.css rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/all.min.css diff --git a/gui/htmlroot/thirdparty/fontawesome-free/css/brands.css b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/brands.css similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/css/brands.css rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/brands.css diff --git a/gui/htmlroot/thirdparty/fontawesome-free/css/brands.min.css b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/brands.min.css similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/css/brands.min.css rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/brands.min.css diff --git a/gui/htmlroot/thirdparty/fontawesome-free/css/fontawesome.css b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/fontawesome.css similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/css/fontawesome.css rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/fontawesome.css diff --git a/gui/htmlroot/thirdparty/fontawesome-free/css/fontawesome.min.css b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/fontawesome.min.css similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/css/fontawesome.min.css rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/fontawesome.min.css diff --git a/gui/htmlroot/thirdparty/fontawesome-free/css/regular.css b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/regular.css similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/css/regular.css rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/regular.css diff --git a/gui/htmlroot/thirdparty/fontawesome-free/css/regular.min.css b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/regular.min.css similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/css/regular.min.css rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/regular.min.css diff --git a/gui/htmlroot/thirdparty/fontawesome-free/css/solid.css b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/solid.css similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/css/solid.css rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/solid.css diff --git a/gui/htmlroot/thirdparty/fontawesome-free/css/solid.min.css b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/solid.min.css similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/css/solid.min.css rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/solid.min.css diff --git a/gui/htmlroot/thirdparty/fontawesome-free/css/svg-with-js.css b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/svg-with-js.css similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/css/svg-with-js.css rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/svg-with-js.css diff --git a/gui/htmlroot/thirdparty/fontawesome-free/css/svg-with-js.min.css b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/svg-with-js.min.css similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/css/svg-with-js.min.css rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/svg-with-js.min.css diff --git a/gui/htmlroot/thirdparty/fontawesome-free/css/v4-shims.css b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/v4-shims.css similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/css/v4-shims.css rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/v4-shims.css diff --git a/gui/htmlroot/thirdparty/fontawesome-free/css/v4-shims.min.css b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/v4-shims.min.css similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/css/v4-shims.min.css rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/css/v4-shims.min.css diff --git a/gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-brands-400.eot b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-brands-400.eot similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-brands-400.eot rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-brands-400.eot diff --git a/gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-brands-400.svg b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-brands-400.svg similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-brands-400.svg rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-brands-400.svg diff --git a/gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-brands-400.ttf b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-brands-400.ttf similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-brands-400.ttf rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-brands-400.ttf diff --git a/gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-brands-400.woff b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-brands-400.woff similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-brands-400.woff rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-brands-400.woff diff --git a/gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-brands-400.woff2 b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-brands-400.woff2 similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-brands-400.woff2 rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-brands-400.woff2 diff --git a/gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-regular-400.eot b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-regular-400.eot similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-regular-400.eot rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-regular-400.eot diff --git a/gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-regular-400.svg b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-regular-400.svg similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-regular-400.svg rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-regular-400.svg diff --git a/gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-regular-400.ttf b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-regular-400.ttf similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-regular-400.ttf rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-regular-400.ttf diff --git a/gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-regular-400.woff b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-regular-400.woff similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-regular-400.woff rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-regular-400.woff diff --git a/gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-regular-400.woff2 b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-regular-400.woff2 similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-regular-400.woff2 rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-regular-400.woff2 diff --git a/gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-solid-900.eot b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-solid-900.eot similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-solid-900.eot rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-solid-900.eot diff --git a/gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-solid-900.svg b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-solid-900.svg similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-solid-900.svg rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-solid-900.svg diff --git a/gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-solid-900.ttf b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-solid-900.ttf similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-solid-900.ttf rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-solid-900.ttf diff --git a/gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-solid-900.woff b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-solid-900.woff similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-solid-900.woff rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-solid-900.woff diff --git a/gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-solid-900.woff2 b/gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-solid-900.woff2 similarity index 100% rename from gui/htmlroot/thirdparty/fontawesome-free/webfonts/fa-solid-900.woff2 rename to gui/app/arbitration_graphs/thirdparty/fontawesome-free/webfonts/fa-solid-900.woff2 diff --git a/gui/htmlroot/thirdparty/js-yaml.min.js b/gui/app/arbitration_graphs/thirdparty/js-yaml.min.js similarity index 100% rename from gui/htmlroot/thirdparty/js-yaml.min.js rename to gui/app/arbitration_graphs/thirdparty/js-yaml.min.js diff --git a/gui/htmlroot/thirdparty/vue.global.js b/gui/app/arbitration_graphs/thirdparty/vue.global.js similarity index 100% rename from gui/htmlroot/thirdparty/vue.global.js rename to gui/app/arbitration_graphs/thirdparty/vue.global.js diff --git a/gui/include/arbitration_graphs/gui/crow_config.hpp.in b/gui/include/arbitration_graphs/gui/crow_config.hpp.in index 9f285fbc..d9f9a380 100644 --- a/gui/include/arbitration_graphs/gui/crow_config.hpp.in +++ b/gui/include/arbitration_graphs/gui/crow_config.hpp.in @@ -1,4 +1,4 @@ #pragma once -#define CROW_STATIC_ENDPOINT "/" -#define CROW_STATIC_DIRECTORY "@CMAKE_CROW_STATIC_DIRECTORY@" \ No newline at end of file +#define INSTALL_APP_DIRECTORY "@INSTALL_APP_DIRECTORY@" +#define LOCAL_APP_DIRECTORY "@LOCAL_APP_DIRECTORY@" \ No newline at end of file diff --git a/gui/include/arbitration_graphs/gui/web_server.hpp b/gui/include/arbitration_graphs/gui/web_server.hpp index 602e0bb5..e811ae00 100644 --- a/gui/include/arbitration_graphs/gui/web_server.hpp +++ b/gui/include/arbitration_graphs/gui/web_server.hpp @@ -3,24 +3,26 @@ #include "crow_config.hpp" #include +#include #include #include #include + namespace arbitration_graphs::gui { class WebServer { public: WebServer(int port, bool autostart = false, crow::LogLevel loglevel = crow::LogLevel::Warning) - : port_{port}, autostart_{autostart} { + : static_directory_{crow::utility::normalize_path(dataDirectory())}, port_{port}, autostart_{autostart} { app_.loglevel(loglevel); CROW_ROUTE(app_, "/") - ([]() { + ([this]() { crow::response response; - response.set_static_file_info_unsafe(std::string{CROW_STATIC_DIRECTORY} + "/index.html"); + response.set_static_file_info_unsafe(static_directory_ + "/index.html"); return response; }); @@ -39,6 +41,14 @@ class WebServer { CROW_LOG_DEBUG << "Received message: " << message; }); + CROW_ROUTE(app_, "/") + ([this](std::string file_path_partial) { + crow::response response; + crow::utility::sanitize_filename(file_path_partial); + response.set_static_file_info_unsafe(static_directory_ + file_path_partial); + return response; + }); + if (autostart_) { // We need to store the std::future to run Crow asynchronously _f = start(); @@ -53,7 +63,7 @@ class WebServer { // Function to start the server std::future start() { - CROW_LOG_INFO << "Serving WebApp from " << CROW_STATIC_DIRECTORY; + CROW_LOG_INFO << "Serving WebApp from " << static_directory_; return app_.port(port_).multithreaded().run_async(); } @@ -77,11 +87,42 @@ class WebServer { } private: + std::string dataDirectory() { + namespace fs = std::filesystem; + + // Check the APP_DIRECTORY environment variable + if (const char* pathEnv = std::getenv("APP_DIRECTORY")) { + fs::path dir = fs::path(pathEnv); + if (fs::exists(dir) && fs::is_directory(dir)) { + return dir; + } + } + + // Check if the install directory works + if (fs::exists(INSTALL_APP_DIRECTORY) && fs::is_directory(INSTALL_APP_DIRECTORY)) { + return INSTALL_APP_DIRECTORY; + } + + // Check if the local source directory works + if (fs::exists(LOCAL_APP_DIRECTORY) && fs::is_directory(LOCAL_APP_DIRECTORY)) { + return LOCAL_APP_DIRECTORY; + } + + // Return an empty path if not found + CROW_LOG_WARNING << "App data directory not found! Defaulting to \"app/\"" + << " Searched in these paths: INSTALL_APP_DIRECTORY=" << INSTALL_APP_DIRECTORY + << " LOCAL_APP_DIRECTORY=" << LOCAL_APP_DIRECTORY + << " APP_DIRECTORY=" << std::getenv("APP_DIRECTORY"); + return "app/"; + } + crow::SimpleApp app_; std::set connections_; std::mutex connections_mutex_; std::future _f; + const std::string static_directory_; + int port_; bool autostart_; }; diff --git a/gui/test/CMakeLists.txt b/gui/test/CMakeLists.txt index 7fa9fe98..81dad2ed 100644 --- a/gui/test/CMakeLists.txt +++ b/gui/test/CMakeLists.txt @@ -1,9 +1,60 @@ +cmake_minimum_required(VERSION 3.22) + + +###################### +## Project settings ## +###################### + +# We support building this as top-level project, e.g. in order to test the lib installation +project(arbitration_graphs_gui_tests + LANGUAGES CXX +) + + +############### +## C++ setup ## +############### + +# Only do these if this is the main project, and not if it is included through add_subdirectory +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + # Require C++17 + set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + + # Let's ensure -std=c++xx instead of -std=g++xx + set(CMAKE_CXX_EXTENSIONS OFF) + + # Let's nicely support folders in IDEs + set_property(GLOBAL PROPERTY USE_FOLDERS ON) + + # Allow clangd and others to properly understand this C++ project + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + + # Testing only available if this is the main project + # Note this needs to be done in the main CMakeLists + # since it calls enable_testing, which must be in the + # main CMakeLists. + include(CTest) +endif() + + ################### ## Find packages ## ################### find_package(GTest) +# Find installed lib and its dependencies, if this is build as top-level project +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + find_package(Glog REQUIRED) + find_package(util_caching REQUIRED) + find_package(Yaml-cpp REQUIRED) + + find_package(arbitration_graphs REQUIRED) + + find_package(Crow REQUIRED) +endif() + ########### ## Build ## @@ -11,29 +62,31 @@ find_package(GTest) if(GTEST_FOUND) file(GLOB_RECURSE _tests CONFIGURE_DEPENDS "*.cpp" "*.cc") + list(FILTER _tests EXCLUDE REGEX "${CMAKE_CURRENT_BINARY_DIR}") foreach(_test ${_tests}) get_filename_component(_test_name ${_test} NAME_WE) # make sure we add only one -test to the target string(REGEX REPLACE "-test" "" TEST_TARGET_NAME ${_test_name}) - set(TEST_TARGET_NAME ${PROJECT_NAME}-gtest-${TEST_TARGET_NAME}) + set(TEST_TARGET_NAME arbitration_graphs_gui_tests-gtest-${TEST_TARGET_NAME}) message(STATUS - "Adding gtest unittest \"${TEST_TARGET_NAME}\" with working dir ${PROJECT_SOURCE_DIR}/${TEST_FOLDER} \n _test: ${_test}" + "Adding gtest unittest \"${TEST_TARGET_NAME}\" with working dir ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_FOLDER} \n _test: ${_test}" ) add_executable(${TEST_TARGET_NAME} ${_test}) target_include_directories(${TEST_TARGET_NAME} PRIVATE - $ - $ - $ - $ + $ + $ + $ + $ + $/gui ) target_link_libraries(${TEST_TARGET_NAME} PUBLIC ${GTEST_BOTH_LIBRARIES} pthread - ${PROJECT_NAME} + arbitration_graphs ) add_test(NAME ${TEST_TARGET_NAME} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ed4e4abb..8a7878f7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,9 +1,58 @@ +cmake_minimum_required(VERSION 3.22) + + +###################### +## Project settings ## +###################### + +# We support building this as top-level project, e.g. in order to test the lib installation +project(arbitration_graphs_tests + LANGUAGES CXX +) + + +############### +## C++ setup ## +############### + +# Only do these if this is the main project, and not if it is included through add_subdirectory +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + # Require C++17 + set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + + # Let's ensure -std=c++xx instead of -std=g++xx + set(CMAKE_CXX_EXTENSIONS OFF) + + # Let's nicely support folders in IDEs + set_property(GLOBAL PROPERTY USE_FOLDERS ON) + + # Allow clangd and others to properl y understand this C++ project + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + + # Testing only available if this is the main project + # Note this needs to be done in the main CMakeLists + # since it calls enable_testing, which must be in the + # main CMakeLists. + include(CTest) +endif() + + ################### ## Find packages ## ################### find_package(GTest) +# Find installed lib and its dependencies, if this is build as top-level project +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + find_package(Glog REQUIRED) + find_package(util_caching REQUIRED) + find_package(Yaml-cpp REQUIRED) + + find_package(arbitration_graphs REQUIRED) +endif() + ########### ## Build ## @@ -11,22 +60,23 @@ find_package(GTest) if(GTEST_FOUND) file(GLOB_RECURSE _tests CONFIGURE_DEPENDS "*.cpp" "*.cc") + list(FILTER _tests EXCLUDE REGEX "${CMAKE_CURRENT_BINARY_DIR}") foreach(_test ${_tests}) get_filename_component(_test_name ${_test} NAME_WE) # make sure we add only one -test to the target string(REGEX REPLACE "-test" "" TEST_TARGET_NAME ${_test_name}) - set(TEST_TARGET_NAME ${PROJECT_NAME}-gtest-${TEST_TARGET_NAME}) + set(TEST_TARGET_NAME arbitration_graphs-gtest-${TEST_TARGET_NAME}) message(STATUS - "Adding gtest unittest \"${TEST_TARGET_NAME}\" with working dir ${PROJECT_SOURCE_DIR}/${TEST_FOLDER} \n _test: ${_test}" + "Adding gtest unittest \"${TEST_TARGET_NAME}\" with working dir ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_FOLDER} \n _test: ${_test}" ) add_executable(${TEST_TARGET_NAME} ${_test}) target_link_libraries(${TEST_TARGET_NAME} PUBLIC ${GTEST_BOTH_LIBRARIES} pthread - ${PROJECT_NAME} + arbitration_graphs ) add_test(NAME ${TEST_TARGET_NAME}