From d14dd678d325c2416ccababbb9b6560f83218cd8 Mon Sep 17 00:00:00 2001 From: Phuntsok Drak-pa Date: Tue, 19 Mar 2019 10:14:19 +0100 Subject: [PATCH] initial commit --- .gitignore | 179 ++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 44 +++++++++ LICENSE | 21 +++++ README.md | 206 ++++++++++++++++++++++++++++++++++++++++++ README.org | 46 ++++++++++ cmake/functions.cmake | 12 +++ conanfile.py | 16 ++++ src/main.cpp | 6 ++ 8 files changed, 530 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 LICENSE create mode 100644 README.md create mode 100644 README.org create mode 100644 cmake/functions.cmake create mode 100644 conanfile.py create mode 100644 src/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..16656c6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,179 @@ +# Created by https://www.gitignore.io/api/c,c++,ninja,macos,linux,cmake,windows,visualstudiocode +# Edit at https://www.gitignore.io/?templates=c,c++,ninja,macos,linux,cmake,windows,visualstudiocode + +### C ### +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +### C++ ### +# Prerequisites + +# Compiled Object files +*.slo + +# Precompiled Headers + +# Compiled Dynamic libraries + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai + +# Executables + +### CMake ### +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +### CMake Patch ### +# External projects +*-prefix/ + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Ninja ### +.ninja_deps +.ninja_log + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.gitignore.io/api/c,c++,ninja,macos,linux,cmake,windows,visualstudiocode + +build \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..14e5c03 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,44 @@ +cmake_minimum_required(VERSION 3.14) + +project("AwesomeCppTemplate" + VERSION 0.1.2 + DESCRIPTION "Configure C++17 project files layout fast and simply." + HOMEPAGE_URL "https://github.com/devkoriel/AwesomeCppTemplate" + LANGUAGES CXX) +# project( +# [VERSION [.[.[.]]]] +# [DESCRIPTION ] +# [HOMEPAGE_URL ] +# [LANGUAGES ...]) + +set(SRC_FILES src/main.cpp) +# Example: set(SRC_FILES ) + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") +# find_package(Foo REQUIRED) # FOO_INCLUDE_DIR, FOO_LIBRARIES +# find_package(Boo REQUIRED) # BOO_INCLUDE_DIR, BOO_LIBRARIES + +include(functions) +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + +enable_cxx_compiler_flag_if_supported("-Wall") +enable_cxx_compiler_flag_if_supported("-pedantic") + +# include_directories() +add_executable(md5 ${SRC_FILES}) +target_compile_features(md5 PRIVATE cxx_std_17) +target_include_directories(md5 PRIVATE include/libfoo) +target_link_libraries(md5 ${CONAN_LIBS}) + +# OS specific instructions. +if(APPLE) +elseif(WIN32) + # Windows developer environment specific instructions. + if(MINGW) + elseif(MSYS) + elseif(CYGWIN) + endif() +elseif(UNIX) +else() +endif() diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a04e0c9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Jinsoo Heo + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..fc2d5a9 --- /dev/null +++ b/README.md @@ -0,0 +1,206 @@ +# AwesomeCppTemplate + +> This project is in its infancy and I plan to continue to improve. It is designed to use C++17. I hope people be able to create the desired C++ project files layout fast and simply. and also I'm very welcome to contributions. + +My goal is to make C++ version of Python [cookiecutter](https://github.com/audreyr/cookiecutter). then people can create C++ project files layout very simply by a single line of command. I hope some contributors to participate. + +Possibly, the project name "AwesomeCppTemplate" make people confused with C++ Template Programming but it's not :). My first choice for the name sucks. My bad... "C++FilesLayout" is more appropriate I think. + +There a lot of useful opinions that I have to look at in Reddit thread for this project. +The link is [here](https://www.reddit.com/r/cpp/comments/b1u9fp/i_created_c17_cmake_conan_ninja_project_template/). + +## Suggestion of C++ programming environment + +I suggest using as much cross-platform open-source software as possible: + +- build system generator: CMake +- build system: Ninja +- compiler: clang++ +- IDE: + - Visual Studio Code + - ⁠Qt Creator +- static code analyzers: + - clang-tidy + - Cppcheck + - Clazy +- source code formatter: clang-format +- documentation generator: Doxygen +- package manager: + - ⁠Conan + - ⁠vcpkg +- libraries: + - Standard Library + - Boost + - string formatting: fmt + - logging: spdlog + - automated tests: Google Test / Google Mock + - GUI: Qt + +## Prerequisites + +### Ubuntu +--- + +1. Update and upgrade packages + +```shell +$ sudo apt update && sudo apt upgrade -y +``` + +2. Install Clang and LLVM (7 release) + +To add the apt repo, find the appropriate one for your Ubuntu version below and append it to `/etc/apt/sources.list` +``` +Trusty (14.04) - Last update : Tue, 26 Feb 2019 05:42:37 UTC / Revision: 354792 +deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty main +deb-src http://apt.llvm.org/trusty/ llvm-toolchain-trusty main +# 7 +deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-7 main +deb-src http://apt.llvm.org/trusty/ llvm-toolchain-trusty-7 main +# 8 +deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-8 main +deb-src http://apt.llvm.org/trusty/ llvm-toolchain-trusty-8 main + +# Also add the following for the appropriate libstdc++ +deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu trusty main +Xenial (16.04) - Last update : Thu, 14 Mar 2019 00:31:13 UTC / Revision: 356003 +deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial main +deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial main +# 7 +deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-7 main +deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-7 main +# 8 +deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main +deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main +Bionic (18.04) - Last update : Thu, 14 Mar 2019 03:23:34 UTC / Revision: 356096 +# i386 not available +deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main +deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic main +# 7 +deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-7 main +deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic-7 main +# 8 +deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-8 main +deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic-8 main +Cosmic (18.10) - Last update : Wed, 13 Mar 2019 12:53:46 UTC / Revision: 356030 +# i386 not available +deb http://apt.llvm.org/cosmic/ llvm-toolchain-cosmic main +deb-src http://apt.llvm.org/cosmic/ llvm-toolchain-cosmic main +# 7 +deb http://apt.llvm.org/cosmic/ llvm-toolchain-cosmic-7 main +deb-src http://apt.llvm.org/cosmic/ llvm-toolchain-cosmic-7 main +# 8 +deb http://apt.llvm.org/cosmic/ llvm-toolchain-cosmic-8 main +deb-src http://apt.llvm.org/cosmic/ llvm-toolchain-cosmic-8 main +Disco (19.04) - Last update : Wed, 13 Mar 2019 12:42:07 UTC / Revision: 356006 +# i386 not available +deb http://apt.llvm.org/disco/ llvm-toolchain-disco main +deb-src http://apt.llvm.org/disco/ llvm-toolchain-disco main +# 7 +deb http://apt.llvm.org/disco/ llvm-toolchain-disco-7 main +deb-src http://apt.llvm.org/disco/ llvm-toolchain-disco-7 main +# 8 +deb http://apt.llvm.org/disco/ llvm-toolchain-disco-8 main +deb-src http://apt.llvm.org/disco/ llvm-toolchain-disco-8 main +``` + +Update apt packages list: +```shell +$ sudo apt update +``` + +To retrieve the archive signature: +```shell +$ wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add - +# Fingerprint: 6084 F3CF 814B 57C1 CF12 EFD5 15CF 4D18 AF4F 7421 +``` + +To install just clang, lld and lldb: +```shell +$ sudo apt install clang-7 lldb-7 lld-7 +``` + +To install all key packages: +```shell +# LLVM +$ sudo apt install libllvm-7-ocaml-dev libllvm7 llvm-7 llvm-7-dev llvm-7-doc llvm-7-examples llvm-7-runtime + +# Clang and co +$ sudo apt install clang-7 clang-tools-7 clang-7-doc libclang-common-7-dev libclang-7-dev libclang1-7 clang-format-7 python-clang-7 + +# libfuzzer +$ sudo apt install libfuzzer-7-dev + +# lldb +$ sudo apt install lldb-7 + +# lld (linker) +$ sudo apt install lld-7 + +# libc++ +$ sudo apt install libc++-7-dev libc++abi-7-dev + +# OpenMP +$ sudo apt install libomp-7-dev +``` + +Finally, link each `clang-7` and `clang++-7` to `clang` and `clang++`. +```shell +$ sudo ln -s /usr/bin/clang-7 /usr/bin/clang +$ sudo ln -s /usr/bin/clang++-7 /usr/bin/clang++ +``` + +Check if all the packages are installed fine. +```shell +$ clang++ --version +clang version 7.0.0-3~ubuntu0.18.04.1 (tags/RELEASE_700/final) +Target: x86_64-pc-linux-gnu +Thread model: posix +InstalledDir: /usr/bin +``` + +3. Install CMake + +```shell +$ sudo apt install cmake +``` + +4. Install Conan + +```shell +$ sudo apt install python3 +$ sudo apt install python3-pip +$ sudo pip3 install --upgrade pip +$ pip install conan +``` +Then change default profile of conan: +```shell +$ conan profile new default --detect +$ conan profile update settings.compiler=clang++ +$ conan profile update settings.compiler.version=7.0 +$ conan profile update settings.compiler.libcxx=libc++ +``` + +5. Install Ninja + +```shell +$ sudo apt install ninja-build +``` + +## Build examples + +```shell +$ mkdir build && cd build +$ conan install .. +$ export CC=clang +$ export CXX=clang++ +$ cmake .. -G Ninja +$ cmake --build . +``` + +Try running the example binary! + +```shell +$ ./bin/md5 +c3fcd3d76192e4007dfb496cca67e13b +``` diff --git a/README.org b/README.org new file mode 100644 index 0000000..ca68292 --- /dev/null +++ b/README.org @@ -0,0 +1,46 @@ +[[http://spacemacs.org][file:https://cdn.rawgit.com/syl20bnr/spacemacs/442d025779da2f62fc86c2082703697714db6514/assets/spacemacs-badge.svg]] + +* Genetic image generation + +This project is a university assignment that aims at regenerating a reference +image from random shapes of random color applied. There will be lots of +different tests on what method is the best and/or the fastest to get a new +image as close as possible to the reference image. + +* Technical information + +This project is built with conan, ninja and cmake using clang-7 for C++17. To +use it, first install clang-7 and lldb 7, then run this: +#+begin_src shell + conan profile new default --detect + conan profile update settings.compiler=clang default + conan profile update settings.compiler.version=7.0 default + conan profile update settings.compiler.libcxx=libstdc++11 default + conan profile update env.CC=/bin/clang default + conan profile update env.CXX=/bin/clang++ default +#+end_src +If you do not wish to overwrite your ~default~ profile, you can instead create a +new one, for instance ~clang~. To do so, write the name of your new profile (in +this example ~clang~) instead of ~default~ in the commands shown above. + +Then, To build and run the program, go to the root of the project and run this: +#+begin_src shell + mkdir build && cd build + conan install .. --build missing + export CC=clang + export CXX=clang++ + cmake .. -G Ninja + cmake --build . +#+end_src +If you want to use another profile than your default one, you should run the +following line instead of the second line: +#+begin_src shell + conan install .. --build missing --profile +#+end_src + +This project was built and tested using clang-7, lldb and gdb on Void Linux +(kernel 4.19) and Arch Linux (kernel 5.0). + +* Credits + +Awesome C++ project template by [[https://github.com/devkoriel/AwesomeCppTemplate][devkoriel]]. diff --git a/cmake/functions.cmake b/cmake/functions.cmake new file mode 100644 index 0000000..e2b4346 --- /dev/null +++ b/cmake/functions.cmake @@ -0,0 +1,12 @@ +INCLUDE(CheckCXXCompilerFlag) + +function(enable_cxx_compiler_flag_if_supported flag) + string(FIND "${CMAKE_CXX_FLAGS}" "${flag}" flag_already_set) + if(flag_already_set EQUAL -1) + check_cxx_compiler_flag("${flag}" flag_supported) + if(flag_supported) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE) + endif() + unset(flag_supported CACHE) + endif() +endfunction() diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 0000000..6054246 --- /dev/null +++ b/conanfile.py @@ -0,0 +1,16 @@ +from conans import ConanFile, CMake + + +class PocoTimerConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + requires = "opencv/4.0.1@conan/stable" + generators = "cmake", "gcc", "txt" + + def imports(self): + self.copy("*.dll", dst="bin", src="bin") # From bin to bin + self.copy("*.dylib*", dst="bin", src="lib") # From lib to bin + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..d067115 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,6 @@ +#include + +int main(int argc, char **argv) { + std::cout << "Hello World!\n"; + return 0; +}