imported lab skeletons

This commit is contained in:
Sven Gestegard Robertz 2021-10-27 15:15:47 +02:00
parent 4fc8b6c771
commit e4df45f4a9
47 changed files with 15122 additions and 87 deletions

View file

@ -0,0 +1,44 @@
cmake_minimum_required (VERSION 3.5)
project (Simple)
set (CMAKE_CXX_STANDARD 11)
# set build type to DEBUG
set(CMAKE_BUILD_TYPE Debug)
# or to get an optimized build w/ debug symbols
# set(CMAKE_BUILD_TYPE RelWithDebInfo)
# add the library to the include file search path
include_directories ("${PROJECT_SOURCE_DIR}/testlib")
add_subdirectory (testlib)
# set compiler and linker flags
add_compile_options("-Og")
#add_compile_options("-fsanitize=address")
#link_libraries("-fsanitize=address")
# add the executable SimpleMain and its dependency on TestLib
add_executable(SimpleMain main.cc)
target_link_libraries (SimpleMain TestLib)
##################### Optional features below this line ############
# The version number. This is not needed but included
# to show how information can be passed from CMakeLists.txt
# to the program.
set (Simple_VERSION_MAJOR 1)
set (Simple_VERSION_MINOR 0)
# configure a header file to pass some of the CMake settings
# to the source code. Only needed if we want to pass some
# information or configuration from Cmake to the program
# being built.
configure_file (
"${PROJECT_SOURCE_DIR}/SimpleConfig.h.in"
"${PROJECT_BINARY_DIR}/SimpleConfig.h"
)
# add the binary tree to the search path for include files
# so that we will find SimpleConfig.h
include_directories("${PROJECT_BINARY_DIR}")

35
lab1/cmake-example/README Normal file
View file

@ -0,0 +1,35 @@
This is an example project that is built with cmake.
The project consists of
- an example library, TestLib, which is built from testlib/foo.h and .cc
- a configuration file, SimpleConfig.h which is built from SimpleConfig.h.in
- a main program, in main.cc
With cmake, you usually build the project in a directory separate from the source,
typically named build. This has the advantages that you can easily make several
separate builds simply by doing them in separate build directories. It also
means that the generated files are kept separate from the source code, so that
removing them is done by simply removing the entire build directory.
The steps to create the build files (Makefile, unless otherwise specified, but
cmake can generate project files for other build systems as well) and then
build the project are
> mkdir build
> cd build
> cmake ..
> make
To see the actual commands executed when building with the generated Makefile,
use the command
> make VERBOSE=1
Configuration of the compilation can be done by setting environment variables
which are read by cmake.
To set which compiler to use:
CC=clang CXX=clang++ cmake ..
To set compiler flags, one can use
cmake -DCMAKE_CXX_FLAGS="-Wall -Werror" ..

View file

@ -0,0 +1,3 @@
// the configured options and settings for simple
#define Simple_VERSION_MAJOR @Simple_VERSION_MAJOR@
#define Simple_VERSION_MINOR @Simple_VERSION_MINOR@

View file

@ -0,0 +1,25 @@
#include <iostream>
#include "SimpleConfig.h"
#include "foo.h"
#include "bar.h"
using std::cout;
using std::endl;
/* A small example of a project built using CMake.
* The Simple_VERSION_* variables are included
* to show how a header file with configuration macros
* can be generated from the CMakeLists.txt.
*/
int main()
{
cout << "This is version " << Simple_VERSION_MAJOR << "." <<
Simple_VERSION_MINOR << "\n";
cout << "Hello, world!\n";
foo_fun();
bar_fun(42);
}

View file

@ -0,0 +1 @@
add_library(TestLib foo.cc bar.cc)

View file

@ -0,0 +1,6 @@
#include <iostream>
void bar_fun(int x)
{
std::cout << "[bar: " << x << "]" << "\n";
}

View file

@ -0,0 +1 @@
void bar_fun(int);

View file

@ -0,0 +1,7 @@
#include <iostream>
void foo_fun()
{
auto x = 17; // use a C++11 feature to see if flags are set correctly
std::cout << "[foo: " << x << "]" << "\n";
}

View file

@ -0,0 +1 @@
void foo_fun();