commit 12991f04e1c3a54d956b4a9d47f3f83ed4b3e61c Author: Alexis Pereda Date: Tue Jul 2 16:35:02 2019 +0200 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e9b2ea5 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,60 @@ +cmake_minimum_required(VERSION 3.0) +get_filename_component(project_name ${CMAKE_CURRENT_SOURCE_DIR} NAME) +project(${project_name}) + +set(EXTENSION "cpp") + +set(CMAKE_CXX_STANDARD 14) + +set(FLAGS_ANY "-Wall -Wextra -Winline") +set(FLAGS_DEBUG "-DDEBUG -O0 -pg") +set(FLAGS_RELEASE "-DNDEBUG -O2") + +set(EXAMPLESDIRS mp et) + +set(INCLUDE_DIRS "") +set(LIBRARIES "-lpthread") + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAGS_ANY}") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAGS_ANY} ${FLAGS_DEBUG}") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${FLAGS_ANY} ${FLAGS_RELEASE}") + +## Examples +foreach(examplesdir ${EXAMPLESDIRS}) + set(examplesfulldir examples/${examplesdir}) + set(examplespath ${CMAKE_CURRENT_SOURCE_DIR}/${examplesfulldir}) + file(GLOB examples RELATIVE ${examplespath} ${examplespath}/*) + if(examples) + foreach(child ${examples}) + set(example_bin_filename "") + set(example "") + if(IS_DIRECTORY ${examplespath}/${child}) + set(example_bin_filename ${child}) + set(example ${examplesdir}_${example_bin_filename}) + file(GLOB_RECURSE example_src ${examplespath}/${child}/*.${EXTENSION}) + else() + get_filename_component(extension ${child} EXT) + if(${extension} MATCHES "^.${EXTENSION}$") + get_filename_component(example_name ${child} NAME_WE) + set(example_bin_filename ${example_name}) + set(example ${examplesdir}_${example_bin_filename}) + set(example_src ${examplespath}/${child}) + endif() + endif() + if(example) + if(example_src) + message(STATUS "+ Example: ${examplesdir}/${example}") + add_executable(${example} ${example_src}) + target_include_directories(${example} PUBLIC ${SRCDIRS} ${LIBSDIRS} ${INCLUDE_DIRS}) + target_link_libraries(${example} ${LIBRARIES} ${USER_LIBRARIES}) + set_target_properties(${example} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${examplesfulldir}) + set_target_properties(${example} PROPERTIES OUTPUT_NAME ${example_bin_filename}) + else() + message(WARNING "! Example ${example}: no sources") + endif() + endif() + endforeach() + endif() +endforeach() diff --git a/README.md b/README.md new file mode 100644 index 0000000..ed87e55 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +## Purpose + +The purpose of this repository is to provide code examples that can be compiled and run for people reading my PhD thesis. +These examples codes are **not** for production and often are simplified with regard of technical specificities (for example, but not limited to, perfect forwarding). + +## Usage + +```bash +mkdir build +cd build +cmake .. +make +``` + +then run any example binary, located inside the `build/examples/` directory.