Compare commits

..

3 Commits

6 changed files with 100 additions and 16 deletions
+26 -4
View File
@@ -10,11 +10,33 @@ find_package(CLI11 REQUIRED)
set(BUILD_DIR "${PROJECT_SOURCE_DIR}/build") set(BUILD_DIR "${PROJECT_SOURCE_DIR}/build")
set(CLI11_DIR ${BUILD_DIR}) set(CLI11_DIR ${BUILD_DIR})
file(GLOB SOURCES "src/*.cpp") # include_directories(include)
add_executable(${PROJECT_NAME} ${SOURCES}) add_library(challenge SHARED
target_link_libraries(${PROJECT_NAME} CLI11::CLI11) src/File.cpp
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin) )
target_include_directories(challenge PUBLIC include)
add_executable(${PROJECT_NAME}
src/cppchallenge.cpp
)
target_link_libraries(${PROJECT_NAME}
CLI11::CLI11
challenge
)
set_target_properties(${PROJECT_NAME}
PROPERTIES
PUBLIC_HEADER
include/File.h
)
install(TARGETS ${PROJECT_NAME} challenge
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
PUBLIC_HEADER DESTINATION include
)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(packdeb) include(packdeb)
+44 -1
View File
@@ -1 +1,44 @@
A basic C++ exercise. A basic C++ exercise which uses `conan` to satisfy dependencies before building a shared library and
an executable that links it. Also produces a `.deb` package which installs the executable, library,
and public headers.
## Prerequisites
* Ubuntu 22.04 (or equivalent)
* Additional required packages:
* `g++`
* `cmake`
* `python3-venv`
## Setup
Create a `python` virtual environment, install `conan`, and create a default profile:
```bash
python3 -m venv conan.venv
source conan.venv/bin/activate
pip install conan
conan profile detect
```
## Building and running
1. To build, run:
```bash
./build.sh
```
2. The build command will generate a `deb` package in the `_packages` directory. To install (to
`/usr/local`) run:
```
sudo dpkg -i _packages/_packages/cppchallenge_1.0.0_*.deb
sudo ldconfig
```
__TODO__: The `sudo ldconfig` step should be added to the `deb` package `postinst` step...
3. To run:
```
$ cppchallenge
Hello World!
File name is: aname
$ cppchallenge --help
Just a simple 'hello'
Usage: cppchallenge [OPTIONS]
Options:
-h,--help Print this help message and exit
```
-11
View File
@@ -1,11 +0,0 @@
#include "CLI/CLI.hpp"
#include <iostream>
int main(int argc, char *argv[]){
CLI::App app{"Just a simple 'hello'"};
CLI11_PARSE(app, argc, argv);
std::cout << "Hello World!" << std::endl;
return 0;
}
// vim: set ts=4 expandtab :
+13
View File
@@ -0,0 +1,13 @@
#include<string>
class File {
private:
const std::string name;
public:
File(const std::string);
const std::string getName() const;
};
// vim: set ts=4 expandtab :
+12
View File
@@ -0,0 +1,12 @@
#include "File.h"
File::File(const std::string name):
name(name)
{
}
const std::string File::getName() const {
return name;
}
// vim: set ts=4 expandtab :
+5
View File
@@ -1,10 +1,15 @@
#include "CLI/CLI.hpp" #include "CLI/CLI.hpp"
#include "File.h"
#include <iostream> #include <iostream>
int main(int argc, char *argv[]){ int main(int argc, char *argv[]){
CLI::App app{"Just a simple 'hello'"}; CLI::App app{"Just a simple 'hello'"};
CLI11_PARSE(app, argc, argv); CLI11_PARSE(app, argc, argv);
File afile("aname");
std::cout << "Hello World!" << std::endl; std::cout << "Hello World!" << std::endl;
std::cout << "File name is: " << afile.getName() << std::endl;
return 0; return 0;
} }