diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..46210d3 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.26) +project(LearningProject CXX) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + string(CONCAT CMAKE_EXPERIMENTAL_CXX_SCANDEP_SOURCE + " " + " -MT -MD -MF " + " ${flags_to_scan_deps} -fdep-file= -fdep-output=" + ) + + set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FORMAT "gcc") + set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FLAG + "${compiler_flags_for_module_map} -fmodule-mapper=") +endif() + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1) +set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "2182bf5c-ef0d-489a-91da-49dbc3090d2a") +set(CMAKE_CXX_EXTENSIONS OFF) + +add_subdirectory(src) + diff --git a/meson.build b/meson.build deleted file mode 100644 index 07fd168..0000000 --- a/meson.build +++ /dev/null @@ -1,2 +0,0 @@ -project('LearningProject', 'cpp') -subdir('src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..6aef24c --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,7 @@ +add_subdirectory(math) + +add_executable(hello hello.cc) +add_executable(sqrt sqrt.cc) +target_link_libraries(sqrt PRIVATE Math) +add_executable(inheritance inheritance.cc) +add_executable(enumerations enumerations.cc) diff --git a/src/enumerations.cc b/src/enumerations.cc index 1f56ce4..284c9cd 100644 --- a/src/enumerations.cc +++ b/src/enumerations.cc @@ -1,6 +1,6 @@ #include -std::string generate_crewmate_string(std::string type); +constexpr std::string generate_crewmate_string(std::string type); enum class CrewmateType { Sus, @@ -34,7 +34,7 @@ public: } }; -std::string generate_crewmate_string(std::string type) +constexpr std::string generate_crewmate_string(std::string type) { return "Your crewmate type is " + type; } diff --git a/src/math.cc b/src/math.cc deleted file mode 100644 index df0d870..0000000 --- a/src/math.cc +++ /dev/null @@ -1,5 +0,0 @@ -#include "math.hh" -double Math::square(double x) -{ - return x * x; -} diff --git a/src/math.hh b/src/math.hh deleted file mode 100644 index 799321a..0000000 --- a/src/math.hh +++ /dev/null @@ -1,4 +0,0 @@ -class Math { -public: - double static square(double x); -}; diff --git a/src/math/CMakeLists.txt b/src/math/CMakeLists.txt new file mode 100644 index 0000000..5a744b7 --- /dev/null +++ b/src/math/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(Math) +target_sources(Math PUBLIC FILE_SET cxx_modules TYPE CXX_MODULES FILES math.cc) diff --git a/src/math/math.cc b/src/math/math.cc new file mode 100644 index 0000000..2c72510 --- /dev/null +++ b/src/math/math.cc @@ -0,0 +1,12 @@ +module; +export module Math; + +export class Math { +public: + double static square(double x); +}; + +double Math::square(double x) +{ + return x * x; +} diff --git a/src/meson.build b/src/meson.build deleted file mode 100644 index 473b72f..0000000 --- a/src/meson.build +++ /dev/null @@ -1,4 +0,0 @@ -executable('hello', 'hello.cc') -executable('sqrt', ['math.cc', 'sqrt.cc']) -executable('inheritance', 'inheritance.cc') -executable('enumerations', 'enumerations.cc') diff --git a/src/sqrt.cc b/src/sqrt.cc index 1a5f411..9ab549d 100644 --- a/src/sqrt.cc +++ b/src/sqrt.cc @@ -1,4 +1,4 @@ -#include "math.hh" +import Math; #include void print_squared(double x);