From b436d33c20e30e15151a92b0b91b0ecf32ef2cbc Mon Sep 17 00:00:00 2001 From: Attila Krasznahorkay Date: Fri, 9 Oct 2020 10:48:14 +0200 Subject: [PATCH 1/3] Added CMake configurations to all of the example projects. --- code/callgrind/CMakeLists.txt | 27 ++++++++++++++++ code/constness/CMakeLists.txt | 30 ++++++++++++++++++ code/cppcheck/CMakeLists.txt | 30 ++++++++++++++++++ code/debug/CMakeLists.txt | 30 ++++++++++++++++++ code/helgrind/CMakeLists.txt | 35 +++++++++++++++++++++ code/hello/CMakeLists.txt | 31 +++++++++++++++++++ code/lambdas/CMakeLists.txt | 30 ++++++++++++++++++ code/memcheck/CMakeLists.txt | 31 +++++++++++++++++++ code/move/CMakeLists.txt | 30 ++++++++++++++++++ code/polymorphism/CMakeLists.txt | 35 +++++++++++++++++++++ code/python/CMakeLists.txt | 41 +++++++++++++++++++++++++ code/race/CMakeLists.txt | 35 +++++++++++++++++++++ code/stl/CMakeLists.txt | 31 +++++++++++++++++++ code/templates/CMakeLists.txt | 31 +++++++++++++++++++ code/valgrind/CMakeLists.txt | 30 ++++++++++++++++++ code/virtual_inheritance/CMakeLists.txt | 35 +++++++++++++++++++++ 16 files changed, 512 insertions(+) create mode 100644 code/callgrind/CMakeLists.txt create mode 100644 code/constness/CMakeLists.txt create mode 100644 code/cppcheck/CMakeLists.txt create mode 100644 code/debug/CMakeLists.txt create mode 100644 code/helgrind/CMakeLists.txt create mode 100644 code/hello/CMakeLists.txt create mode 100644 code/lambdas/CMakeLists.txt create mode 100644 code/memcheck/CMakeLists.txt create mode 100644 code/move/CMakeLists.txt create mode 100644 code/polymorphism/CMakeLists.txt create mode 100644 code/python/CMakeLists.txt create mode 100644 code/race/CMakeLists.txt create mode 100644 code/stl/CMakeLists.txt create mode 100644 code/templates/CMakeLists.txt create mode 100644 code/valgrind/CMakeLists.txt create mode 100644 code/virtual_inheritance/CMakeLists.txt diff --git a/code/callgrind/CMakeLists.txt b/code/callgrind/CMakeLists.txt new file mode 100644 index 0000000..c36daa6 --- /dev/null +++ b/code/callgrind/CMakeLists.txt @@ -0,0 +1,27 @@ + +# Set up the project. +cmake_minimum_required( VERSION 3.1 ) +project( callgrind LANGUAGES CXX ) + +# Set up a Debug build type by default. +if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES ) + set( CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Choose the type of build." FORCE ) + set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Release" "MinSizeRel" "RelWithDebInfo" ) +endif() + +# Use C++17 in the project, or as high of a value as possible. +set( CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to use" ) +set( CMAKE_CXX_EXTENSIONS FALSE CACHE BOOL "(Dis)Allow C++ extensions" ) + +# Enable warnings for the build. +if( ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) OR + ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra" ) +elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4" ) +endif() + +# Create the executable. +add_executable( test test.cpp ) diff --git a/code/constness/CMakeLists.txt b/code/constness/CMakeLists.txt new file mode 100644 index 0000000..0e70448 --- /dev/null +++ b/code/constness/CMakeLists.txt @@ -0,0 +1,30 @@ + +# Set up the project. +cmake_minimum_required( VERSION 3.1 ) +project( constness LANGUAGES CXX ) + +# Set up a Debug build type by default. +if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES ) + set( CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Choose the type of build." FORCE ) + set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Release" "MinSizeRel" "RelWithDebInfo" ) +endif() + +# Use C++17 in the project, or as high of a value as possible. +set( CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to use" ) +set( CMAKE_CXX_EXTENSIONS FALSE CACHE BOOL "(Dis)Allow C++ extensions" ) + +# Enable warnings for the build. +if( ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) OR + ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra" ) +elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4" ) +endif() + +# Create the user's executable. +add_executable( test test.cpp ) + +# Create the "solution executable". +add_executable( test.sol EXCLUDE_FROM_ALL test.sol.cpp ) diff --git a/code/cppcheck/CMakeLists.txt b/code/cppcheck/CMakeLists.txt new file mode 100644 index 0000000..41a6c97 --- /dev/null +++ b/code/cppcheck/CMakeLists.txt @@ -0,0 +1,30 @@ + +# Set up the project. +cmake_minimum_required( VERSION 3.1 ) +project( cppcheck LANGUAGES CXX ) + +# Set up a Debug build type by default. +if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES ) + set( CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Choose the type of build." FORCE ) + set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Release" "MinSizeRel" "RelWithDebInfo" ) +endif() + +# Use C++17 in the project, or as high of a value as possible. +set( CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to use" ) +set( CMAKE_CXX_EXTENSIONS FALSE CACHE BOOL "(Dis)Allow C++ extensions" ) + +# Enable warnings for the build. +if( ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) OR + ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra" ) +elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4" ) +endif() + +# Create the user's executable. +add_executable( test test.cpp ) + +# Create the "solution executable". +add_executable( test.sol EXCLUDE_FROM_ALL test.sol.cpp ) diff --git a/code/debug/CMakeLists.txt b/code/debug/CMakeLists.txt new file mode 100644 index 0000000..37259f3 --- /dev/null +++ b/code/debug/CMakeLists.txt @@ -0,0 +1,30 @@ + +# Set up the project. +cmake_minimum_required( VERSION 3.1 ) +project( debug LANGUAGES CXX ) + +# Set up a Debug build type by default. +if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES ) + set( CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Choose the type of build." FORCE ) + set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Release" "MinSizeRel" "RelWithDebInfo" ) +endif() + +# Use C++17 in the project, or as high of a value as possible. +set( CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to use" ) +set( CMAKE_CXX_EXTENSIONS FALSE CACHE BOOL "(Dis)Allow C++ extensions" ) + +# Enable warnings for the build. +if( ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) OR + ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra" ) +elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4" ) +endif() + +# Create the user's executable. +add_executable( test test.cpp ) + +# Create the "solution executable". +add_executable( test.sol EXCLUDE_FROM_ALL test.sol.cpp ) diff --git a/code/helgrind/CMakeLists.txt b/code/helgrind/CMakeLists.txt new file mode 100644 index 0000000..dce17c0 --- /dev/null +++ b/code/helgrind/CMakeLists.txt @@ -0,0 +1,35 @@ + +# Set up the project. +cmake_minimum_required( VERSION 3.1 ) +project( helgrind LANGUAGES CXX ) + +# Set up a Debug build type by default. +if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES ) + set( CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Choose the type of build." FORCE ) + set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Release" "MinSizeRel" "RelWithDebInfo" ) +endif() + +# Use C++17 in the project, or as high of a value as possible. +set( CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to use" ) +set( CMAKE_CXX_EXTENSIONS FALSE CACHE BOOL "(Dis)Allow C++ extensions" ) + +# Enable warnings for the build. +if( ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) OR + ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra" ) +elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4" ) +endif() + +# Figure out how to use the platform's thread capabilities. +find_package( Threads REQUIRED ) + +# Create the user's executable. +add_executable( test test.cpp ) +target_link_libraries( test PRIVATE Threads::Threads ) + +# Create the "solution executable". +add_executable( test.sol EXCLUDE_FROM_ALL test.sol.cpp ) +target_link_libraries( test.sol PRIVATE Threads::Threads ) diff --git a/code/hello/CMakeLists.txt b/code/hello/CMakeLists.txt new file mode 100644 index 0000000..276b1af --- /dev/null +++ b/code/hello/CMakeLists.txt @@ -0,0 +1,31 @@ + +# Set up the project. +cmake_minimum_required( VERSION 3.1 ) +project( hello LANGUAGES CXX ) + +# Set up a Debug build type by default. +if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES ) + set( CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Choose the type of build." FORCE ) + set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Release" "MinSizeRel" "RelWithDebInfo" ) +endif() + +# Use C++17 in the project, or as high of a value as possible. +set( CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to use" ) +set( CMAKE_CXX_EXTENSIONS FALSE CACHE BOOL "(Dis)Allow C++ extensions" ) + +# Enable warnings for the build. +if( ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) OR + ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra" ) +elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4" ) +endif() + +# Set up the shared library. +add_library( hello SHARED hello.hpp hello.cpp ) + +# Set up the executable. +add_executable( test test.cpp ) +target_link_libraries( test PRIVATE hello ) diff --git a/code/lambdas/CMakeLists.txt b/code/lambdas/CMakeLists.txt new file mode 100644 index 0000000..b44ab0a --- /dev/null +++ b/code/lambdas/CMakeLists.txt @@ -0,0 +1,30 @@ + +# Set up the project. +cmake_minimum_required( VERSION 3.1 ) +project( lambdas LANGUAGES CXX ) + +# Set up a Debug build type by default. +if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES ) + set( CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Choose the type of build." FORCE ) + set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Release" "MinSizeRel" "RelWithDebInfo" ) +endif() + +# Use C++17 in the project, or as high of a value as possible. +set( CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to use" ) +set( CMAKE_CXX_EXTENSIONS FALSE CACHE BOOL "(Dis)Allow C++ extensions" ) + +# Enable warnings for the build. +if( ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) OR + ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra" ) +elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4" ) +endif() + +# Create the user's executable. +add_executable( test Complex.hpp test.cpp ) + +# Create the "solution executable". +add_executable( test.sol EXCLUDE_FROM_ALL Complex.hpp test.sol.cpp ) diff --git a/code/memcheck/CMakeLists.txt b/code/memcheck/CMakeLists.txt new file mode 100644 index 0000000..48f7002 --- /dev/null +++ b/code/memcheck/CMakeLists.txt @@ -0,0 +1,31 @@ + +# Set up the project. +cmake_minimum_required( VERSION 3.1 ) +project( memcheck LANGUAGES CXX ) + +# Set up a Debug build type by default. +if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES ) + set( CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Choose the type of build." FORCE ) + set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Release" "MinSizeRel" "RelWithDebInfo" ) +endif() + +# Use C++17 in the project, or as high of a value as possible. +set( CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to use" ) +set( CMAKE_CXX_EXTENSIONS FALSE CACHE BOOL "(Dis)Allow C++ extensions" ) + +# Enable warnings for the build. +if( ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) OR + ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra" ) +elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4" ) +endif() + +# Set up the shared library. +add_library( poly SHARED Polygons.hpp Polygons.cpp ) + +# Set up the executable. +add_executable( test test.cpp ) +target_link_libraries( test PRIVATE poly ) diff --git a/code/move/CMakeLists.txt b/code/move/CMakeLists.txt new file mode 100644 index 0000000..41e0cc2 --- /dev/null +++ b/code/move/CMakeLists.txt @@ -0,0 +1,30 @@ + +# Set up the project. +cmake_minimum_required( VERSION 3.1 ) +project( move LANGUAGES CXX ) + +# Set up a Debug build type by default. +if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES ) + set( CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Choose the type of build." FORCE ) + set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Release" "MinSizeRel" "RelWithDebInfo" ) +endif() + +# Use C++17 in the project, or as high of a value as possible. +set( CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to use" ) +set( CMAKE_CXX_EXTENSIONS FALSE CACHE BOOL "(Dis)Allow C++ extensions" ) + +# Enable warnings for the build. +if( ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) OR + ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra" ) +elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4" ) +endif() + +# Create the user's executable. +add_executable( test NVector.hpp test.cpp ) + +# Create the "solution executable". +add_executable( test.sol EXCLUDE_FROM_ALL NVector.sol.hpp test.sol.cpp ) diff --git a/code/polymorphism/CMakeLists.txt b/code/polymorphism/CMakeLists.txt new file mode 100644 index 0000000..0da8b7f --- /dev/null +++ b/code/polymorphism/CMakeLists.txt @@ -0,0 +1,35 @@ + +# Set up the project. +cmake_minimum_required( VERSION 3.1 ) +project( polymorhism LANGUAGES CXX ) + +# Set up a Debug build type by default. +if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES ) + set( CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Choose the type of build." FORCE ) + set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Release" "MinSizeRel" "RelWithDebInfo" ) +endif() + +# Use C++17 in the project, or as high of a value as possible. +set( CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to use" ) +set( CMAKE_CXX_EXTENSIONS FALSE CACHE BOOL "(Dis)Allow C++ extensions" ) + +# Enable warnings for the build. +if( ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) OR + ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra" ) +elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4" ) +endif() + +# Set up the shared library. +add_library( poly SHARED Polygons.hpp Polygons.cpp ) + +# Create the user's executable. +add_executable( test test.cpp ) +target_link_libraries( test PRIVATE poly ) + +# Create the "solution executable". +add_executable( test.sol EXCLUDE_FROM_ALL test.sol.cpp ) +target_link_libraries( test.sol PRIVATE poly ) diff --git a/code/python/CMakeLists.txt b/code/python/CMakeLists.txt new file mode 100644 index 0000000..2cb254c --- /dev/null +++ b/code/python/CMakeLists.txt @@ -0,0 +1,41 @@ + +# Set up the project. +cmake_minimum_required( VERSION 3.12 ) +project( python LANGUAGES CXX ) + +# Set up a Debug build type by default. +if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES ) + set( CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Choose the type of build." FORCE ) + set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Release" "MinSizeRel" "RelWithDebInfo" ) +endif() + +# Use C++17 in the project, or as high of a value as possible. +set( CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to use" ) +set( CMAKE_CXX_EXTENSIONS FALSE CACHE BOOL "(Dis)Allow C++ extensions" ) + +# Enable warnings for the build. +if( ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) OR + ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra" ) +elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4" ) +endif() + +# Find Python for the build. +find_package( Python2 COMPONENTS Development REQUIRED ) + +# Build the C++ shared library. +add_library( mandel SHARED Complex.hpp mandel.hpp mandel.cpp ) + +# Build a "C wrapper" around the C++ shared library. +add_library( mandelc SHARED mandel_cwrapper.hpp mandel_cwrapper.cpp ) +target_link_libraries( mandelc PUBLIC mandel ) + +# Build the Python module around the C++ shared library. +add_library( mandelm SHARED mandel_module.cpp ) +target_link_libraries( mandelm PRIVATE Python2::Python mandel ) +set_target_properties( mandelm PROPERTIES + PREFIX "" + OUTPUT_NAME "mandel" ) diff --git a/code/race/CMakeLists.txt b/code/race/CMakeLists.txt new file mode 100644 index 0000000..04b8f1e --- /dev/null +++ b/code/race/CMakeLists.txt @@ -0,0 +1,35 @@ + +# Set up the project. +cmake_minimum_required( VERSION 3.1 ) +project( race LANGUAGES CXX ) + +# Set up a Debug build type by default. +if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES ) + set( CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Choose the type of build." FORCE ) + set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Release" "MinSizeRel" "RelWithDebInfo" ) +endif() + +# Use C++17 in the project, or as high of a value as possible. +set( CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to use" ) +set( CMAKE_CXX_EXTENSIONS FALSE CACHE BOOL "(Dis)Allow C++ extensions" ) + +# Enable warnings for the build. +if( ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) OR + ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra" ) +elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4" ) +endif() + +# Figure out how to use the platform's thread capabilities. +find_package( Threads REQUIRED ) + +# Create the user's executable. +add_executable( test test.cpp ) +target_link_libraries( test PRIVATE Threads::Threads ) + +# Create the "solution executable". +add_executable( test.sol EXCLUDE_FROM_ALL test.sol.cpp ) +target_link_libraries( test.sol PRIVATE Threads::Threads ) diff --git a/code/stl/CMakeLists.txt b/code/stl/CMakeLists.txt new file mode 100644 index 0000000..21071a0 --- /dev/null +++ b/code/stl/CMakeLists.txt @@ -0,0 +1,31 @@ + +# Set up the project. +cmake_minimum_required( VERSION 3.1 ) +project( stl LANGUAGES CXX ) + +# Set up a Debug build type by default. +if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES ) + set( CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Choose the type of build." FORCE ) + set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Release" "MinSizeRel" "RelWithDebInfo" ) +endif() + +# Use C++17 in the project, or as high of a value as possible. +set( CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to use" ) +set( CMAKE_CXX_EXTENSIONS FALSE CACHE BOOL "(Dis)Allow C++ extensions" ) + +# Enable warnings for the build. +if( ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) OR + ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra" ) +elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4" ) +endif() + +# Create the user's executable(s). +add_executable( test Complex.hpp test.cpp ) +add_executable( test.nostl Complex.hpp test.nostl.cpp ) + +# Create the "solution executable". +add_executable( test.sol EXCLUDE_FROM_ALL Complex.hpp test.sol.cpp ) diff --git a/code/templates/CMakeLists.txt b/code/templates/CMakeLists.txt new file mode 100644 index 0000000..0834dd3 --- /dev/null +++ b/code/templates/CMakeLists.txt @@ -0,0 +1,31 @@ + +# Set up the project. +cmake_minimum_required( VERSION 3.1 ) +project( templates LANGUAGES CXX ) + +# Set up a Debug build type by default. +if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES ) + set( CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Choose the type of build." FORCE ) + set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Release" "MinSizeRel" "RelWithDebInfo" ) +endif() + +# Use C++17 in the project, or as high of a value as possible. +set( CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to use" ) +set( CMAKE_CXX_EXTENSIONS FALSE CACHE BOOL "(Dis)Allow C++ extensions" ) + +# Enable warnings for the build. +if( ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) OR + ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra" ) +elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4" ) +endif() + +# Create the user's executable. +add_executable( test OrderedVector.hpp Complex.hpp test.cpp ) + +# Create the "solution executable". +add_executable( test.sol EXCLUDE_FROM_ALL OrderedVector.sol.hpp Complex.hpp + test.sol.cpp ) diff --git a/code/valgrind/CMakeLists.txt b/code/valgrind/CMakeLists.txt new file mode 100644 index 0000000..d9b197b --- /dev/null +++ b/code/valgrind/CMakeLists.txt @@ -0,0 +1,30 @@ + +# Set up the project. +cmake_minimum_required( VERSION 3.1 ) +project( valgrind LANGUAGES CXX ) + +# Set up a Debug build type by default. +if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES ) + set( CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Choose the type of build." FORCE ) + set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Release" "MinSizeRel" "RelWithDebInfo" ) +endif() + +# Use C++17 in the project, or as high of a value as possible. +set( CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to use" ) +set( CMAKE_CXX_EXTENSIONS FALSE CACHE BOOL "(Dis)Allow C++ extensions" ) + +# Enable warnings for the build. +if( ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) OR + ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra" ) +elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4" ) +endif() + +# Create the user's executable. +add_executable( test test.cpp ) + +# Create the "solution executable". +add_executable( test.sol EXCLUDE_FROM_ALL test.sol.cpp ) diff --git a/code/virtual_inheritance/CMakeLists.txt b/code/virtual_inheritance/CMakeLists.txt new file mode 100644 index 0000000..b858577 --- /dev/null +++ b/code/virtual_inheritance/CMakeLists.txt @@ -0,0 +1,35 @@ + +# Set up the project. +cmake_minimum_required( VERSION 3.1 ) +project( virtual_inheritance LANGUAGES CXX ) + +# Set up a Debug build type by default. +if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES ) + set( CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Choose the type of build." FORCE ) + set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Release" "MinSizeRel" "RelWithDebInfo" ) +endif() + +# Use C++17 in the project, or as high of a value as possible. +set( CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to use" ) +set( CMAKE_CXX_EXTENSIONS FALSE CACHE BOOL "(Dis)Allow C++ extensions" ) + +# Enable warnings for the build. +if( ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" ) OR + ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra" ) +elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4" ) +endif() + +# Set up the shared library. +add_library( textbox SHARED TextBox.hpp TextBox.cpp ) + +# Create the user's executable. +add_executable( test test.cpp ) +target_link_libraries( test PRIVATE textbox ) + +# Create the "solution executable". +add_executable( test.sol EXCLUDE_FROM_ALL test.sol.cpp ) +target_link_libraries( test.sol PRIVATE textbox ) -- GitLab From 75b249bed6bcd504e1990c28f7fdfc4223b6d716 Mon Sep 17 00:00:00 2001 From: Attila Krasznahorkay Date: Fri, 9 Oct 2020 10:49:34 +0200 Subject: [PATCH 2/3] Fixes for the examples. One is there to avoid a simple warning during the build, the other one fixes the build of the solution executable outright. --- code/python/mandel_module.cpp | 2 +- code/templates/test.sol.cpp | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/code/python/mandel_module.cpp b/code/python/mandel_module.cpp index 68323d7..2cfcc84 100644 --- a/code/python/mandel_module.cpp +++ b/code/python/mandel_module.cpp @@ -1,7 +1,7 @@ #include #include "mandel.hpp" -static PyObject * mandel_wrapper(PyObject * self, +static PyObject * mandel_wrapper(PyObject * /*self*/, PyObject * args) { // Parse Input float r, i; diff --git a/code/templates/test.sol.cpp b/code/templates/test.sol.cpp index 1097060..5d979ee 100644 --- a/code/templates/test.sol.cpp +++ b/code/templates/test.sol.cpp @@ -1,4 +1,4 @@ -#include "OrderedVector.hpp" +#include "OrderedVector.sol.hpp" #include "Complex.hpp" #include #include @@ -24,19 +24,19 @@ struct ManhattanOrder { int main() { std::cout << "Integer" << std::endl; OrderedVector v(10); - for (int i = 10; i > 0; i--) + for (int i = 10; i > 0; i--) v.add(i); for (int i = 0; i < 10; i++) std::cout << v[i] << " "; std::cout << std::endl << std::endl; - + std::cout << "String" << std::endl; OrderedVector vs(5); vs.add(std::string("one")); vs.add(std::string("two")); vs.add(std::string("three")); vs.add(std::string("four")); - vs.add(std::string("five")); + vs.add(std::string("five")); for (int i = 0; i < 5; i++) std::cout << vs[i] << " "; std::cout << std::endl << std::endl; @@ -47,7 +47,7 @@ int main() { vc.add(Complex(1.0,1.0)); vc.add(Complex(-1.0,0.0)); vc.add(Complex(1.0,2.0)); - vc.add(Complex(0.0,0.0)); + vc.add(Complex(0.0,0.0)); for (int i = 0; i < 5; i++) std::cout << vc[i] << " "; std::cout << std::endl << std::endl; @@ -58,7 +58,7 @@ int main() { vsr.add(std::string("two")); vsr.add(std::string("three")); vsr.add(std::string("four")); - vsr.add(std::string("five")); + vsr.add(std::string("five")); for (int i = 0; i < 5; i++) std::cout << vsr[i] << " "; std::cout << std::endl << std::endl; @@ -69,7 +69,7 @@ int main() { vcm.add(Complex(1.0,1.0)); vcm.add(Complex(-1.0,0.0)); vcm.add(Complex(1.0,2.0)); - vcm.add(Complex(0.0,0.0)); + vcm.add(Complex(0.0,0.0)); for (int i = 0; i < 5; i++) std::cout << vcm[i] << " "; std::cout << std::endl << std::endl; @@ -81,7 +81,7 @@ int main() { vci.add(IComplex(1,1)); vci.add(IComplex(-1,0)); vci.add(IComplex(1,2)); - vci.add(IComplex(0,0)); + vci.add(IComplex(0,0)); for (int i = 0; i < 5; i++) std::cout << vci[i] << " "; std::cout << std::endl << std::endl; @@ -93,7 +93,7 @@ int main() { vcv.add(VComplex(Complex(2,0),Complex(0,2))); vcv.add(VComplex(Complex(1,0),Complex(0,0))); vcv.add(VComplex(Complex(0,1),Complex(1,0))); - vcv.add(VComplex(Complex(2,0),Complex(0,0))); + vcv.add(VComplex(Complex(2,0),Complex(0,0))); for (int i = 0; i < 5; i++) std::cout << vcv[i] << " "; std::cout << std::endl << std::endl; -- GitLab From c6d4fcaa211ed19fa55f3286b9e27544e1ff3c4c Mon Sep 17 00:00:00 2001 From: Attila Krasznahorkay Date: Fri, 9 Oct 2020 09:44:37 +0200 Subject: [PATCH 3/3] Taught (some of) the projects that build shared libraries, how to do it on Windows. On this platform one must explicit declare which symbols would be exported by the generated shared library (DLL). --- code/hello/CMakeLists.txt | 9 ++++++++- code/hello/hello.hpp | 4 +++- code/memcheck/CMakeLists.txt | 9 ++++++++- code/memcheck/Polygons.hpp | 7 +++++-- code/polymorphism/CMakeLists.txt | 9 ++++++++- code/polymorphism/Polygons.hpp | 9 ++++++--- code/virtual_inheritance/CMakeLists.txt | 9 ++++++++- code/virtual_inheritance/TextBox.hpp | 10 ++++++---- 8 files changed, 52 insertions(+), 14 deletions(-) diff --git a/code/hello/CMakeLists.txt b/code/hello/CMakeLists.txt index 276b1af..45a0325 100644 --- a/code/hello/CMakeLists.txt +++ b/code/hello/CMakeLists.txt @@ -24,7 +24,14 @@ elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" ) endif() # Set up the shared library. -add_library( hello SHARED hello.hpp hello.cpp ) +include( GenerateExportHeader ) +add_library( hello SHARED hello.hpp hello.cpp + "${CMAKE_CURRENT_BINARY_DIR}/hello_exports.hpp" ) +generate_export_header( hello + EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/hello_exports.hpp" + STATIC_DEFINE SHARED_EXPORTS_BUILT_AS_STATIC ) +target_include_directories( hello PUBLIC + $ ) # Set up the executable. add_executable( test test.cpp ) diff --git a/code/hello/hello.hpp b/code/hello/hello.hpp index d53f7ae..e3251ee 100644 --- a/code/hello/hello.hpp +++ b/code/hello/hello.hpp @@ -2,6 +2,8 @@ #ifndef HELLO_HPP #define HELLO_HPP -void printHello(int i) ; +#include "hello_exports.hpp" + +void HELLO_EXPORT printHello(int i) ; #endif diff --git a/code/memcheck/CMakeLists.txt b/code/memcheck/CMakeLists.txt index 48f7002..488c1d6 100644 --- a/code/memcheck/CMakeLists.txt +++ b/code/memcheck/CMakeLists.txt @@ -24,7 +24,14 @@ elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" ) endif() # Set up the shared library. -add_library( poly SHARED Polygons.hpp Polygons.cpp ) +include( GenerateExportHeader ) +add_library( poly SHARED Polygons.hpp Polygons.cpp + "${CMAKE_CURRENT_BINARY_DIR}/poly_exports.hpp" ) +generate_export_header( poly + EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/poly_exports.hpp" + STATIC_DEFINE SHARED_EXPORTS_BUILT_AS_STATIC ) +target_include_directories( poly PUBLIC + $ ) # Set up the executable. add_executable( test test.cpp ) diff --git a/code/memcheck/Polygons.hpp b/code/memcheck/Polygons.hpp index 6a5101f..2e2a3b6 100644 --- a/code/memcheck/Polygons.hpp +++ b/code/memcheck/Polygons.hpp @@ -1,4 +1,7 @@ -class Polygon { + +#include "poly_exports.hpp" + +class POLY_EXPORT Polygon { public: Polygon(int n, float radius); ~Polygon(){}; @@ -8,7 +11,7 @@ protected: int m_radius; }; -class Hexagon : public Polygon { +class POLY_EXPORT Hexagon : public Polygon { public: Hexagon(char* name, float radius); ~Hexagon(); diff --git a/code/polymorphism/CMakeLists.txt b/code/polymorphism/CMakeLists.txt index 0da8b7f..7351e64 100644 --- a/code/polymorphism/CMakeLists.txt +++ b/code/polymorphism/CMakeLists.txt @@ -24,7 +24,14 @@ elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" ) endif() # Set up the shared library. -add_library( poly SHARED Polygons.hpp Polygons.cpp ) +include( GenerateExportHeader ) +add_library( poly SHARED Polygons.hpp Polygons.cpp + "${CMAKE_CURRENT_BINARY_DIR}/poly_exports.hpp" ) +generate_export_header( poly + EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/poly_exports.hpp" + STATIC_DEFINE SHARED_EXPORTS_BUILT_AS_STATIC ) +target_include_directories( poly PUBLIC + $ ) # Create the user's executable. add_executable( test test.cpp ) diff --git a/code/polymorphism/Polygons.hpp b/code/polymorphism/Polygons.hpp index 5b75ffe..2826cd0 100644 --- a/code/polymorphism/Polygons.hpp +++ b/code/polymorphism/Polygons.hpp @@ -1,4 +1,7 @@ -class Polygon { + +#include "poly_exports.hpp" + +class POLY_EXPORT Polygon { public: Polygon(int n, float radius); float computePerimeter(); @@ -7,12 +10,12 @@ protected: int m_radius; }; -class Pentagon : public Polygon { +class POLY_EXPORT Pentagon : public Polygon { public: Pentagon(float radius); }; -class Hexagon : public Polygon { +class POLY_EXPORT Hexagon : public Polygon { public: Hexagon(float radius); // 6*radius is easier than generic case diff --git a/code/virtual_inheritance/CMakeLists.txt b/code/virtual_inheritance/CMakeLists.txt index b858577..14f2330 100644 --- a/code/virtual_inheritance/CMakeLists.txt +++ b/code/virtual_inheritance/CMakeLists.txt @@ -24,7 +24,14 @@ elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" ) endif() # Set up the shared library. -add_library( textbox SHARED TextBox.hpp TextBox.cpp ) +include( GenerateExportHeader ) +add_library( textbox SHARED TextBox.hpp TextBox.cpp + "${CMAKE_CURRENT_BINARY_DIR}/textbox_exports.hpp" ) +generate_export_header( textbox + EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/textbox_exports.hpp" + STATIC_DEFINE SHARED_EXPORTS_BUILT_AS_STATIC ) +target_include_directories( textbox PUBLIC + $ ) # Create the user's executable. add_executable( test test.cpp ) diff --git a/code/virtual_inheritance/TextBox.hpp b/code/virtual_inheritance/TextBox.hpp index 31fed4e..2b0ff49 100644 --- a/code/virtual_inheritance/TextBox.hpp +++ b/code/virtual_inheritance/TextBox.hpp @@ -1,6 +1,8 @@ #include -class Drawable { +#include "textbox_exports.hpp" + +class TEXTBOX_EXPORT Drawable { public: Drawable(int id); void draw(); @@ -8,7 +10,7 @@ private: int m_id; }; -class Rectangle : public Drawable { +class TEXTBOX_EXPORT Rectangle : public Drawable { public: Rectangle(int id, float width, float height); protected: @@ -16,14 +18,14 @@ protected: int m_height; }; -class Text : public Drawable { +class TEXTBOX_EXPORT Text : public Drawable { public: Text(int id, std::string content); protected: std::string m_content; }; -class TextBox : public Rectangle, public Text { +class TEXTBOX_EXPORT TextBox : public Rectangle, public Text { public: TextBox(std::string content, float width, float height); -- GitLab