Skip to content

Commit 86a048d

Browse files
author
Sebastien Ponce
committed
Merge branch 'AddCMakeConfig-master-20201010' into 'master'
Add CMake Configuration Files, master branch (2020.10.10.) See merge request sponce/cpluspluscourse!6
2 parents 17ec135 + 7756519 commit 86a048d

File tree

18 files changed

+392
-0
lines changed

18 files changed

+392
-0
lines changed

code/CMakeLists.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#
2+
# Main project for building all of the exercises at once.
3+
#
4+
5+
# Set up the project.
6+
cmake_minimum_required( VERSION 3.1 )
7+
project( cpluspluscourse LANGUAGES CXX )
8+
9+
# Make sure that the project is built "out of source". As an "in source" build
10+
# would interfere with the simple Makefiles coming with the code.
11+
if( "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}" )
12+
message( FATAL_ERROR "The tutorial code must be built out of source!" )
13+
endif()
14+
15+
# Add a custom target for building all the solutions. Which are not built by
16+
# default.
17+
add_custom_target( solution )
18+
19+
# Include the test (hello world) project.
20+
add_subdirectory( hello )
21+
22+
# Include the exercises that (should) work on all platforms.
23+
add_subdirectory( callgrind )
24+
add_subdirectory( constness )
25+
add_subdirectory( cppcheck )
26+
add_subdirectory( debug )
27+
add_subdirectory( memcheck )
28+
add_subdirectory( move )
29+
add_subdirectory( polymorphism )
30+
add_subdirectory( templates )
31+
add_subdirectory( valgrind )
32+
add_subdirectory( virtual_inheritance )
33+
34+
# Include the non-Windows-native exercises.
35+
if( NOT MSVC )
36+
add_subdirectory( helgrind )
37+
add_subdirectory( python )
38+
add_subdirectory( race )
39+
endif()
40+
41+
# Include the gcc-only exercises.
42+
if( NOT APPLE AND NOT MSVC )
43+
add_subdirectory( lambdas )
44+
add_subdirectory( stl )
45+
endif()

code/CompilerSettings.cmake

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# Small module used in every project to set up the default "compilation
3+
# environment".
4+
#
5+
6+
# Guard this file against multiple inclusions.
7+
get_property( _compilersSet GLOBAL PROPERTY COMPILER_SETTINGS_DONE SET )
8+
if( _compilersSet )
9+
unset( _compilersSet )
10+
return()
11+
endif()
12+
set_property( GLOBAL PROPERTY COMPILER_SETTINGS_DONE TRUE )
13+
14+
15+
# Set up a Debug build type by default, if the user didn't ask for something
16+
# else.
17+
if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES )
18+
set( CMAKE_BUILD_TYPE "Debug" CACHE
19+
STRING "Choose the type of build." FORCE )
20+
set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
21+
"Debug" "Release" "MinSizeRel" "RelWithDebInfo" )
22+
endif()
23+
24+
# Use C++17 in the project by default, or as high of a value as possible.
25+
set( CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to use" )
26+
set( CMAKE_CXX_EXTENSIONS FALSE CACHE BOOL "(Dis)Allow C++ extensions" )
27+
28+
# Enable (almost) all warnings for the build.
29+
if( ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) OR
30+
( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) )
31+
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra" )
32+
elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" )
33+
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4" )
34+
endif()

code/callgrind/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
# Set up the project.
3+
cmake_minimum_required( VERSION 3.1 )
4+
project( callgrind LANGUAGES CXX )
5+
6+
# Set up the compilation environment.
7+
include( "${CMAKE_CURRENT_SOURCE_DIR}/../CompilerSettings.cmake" )
8+
9+
# Create the user's executable.
10+
add_executable( fibocrunch fibocrunch.cpp )
11+
12+
# Create the "solution executable".
13+
add_executable( fibocrunch.sol EXCLUDE_FROM_ALL solution/fibocrunch.sol.cpp )
14+
if( TARGET solution )
15+
add_dependencies( solution fibocrunch.sol )
16+
endif()

code/constness/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
# Set up the project.
3+
cmake_minimum_required( VERSION 3.1 )
4+
project( constness LANGUAGES CXX )
5+
6+
# Set up the compilation environment.
7+
include( "${CMAKE_CURRENT_SOURCE_DIR}/../CompilerSettings.cmake" )
8+
9+
# Create the user's executable.
10+
add_executable( constplay constplay.cpp )
11+
12+
# Create the "solution executable".
13+
add_executable( constplay.sol EXCLUDE_FROM_ALL solution/constplay.sol.cpp )
14+
if( TARGET solution )
15+
add_dependencies( solution constplay.sol )
16+
endif()

