Skip to content

Commit

Permalink
added install target
Browse files Browse the repository at this point in the history
  • Loading branch information
K20shores committed Jan 10, 2024
1 parent 280f2a2 commit 98ff5c9
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 10 deletions.
37 changes: 37 additions & 0 deletions cmake/cmake_uninstall.cmake.in
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 5 additions & 0 deletions cmake/mechanism_configurationConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@_Exports.cmake")

check_required_components("@PROJECT_NAME@")
5 changes: 1 addition & 4 deletions include/open_atmos/mechanism_configuration/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <filesystem>
#include <fstream>
#include <iostream>
#include <nlohmann/json.hpp>

namespace open_atmos
{
Expand Down Expand Up @@ -73,8 +72,6 @@ namespace open_atmos

class JsonReaderPolicy
{
using json = nlohmann::json;

public:

/// @brief Parse configures
Expand All @@ -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);
}
Expand Down
71 changes: 71 additions & 0 deletions packaging/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 3 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

target_link_libraries(mechanism_configuration PUBLIC nlohmann_json::nlohmann_json)
target_link_libraries(mechanism_configuration PRIVATE nlohmann_json::nlohmann_json)
3 changes: 2 additions & 1 deletion src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
// SPDX-License-Identifier: Apache-2.0

#include <open_atmos/mechanism_configuration/parser.hpp>
#include <nlohmann/json.hpp>

namespace open_atmos
{
namespace mechanism_configuration
{
// explicit template instanatiation
template class ConfigurationReader<JsonReaderPolicy> json_reader;
template class ConfigurationReader<JsonReaderPolicy>;

ConfigParseStatus JsonReaderPolicy::Parse(const std::filesystem::path &config_path) {
return ConfigParseStatus::Success;
Expand Down
4 changes: 2 additions & 2 deletions test/unit/test_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#include <open_atmos/mechanism_configuration/parser.hpp>

using open_atmos::mechanism_configuration;
using namespace open_atmos::mechanism_configuration;

TEST(Parser, Returns)
{
ConfigurationReader reader;
ConfigurationReader<JsonReaderPolicy> reader;
}

0 comments on commit 98ff5c9

Please sign in to comment.