Compare commits
3 Commits
main
..
f643d41561
| Author | SHA1 | Date | |
|---|---|---|---|
| f643d41561 | |||
| aea438416d | |||
| ccaba7d26f |
+5
-10
@@ -10,12 +10,13 @@ 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})
|
||||||
|
|
||||||
# include_directories(include)
|
# file(GLOB SOURCES "src/*.cpp")
|
||||||
|
|
||||||
|
include_directories(include)
|
||||||
|
|
||||||
add_library(challenge SHARED
|
add_library(challenge SHARED
|
||||||
src/File.cpp
|
src/File.cpp
|
||||||
)
|
)
|
||||||
target_include_directories(challenge PUBLIC include)
|
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME}
|
add_executable(${PROJECT_NAME}
|
||||||
src/cppchallenge.cpp
|
src/cppchallenge.cpp
|
||||||
@@ -26,16 +27,10 @@ target_link_libraries(${PROJECT_NAME}
|
|||||||
challenge
|
challenge
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(${PROJECT_NAME}
|
install(TARGETS ${PROJECT_NAME}
|
||||||
PROPERTIES
|
|
||||||
PUBLIC_HEADER
|
|
||||||
include/File.h
|
|
||||||
)
|
|
||||||
|
|
||||||
install(TARGETS ${PROJECT_NAME} challenge
|
|
||||||
RUNTIME DESTINATION bin
|
RUNTIME DESTINATION bin
|
||||||
LIBRARY DESTINATION lib
|
LIBRARY DESTINATION lib
|
||||||
PUBLIC_HEADER DESTINATION include
|
INCLUDES DESTINATION include
|
||||||
)
|
)
|
||||||
|
|
||||||
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||||
|
|||||||
@@ -1,44 +1 @@
|
|||||||
A basic C++ exercise which uses `conan` to satisfy dependencies before building a shared library and
|
A basic C++ exercise.
|
||||||
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
|
|
||||||
```
|
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#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 :
|
||||||
+3
-5
@@ -3,11 +3,9 @@
|
|||||||
class File {
|
class File {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string name;
|
std::string name;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
File(const std::string);
|
File(std::string);
|
||||||
const std::string getName() const;
|
std::string getName();
|
||||||
};
|
};
|
||||||
|
|
||||||
// vim: set ts=4 expandtab :
|
|
||||||
|
|||||||
+2
-4
@@ -1,12 +1,10 @@
|
|||||||
#include "File.h"
|
#include "File.h"
|
||||||
|
|
||||||
File::File(const std::string name):
|
File::File(std::string name):
|
||||||
name(name)
|
name(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string File::getName() const {
|
std::string File::getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// vim: set ts=4 expandtab :
|
|
||||||
|
|||||||
@@ -1,15 +1,10 @@
|
|||||||
#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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user