mirror of
https://github.com/modelec/cpp-lib.git
synced 2026-01-18 16:17:22 +01:00
more versatile cmake
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.25)
|
cmake_minimum_required(VERSION 3.25)
|
||||||
project(ModelecProject VERSION 1.0.0 LANGUAGES CXX DESCRIPTION "Modelec Lib")
|
project(ModelecProject VERSION 1.1.0 LANGUAGES CXX DESCRIPTION "Modelec Lib")
|
||||||
|
|
||||||
# Define default install path if not provided
|
# Define default install path if not provided
|
||||||
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
||||||
@@ -9,13 +9,24 @@ endif()
|
|||||||
# Library and executable paths
|
# Library and executable paths
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
# Function to safely add a component
|
||||||
|
function(add_component component_dir)
|
||||||
|
if(IS_DIRECTORY ${component_dir})
|
||||||
|
if(EXISTS ${component_dir}/CMakeLists.txt)
|
||||||
|
message(STATUS "Adding component: ${component_dir}")
|
||||||
|
add_subdirectory(${component_dir})
|
||||||
|
else()
|
||||||
|
message(WARNING "Skipping component: ${component_dir} (no CMakeLists.txt found)")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(WARNING "Skipping invalid directory: ${component_dir}")
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
# Automatically add subdirectories found in the components directory
|
# Automatically add subdirectories found in the components directory
|
||||||
file(GLOB children RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/components ${CMAKE_CURRENT_SOURCE_DIR}/components/*)
|
file(GLOB children RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/components ${CMAKE_CURRENT_SOURCE_DIR}/components/*)
|
||||||
foreach(child ${children})
|
foreach(child ${children})
|
||||||
if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/components/${child})
|
add_component(${CMAKE_CURRENT_SOURCE_DIR}/components/${child})
|
||||||
message(STATUS "Adding component: ${child}")
|
|
||||||
add_subdirectory(components/${child})
|
|
||||||
endif()
|
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
# Configuration for installation and find_package()
|
# Configuration for installation and find_package()
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class CLParser {
|
class CLParser {
|
||||||
|
|
||||||
@@ -79,8 +80,10 @@ public:
|
|||||||
|
|
||||||
~CLParser();
|
~CLParser();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string* _argv;
|
std::vector<std::string> _argv;
|
||||||
int _argc;
|
int _argc;
|
||||||
|
|
||||||
std::map<std::string, std::string> _options;
|
std::map<std::string, std::string> _options;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include <Modelec/CLParser.h>
|
#include <Modelec/CLParser.h>
|
||||||
|
|
||||||
CLParser::CLParser(int argc, char **argv) : _argc(argc) {
|
CLParser::CLParser(int argc, char **argv) : _argc(argc) {
|
||||||
this->_argv = new std::string[argc];
|
this->_argv = std::vector<std::string>(argc);
|
||||||
for (int i = 0; i < argc; i++) {
|
for (int i = 0; i < argc; i++) {
|
||||||
this->_argv[i] = argv[i];
|
this->_argv[i] = argv[i];
|
||||||
}
|
}
|
||||||
@@ -54,15 +54,6 @@ int CLParser::positionalArgumentsCount() const {
|
|||||||
return this->_argc;
|
return this->_argc;
|
||||||
}
|
}
|
||||||
|
|
||||||
CLParser::~CLParser() {
|
CLParser::~CLParser() = default;
|
||||||
delete[] this->_argv;
|
|
||||||
}
|
|
||||||
|
|
||||||
CLParser::CLParser(const CLParser &other) : _argc(other._argc) {
|
CLParser::CLParser(const CLParser &other) = default;
|
||||||
this->_argv = new std::string[other._argc];
|
|
||||||
for (int i = 0; i < other._argc; i++) {
|
|
||||||
this->_argv[i] = other._argv[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
this->_options = other._options;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user