Skip to content

Commit

Permalink
revert back to upstream example
Browse files Browse the repository at this point in the history
  • Loading branch information
meintte committed Jun 21, 2023
1 parent c0d8da6 commit 5ee54df
Show file tree
Hide file tree
Showing 16 changed files with 675 additions and 34 deletions.
43 changes: 24 additions & 19 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
---
Checks: "*,
-abseil-*,
-altera-*,
-android-*,
-fuchsia-*,
-google-*,
-llvm*,
-modernize-use-trailing-return-type,
-zircon-*,
-readability-else-after-return,
-readability-static-accessed-through-instance,
-readability-avoid-const-params-in-decls,
-cppcoreguidelines-non-private-member-variables-in-classes,
-misc-non-private-member-variables-in-classes"

WarningsAsErrors: ""
HeaderFilterRegex: ""
FormatStyle: none
-abseil-*,
-altera-*,
-android-*,
-fuchsia-*,
-google-*,
-llvm*,
-modernize-use-trailing-return-type,
-zircon-*,
-readability-else-after-return,
-readability-static-accessed-through-instance,
-readability-avoid-const-params-in-decls,
-cppcoreguidelines-non-private-member-variables-in-classes,
-misc-non-private-member-variables-in-classes,
"
WarningsAsErrors: ''
HeaderFilterRegex: ''
FormatStyle: none

CheckOptions:
- key: readability-identifier-length.IgnoredVariableNames
value: "x|y|z"
value: 'x|y|z'
- key: readability-identifier-length.IgnoredParameterNames
value: "x|y|z"
value: 'x|y|z'





4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ if(MSVC)
endif()

# set the startup project for the "play" button in MSVC
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT app)
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT intro)