code/cppcheck/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
# Set up the project.
3+
cmake_minimum_required( VERSION 3.1 )
4+
project( cppcheck LANGUAGES CXX )
5+
6+
# Set up the compilation environment.
7+
include( "${CMAKE_CURRENT_SOURCE_DIR}/../CompilerSettings.cmake" )
8+
9+
# Create the user's executable.
10+
add_executable( cppcheck_randomize randomize.cpp )
11+
12+
# Create the "solution executable".
13+
add_executable( cppcheck_randomize.sol EXCLUDE_FROM_ALL
14+
solution/randomize.sol.cpp )
15+
if( TARGET solution )
16+
add_dependencies( solution cppcheck_randomize.sol )
17+
endif()

code/debug/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
# Set up the project.
3+
cmake_minimum_required( VERSION 3.1 )
4+
project( debug LANGUAGES CXX )
5+
6+
# Set up the compilation environment.
7+
include( "${CMAKE_CURRENT_SOURCE_DIR}/../CompilerSettings.cmake" )
8+
9+
# Create the user's executable.
10+
add_executable( debug_randomize randomize.cpp )
11+
12+
# Create the "solution executable".
13+
add_executable( debug_randomize.sol EXCLUDE_FROM_ALL
14+
solution/randomize.sol.cpp )
15+
if( TARGET solution )
16+
add_dependencies( solution debug_randomize.sol )
17+
endif()

code/helgrind/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
# Set up the project.
3+
cmake_minimum_required( VERSION 3.1 )
4+
project( helgrind LANGUAGES CXX )
5+
6+
# Set up the compilation environment.
7+
include( "${CMAKE_CURRENT_SOURCE_DIR}/../CompilerSettings.cmake" )
8+
9+
# Figure out how to use the platform's thread capabilities.
10+
find_package( Threads REQUIRED )
11+
12+
# Create the user's executable.
13+
add_executable( fiboMT fiboMT.cpp )
14+
target_link_libraries( fiboMT PRIVATE Threads::Threads )
15+
16+
# Create the "solution executable".
17+
add_executable( fiboMT.sol EXCLUDE_FROM_ALL solution/fiboMT.sol.cpp )
18+
target_link_libraries( fiboMT.sol PRIVATE Threads::Threads )
19+
if( TARGET solution )
20+
add_dependencies( solution fiboMT.sol )
21+
endif()

code/hello/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
# Set up the project.
3+
cmake_minimum_required( VERSION 3.1 )
4+
project( hello LANGUAGES CXX )
5+
6+
# Set up the compilation environment.
7+
include( "${CMAKE_CURRENT_SOURCE_DIR}/../CompilerSettings.cmake" )
8+
9+
# Set up the library.
10+
add_library( helloLib hello.hpp hello.cpp )
11+
set_target_properties( helloLib PROPERTIES OUTPUT_NAME "hello" )
12+
13+
# Set up the executable.
14+
add_executable( hello main.cpp )
15+
target_link_libraries( hello PRIVATE helloLib )

code/lambdas/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
# Set up the project.
3+
cmake_minimum_required( VERSION 3.1 )
4+
project( lambdas LANGUAGES CXX )
5+
6+
# Set up the compilation environment.
7+
include( "${CMAKE_CURRENT_SOURCE_DIR}/../CompilerSettings.cmake" )
8+
9+
# Create the user's executable.
10+
add_executable( lambdas_randomize Complex.hpp randomize.cpp )
11+
12+
# Create the "solution executable".
13+
add_executable( lambdas_randomize.sol EXCLUDE_FROM_ALL
14+
Complex.hpp solution/randomize.sol.cpp )
15+
target_include_directories( lambdas_randomize.sol PRIVATE
16+
${CMAKE_CURRENT_SOURCE_DIR} )
17+
if( TARGET solution )
18+
add_dependencies( solution lambdas_randomize.sol )
19+
endif()

code/memcheck/CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
# Set up the project.
3+
cmake_minimum_required( VERSION 3.1 )
4+
project( memcheck LANGUAGES CXX )
5+
6+
# Set up the compilation environment.
7+
include( "${CMAKE_CURRENT_SOURCE_DIR}/../CompilerSettings.cmake" )
8+
9+
# Create the user's library.
10+
add_library( memcheckPoly Polygons.hpp Polygons.cpp )
11+
set_target_properties( memcheckPoly PROPERTIES OUTPUT_NAME "poly" )
12+
13+
# Create the user's executable.
14+
add_executable( memleak memleak.cpp )
15+
target_link_libraries( memleak PRIVATE memcheckPoly )
16+
17+
# Create the "solution library".
18+
add_library( memcheckPolySol EXCLUDE_FROM_ALL
19+
solution/Polygons.sol.hpp solution/Polygons.sol.cpp )
20+
set_target_properties( memcheckPolySol PROPERTIES OUTPUT_NAME "polysol" )
21+
22+
# Create the "solution executable".
23+
add_executable( memleak.sol EXCLUDE_FROM_ALL solution/memleak.sol.cpp )
24+
target_link_libraries( memleak.sol PRIVATE memcheckPolySol )
25+
if( TARGET solution )
26+
add_dependencies( solution memleak.sol )
27+
endif()

0 commit comments

Comments
 (0)