From 98ff5c95de77032d0a656633ad1629af3f0aef17 Mon Sep 17 00:00:00 2001 From: Kyle Shores Date: Wed, 10 Jan 2024 13:28:45 -0600 Subject: [PATCH] added install target --- cmake/cmake_uninstall.cmake.in | 37 ++++++++++ cmake/mechanism_configurationConfig.cmake.in | 5 ++ .../mechanism_configuration/parser.hpp | 5 +- packaging/CMakeLists.txt | 71 +++++++++++++++++++ src/CMakeLists.txt | 6 +- src/parser.cpp | 3 +- test/unit/test_parser.cpp | 4 +- 7 files changed, 121 insertions(+), 10 deletions(-) create mode 100644 cmake/cmake_uninstall.cmake.in create mode 100644 cmake/mechanism_configurationConfig.cmake.in diff --git a/cmake/cmake_uninstall.cmake.in b/cmake/cmake_uninstall.cmake.in new file mode 100644 index 0000000..1fd04b5 --- /dev/null +++ b/cmake/cmake_uninstall.cmake.in @@ -0,0 +1,37 @@ +# https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake + +if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") + message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt") +endif() + +file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files) +string(REGEX REPLACE "\n" ";" files "${files}") +foreach(file ${files}) + message(STATUS "Uninstalling $ENV{DESTDIR}${file}") + if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") + exec_program( + "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" + OUTPUT_VARIABLE rm_out + RETURN_VALUE rm_retval + ) + if(NOT "${rm_retval}" STREQUAL 0) + message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") + endif() + else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") + message(STATUS "File $ENV{DESTDIR}${file} does not exist.") + endif() +endforeach() + +set(uninstall_dirs "@INSTALL_PREFIX@;@cmake_config_install_location@") + +foreach(dir IN LISTS uninstall_dirs) + message(STATUS "Uninstalling ${dir}") + exec_program( + "@CMAKE_COMMAND@" ARGS "-E remove_directory ${dir}" + OUTPUT_VARIABLE rm_out + RETURN_VALUE rm_retval + ) + if(NOT "${rm_retval}" STREQUAL 0) + message(FATAL_ERROR "Problem when removing ${dir}") + endif() +endforeach() diff --git a/cmake/mechanism_configurationConfig.cmake.in b/cmake/mechanism_configurationConfig.cmake.in new file mode 100644 index 0000000..3cc6a43 --- /dev/null +++ b/cmake/mechanism_configurationConfig.cmake.in @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@_Exports.cmake") + +check_required_components("@PROJECT_NAME@") \ No newline at end of file diff --git a/include/open_atmos/mechanism_configuration/parser.hpp b/include/open_atmos/mechanism_configuration/parser.hpp index 830d866..d3f0645 100644 --- a/include/open_atmos/mechanism_configuration/parser.hpp +++ b/include/open_atmos/mechanism_configuration/parser.hpp @@ -8,7 +8,6 @@ #include #include #include -#include namespace open_atmos { @@ -73,8 +72,6 @@ namespace open_atmos class JsonReaderPolicy { - using json = nlohmann::json; - public: /// @brief Parse configures @@ -93,7 +90,7 @@ namespace open_atmos /// @brief Reads and parses configures /// @param config_dir Path to a the configuration directory /// @return an enum indicating the success or failure of the parse - [[nodiscard]] ConfigParseStatus ReadAndParse(const std::filesystem::path &config_dir); + [[nodiscard]] ConfigParseStatus ReadAndParse(const std::filesystem::path &config_dir) { return this->Parse(config_dir); } diff --git a/packaging/CMakeLists.txt b/packaging/CMakeLists.txt index e69de29..a091cd0 100644 --- a/packaging/CMakeLists.txt +++ b/packaging/CMakeLists.txt @@ -0,0 +1,71 @@ +include(CMakePackageConfigHelpers) +include(GNUInstallDirs) +set(INSTALL_PREFIX "mechanism_configuration-${PROJECT_VERSION}" ) + +install( + TARGETS + mechanism_configuration + EXPORT + mechanism_configuration_Exports + LIBRARY DESTINATION ${INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR} + INCLUDES DESTINATION ${INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR} + PUBLIC_HEADER DESTINATION ${INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR} +) + +install( + DIRECTORY + ${PROJECT_SOURCE_DIR}/include/open_atmos + DESTINATION + ${INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR} +) + + +install(TARGETS nlohmann_json EXPORT mechanism_configuration_Exports) + +# install the cmake config files +set(cmake_config_install_location ${INSTALL_PREFIX}/cmake) + +install( + EXPORT + mechanism_configuration_Exports + DESTINATION + ${cmake_config_install_location} + NAMESPACE open_atmos:: +) + +configure_package_config_file( + "${PROJECT_SOURCE_DIR}/cmake/mechanism_configurationConfig.cmake.in" + "${PROJECT_BINARY_DIR}/mechanism_configurationConfig.cmake" + INSTALL_DESTINATION + ${cmake_config_install_location} +) + +write_basic_package_version_file( + "${PROJECT_BINARY_DIR}/mechanism_configurationConfigVersion.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion +) + +install( + FILES + ${PROJECT_BINARY_DIR}/mechanism_configurationConfig.cmake + ${PROJECT_BINARY_DIR}/mechanism_configurationConfigVersion.cmake + DESTINATION + ${cmake_config_install_location} +) + +###################################################################### +# uninstall target + +# https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake +if(NOT TARGET uninstall) + configure_file( + "${PROJECT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" + IMMEDIATE @ONLY) + + add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) +endif() \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2d0c1de..186904e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,17 +5,17 @@ configure_file(version.hpp.in ${PROJECT_SOURCE_DIR}/include/open_atmos/mechanism add_library(mechanism_configuration) add_library(open_atmos::mechanism_configuration ALIAS mechanism_configuration) +target_compile_features(mechanism_configuration PUBLIC cxx_std_20) + target_sources(mechanism_configuration PRIVATE parser.cpp ) -message(STATUS "Path: ${PROJECT_SOURCE_DIR}/include") - target_include_directories(mechanism_configuration PUBLIC $ $ ) -target_link_libraries(mechanism_configuration PUBLIC nlohmann_json::nlohmann_json) \ No newline at end of file +target_link_libraries(mechanism_configuration PRIVATE nlohmann_json::nlohmann_json) \ No newline at end of file diff --git a/src/parser.cpp b/src/parser.cpp index 3df20e9..652d998 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -3,13 +3,14 @@ // SPDX-License-Identifier: Apache-2.0 #include +#include namespace open_atmos { namespace mechanism_configuration { // explicit template instanatiation - template class ConfigurationReader json_reader; + template class ConfigurationReader; ConfigParseStatus JsonReaderPolicy::Parse(const std::filesystem::path &config_path) { return ConfigParseStatus::Success; diff --git a/test/unit/test_parser.cpp b/test/unit/test_parser.cpp index b8688e3..b5b9873 100644 --- a/test/unit/test_parser.cpp +++ b/test/unit/test_parser.cpp @@ -2,9 +2,9 @@ #include -using open_atmos::mechanism_configuration; +using namespace open_atmos::mechanism_configuration; TEST(Parser, Returns) { - ConfigurationReader reader; + ConfigurationReader reader; } \ No newline at end of file