if(CMAKE_SKIP_INSTALL_RULES)
return()
Expand All @@ -102,7 +102,7 @@ include(cmake/PackageProject.cmake)
# we know we want to ship
myproject_package_project(
TARGETS
app
intro
myproject_options
myproject_warnings
# FIXME: this does not work! CK
Expand Down
8 changes: 8 additions & 0 deletions Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ function(myproject_setup_dependencies)
cpmaddpackage("gh:CLIUtils/CLI11@2.3.2")
endif()

if(NOT TARGET ftxui::screen)
cpmaddpackage("gh:ArthurSonzogni/FTXUI#e23dbc7473654024852ede60e2121276c5aab660")
endif()

if(NOT TARGET tools::tools)
cpmaddpackage("gh:lefticus/tools#update_build_system")
endif()

if(NOT TARGET Eigen3::Eigen)
cpmaddpackage(
GITLAB_REPOSITORY
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ Now you can clone the project locally and get to work!

* [Dependency Setup](README_dependencies.md)
* [Building Details](README_building.md)
* [Troubleshooting](README_troubleshooting.md)
* [Docker](README_docker.md)

## Testing
Expand All @@ -57,3 +56,5 @@ See [Catch2 tutorial](https://github.com/catchorg/Catch2/blob/master/docs/tutori
## Fuzz testing

See [libFuzzer Tutorial](https://github.com/google/fuzzing/blob/master/tutorial/libFuzzerTutorial.md)


192 changes: 192 additions & 0 deletions README_building.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
## Build Instructions

A full build has different steps:
1) Specifying the compiler using environment variables
2) Configuring the project
3) Building the project

For the subsequent builds, in case you change the source code, you only need to repeat the last step.

### (1) Specify the compiler using environment variables

By default (if you don't set environment variables `CC` and `CXX`), the system default compiler will be used.

CMake uses the environment variables CC and CXX to decide which compiler to use. So to avoid the conflict issues only specify the compilers using these variables.


<details>
<summary>Commands for setting the compilers </summary>

- Debian/Ubuntu/MacOS:

Set your desired compiler (`clang`, `gcc`, etc):

- Temporarily (only for the current shell)

Run one of the followings in the terminal:

- clang

CC=clang CXX=clang++

- gcc

CC=gcc CXX=g++

- Permanent:

Open `~/.bashrc` using your text editor:

gedit ~/.bashrc

Add `CC` and `CXX` to point to the compilers:

export CC=clang
export CXX=clang++

Save and close the file.

- Windows:

- Permanent:

Run one of the followings in PowerShell:

- Visual Studio generator and compiler (cl)

[Environment]::SetEnvironmentVariable("CC", "cl.exe", "User")
[Environment]::SetEnvironmentVariable("CXX", "cl.exe", "User")
refreshenv

Set the architecture using [vcvarsall](https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=vs-2019#vcvarsall-syntax):

vcvarsall.bat x64

- clang

[Environment]::SetEnvironmentVariable("CC", "clang.exe", "User")
[Environment]::SetEnvironmentVariable("CXX", "clang++.exe", "User")
refreshenv

- gcc

[Environment]::SetEnvironmentVariable("CC", "gcc.exe", "User")
[Environment]::SetEnvironmentVariable("CXX", "g++.exe", "User")
refreshenv


- Temporarily (only for the current shell):

$Env:CC="clang.exe"
$Env:CXX="clang++.exe"

</details>

### (2) Configure your build

To configure the project, you could use `cmake`, or `ccmake` or `cmake-gui`. Each of them are explained in the following:

#### (2.a) Configuring via cmake:
With Cmake directly:

cmake -S . -B ./build

Cmake will automatically create the `./build` folder if it does not exist, and it wil configure the project.

Instead, if you have CMake version 3.21+, you can use one of the configuration presets that are listed in the CmakePresets.json file.

cmake . --preset <configure-preset>
cmake --build

#### (2.b) Configuring via ccmake:

With the Cmake Curses Dialog Command Line tool:

ccmake -S . -B ./build

Once `ccmake` has finished setting up, press 'c' to configure the project,
press 'g' to generate, and 'q' to quit.

#### (2.c) Configuring via cmake-gui:

To use the GUI of the cmake:

2.c.1) Open cmake-gui from the project directory:
```
cmake-gui .
```
2.c.2) Set the build directory:

![build_dir](https://user-images.githubusercontent.com/16418197/82524586-fa48e380-9af4-11ea-8514-4e18a063d8eb.jpg)

2.c.3) Configure the generator:

In cmake-gui, from the upper menu select `Tools/Configure`.

**Warning**: if you have set `CC` and `CXX` always choose the `use default native compilers` option. This picks `CC` and `CXX`. Don't change the compiler at this stage!

<details>
<summary>Windows - MinGW Makefiles</summary>

Choose MinGW Makefiles as the generator:

<img src="https://user-images.githubusercontent.com/16418197/82769479-616ade80-9dfa-11ea-899e-3a8c31d43032.png" alt="mingw">

</details>

<details>
<summary>Windows - Visual Studio generator and compiler</summary>

You should have already set `C` and `CXX` to `cl.exe`.

Choose "Visual Studio 16 2019" as the generator:

<img src="https://user-images.githubusercontent.com/16418197/82524696-32502680-9af5-11ea-9697-a42000e900a6.jpg" alt="default_vs">

</details>

<details>

<summary>Windows - Visual Studio generator and Clang Compiler</summary>

You should have already set `C` and `CXX` to `clang.exe` and `clang++.exe`.

Choose "Visual Studio 16 2019" as the generator. To tell Visual studio to use `clang-cl.exe`:
- If you use the LLVM that is shipped with Visual Studio: write `ClangCl` under "optional toolset to use".

<img src="https://user-images.githubusercontent.com/16418197/82781142-ae60ac00-9e1e-11ea-8c77-222b005a8f7e.png" alt="visual_studio">

- If you use an external LLVM: write [`LLVM_v142`](https://github.com/zufuliu/llvm-utils#llvm-for-visual-studio-2017-and-2019)
under "optional toolset to use".

<img src="https://user-images.githubusercontent.com/16418197/82769558-b3136900-9dfa-11ea-9f73-02ab8f9b0ca4.png" alt="visual_studio">

</details>
<br/>

2.c.4) Choose the Cmake options and then generate:

![generate](https://user-images.githubusercontent.com/16418197/82781591-c97feb80-9e1f-11ea-86c8-f2748b96f516.png)

### (3) Build the project
Once you have selected all the options you would like to use, you can build the
project (all targets):

cmake --build ./build

For Visual Studio, give the build configuration (Release, RelWithDeb, Debug, etc) like the following:

cmake --build ./build -- /p:configuration=Release


### Running the tests

You can use the `ctest` command run the tests.

```shell
cd ./build
ctest -C Debug
cd ../
```


71 changes: 71 additions & 0 deletions README_docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
## Docker Instructions

If you have [Docker](https://www.docker.com/) installed, you can run this
in your terminal, when the Dockerfile is inside the `.devcontainer` directory:

```bash
docker build -f ./.devcontainer/Dockerfile --tag=my_project:latest .
docker run -it my_project:latest
```

This command will put you in a `bash` session in a Ubuntu 20.04 Docker container,
with all of the tools listed in the [Dependencies](#dependencies) section already installed.
Additionally, you will have `g++-11` and `clang++-13` installed as the default
versions of `g++` and `clang++`.

If you want to build this container using some other versions of gcc and clang,
you may do so with the `GCC_VER` and `LLVM_VER` arguments:

```bash
docker build --tag=myproject:latest --build-arg GCC_VER=10 --build-arg LLVM_VER=11 .
```

The CC and CXX environment variables are set to GCC version 11 by default.
If you wish to use clang as your default CC and CXX environment variables, you
may do so like this:

```bash
docker build --tag=my_project:latest --build-arg USE_CLANG=1 .
```

You will be logged in as root, so you will see the `#` symbol as your prompt.
You will be in a directory that contains a copy of the `cpp_starter_project`;
any changes you make to your local copy will not be updated in the Docker image
until you rebuild it.
If you need to mount your local copy directly in the Docker image, see
[Docker volumes docs](https://docs.docker.com/storage/volumes/).
TLDR:

```bash
docker run -it \
-v absolute_path_on_host_machine:absolute_path_in_guest_container \
my_project:latest
```

You can configure and build [as directed above](#build) using these commands:

```bash
/starter_project# mkdir build
/starter_project# cmake -S . -B ./build
/starter_project# cmake --build ./build
```

You can configure and build using `clang-13`, without rebuilding the container,
with these commands:

```bash
/starter_project# mkdir build
/starter_project# CC=clang CXX=clang++ cmake -S . -B ./build
/starter_project# cmake --build ./build
```

The `ccmake` tool is also installed; you can substitute `ccmake` for `cmake` to
configure the project interactively.
All of the tools this project supports are installed in the Docker image;
enabling them is as simple as flipping a switch using the `ccmake` interface.
Be aware that some of the sanitizers conflict with each other, so be sure to
run them separately.

A script called `build_examples.sh` is provided to help you to build the example
GUI projects in this container.

2 changes: 0 additions & 2 deletions fuzz_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# A fuzz test runs until it finds an error. This particular one is going to rely on libFuzzer.
#

find_package(fmt)

add_executable(fuzz_tester fuzz_tester.cpp)
target_link_libraries(
fuzz_tester
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
add_subdirectory(Utils)
add_subdirectory(sample_library)
add_subdirectory(app)
add_subdirectory(ftxui_sample)
add_subdirectory(Utils)
2 changes: 0 additions & 2 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ int main(int argc, const char** argv) {
myproject::cmake::project_name,
myproject::cmake::project_version)};

// std::optional<std::string> message;
// app.add_option("-m,--message", message, "A message to print out");
bool show_version = false;
app.add_flag("--version", show_version, "Show version information");

Expand Down
Loading

0 comments on commit 5ee54df

Please sign in to comment.