Compare commits

..

3 Commits

6 changed files with 68 additions and 22 deletions
+10 -5
View File
@@ -10,13 +10,12 @@ find_package(CLI11 REQUIRED)
set(BUILD_DIR "${PROJECT_SOURCE_DIR}/build")
set(CLI11_DIR ${BUILD_DIR})
# file(GLOB SOURCES "src/*.cpp")
include_directories(include)
# include_directories(include)
add_library(challenge SHARED
src/File.cpp
)
target_include_directories(challenge PUBLIC include)
add_executable(${PROJECT_NAME}
src/cppchallenge.cpp
@@ -27,10 +26,16 @@ target_link_libraries(${PROJECT_NAME}
challenge
)
install(TARGETS ${PROJECT_NAME}
set_target_properties(${PROJECT_NAME}
PROPERTIES
PUBLIC_HEADER
include/File.h
)
install(TARGETS ${PROJECT_NAME} challenge
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
INCLUDES DESTINATION include
PUBLIC_HEADER DESTINATION include
)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
+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 :
+5 -3
View File
@@ -3,9 +3,11 @@
class File {
private:
std::string name;
const std::string name;
public:
File(std::string);
std::string getName();
File(const std::string);
const std::string getName() const;
};
// vim: set ts=4 expandtab :
+4 -2
View File
@@ -1,10 +1,12 @@
#include "File.h"
File::File(std::string name):
File::File(const std::string name):
name(name)
{
}
std::string File::getName() {
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 "File.h"
#include <iostream>
int main(int argc, char *argv[]){
CLI::App app{"Just a simple 'hello'"};
CLI11_PARSE(app, argc, argv);
File afile("aname");
std::cout << "Hello World!" << std::endl;
std::cout << "File name is: " << afile.getName() << std::endl;
return 0;
}