Initial Commit
This commit is contained in:
11
examples/cmake/CMakeLists.txt
Normal file
11
examples/cmake/CMakeLists.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
project(cex_cmake_demo LANGUAGES CXX)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(DEMO_INCREMENT 1)
|
||||
configure_file(config.hpp.in generated/config.hpp @ONLY)
|
||||
add_library(numbers src/numbers.cpp)
|
||||
target_include_directories(numbers PUBLIC src PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/generated")
|
||||
add_executable(cmake-demo main.cpp)
|
||||
target_link_libraries(cmake-demo PRIVATE numbers)
|
||||
2
examples/cmake/config.hpp.in
Normal file
2
examples/cmake/config.hpp.in
Normal file
@@ -0,0 +1,2 @@
|
||||
#pragma once
|
||||
#define DEMO_INCREMENT @DEMO_INCREMENT@
|
||||
7
examples/cmake/main.cpp
Normal file
7
examples/cmake/main.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "numbers.hpp"
|
||||
template<Addable T>
|
||||
T twice(T value) { return value + value; }
|
||||
constexpr int evaluation_mode() {
|
||||
if consteval { return 1; } else { return 2; }
|
||||
}
|
||||
int main() { return increment(twice(20)) + evaluation_mode(); }
|
||||
3
examples/cmake/src/numbers.cpp
Normal file
3
examples/cmake/src/numbers.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
#include "numbers.hpp"
|
||||
#include "config.hpp"
|
||||
int increment(int value) { return value + DEMO_INCREMENT; }
|
||||
4
examples/cmake/src/numbers.hpp
Normal file
4
examples/cmake/src/numbers.hpp
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
template<class T>
|
||||
concept Addable = requires(T value) { value + value; };
|
||||
int increment(int value);
|
||||
Reference in New Issue
Block a user