-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example to test import std with cmake Test only Release builds on CI
- Loading branch information
1 parent
511114a
commit be999c2
Showing
13 changed files
with
170 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
include(ExternalProject) | ||
|
||
ExternalProject_Add( | ||
example | ||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/example | ||
#--Download step-------------- | ||
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/example | ||
#--Update/Patch step---------- | ||
#--Configure step------------- | ||
USES_TERMINAL_CONFIGURE TRUE | ||
CONFIGURE_COMMAND cmake -G "${CMAKE_GENERATOR}" -S ${CMAKE_CURRENT_SOURCE_DIR}/example -B . # | ||
-D CMAKE_BUILD_TYPE=$<CONFIG> -D CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} | ||
#--Build step----------------- | ||
USES_TERMINAL_BUILD TRUE | ||
# BUILD_IN_SOURCE 1 | ||
BUILD_COMMAND cmake --build <BINARY_DIR> -j 8 | ||
#--Install step--------------- | ||
USES_TERMINAL_INSTALL TRUE | ||
INSTALL_COMMAND ctest --verbose | ||
#--Logging ------------------- | ||
LOG_BUILD OFF | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# CMake 3.30 is required for C++23 `import std` support; we use 3.29.20240416 | ||
# here so that in-development versions satisfy it. | ||
cmake_minimum_required(VERSION 3.30 FATAL_ERROR) | ||
|
||
# Set experimental flag to enable `import std` support from CMake. | ||
# This must be enabled before C++ language support. | ||
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD # This specific value changes as experimental support evolves. See | ||
# `Help/dev/experimental.rst` in the CMake source corresponding to | ||
# your CMake build for the exact value to use. | ||
"0e5b6991-d74f-4b3d-a41c-cf096e0b2508" | ||
) | ||
|
||
# C++ needs to be enabled. | ||
project(import_std LANGUAGES CXX) | ||
|
||
# Tell CMake that we explicitly want `import std`. This will initialize the | ||
# property on all targets declared after this to 1 | ||
set(CMAKE_CXX_MODULE_STD 1) | ||
|
||
# Make a library. | ||
add_library(uses_std STATIC) | ||
# Add sources. | ||
target_sources(uses_std PRIVATE uses_std.cxx) | ||
# Tell CMake we're using C++23 but only C++20 is needed to consume it. | ||
target_compile_features(uses_std PRIVATE cxx_std_23 INTERFACE cxx_std_20) | ||
|
||
# Make an executable. | ||
add_executable(main) | ||
# Note that this source is *not* allowed to `import std` as it ends up | ||
# with only C++20 support due to the `uses_std` INTERFACE requirements. | ||
target_sources(main PRIVATE main.cxx) | ||
target_link_libraries(main PRIVATE uses_std) | ||
|
||
enable_testing() | ||
add_test(NAME main COMMAND main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <string> | ||
|
||
void hello_world(std::string const& name); | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
const char* name = "Voldemort?"; | ||
hello_world(name); | ||
while (--argc > 0) { | ||
hello_world(argv[argc]); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import std; | ||
|
||
void hello_world(std::string const& name) | ||
{ | ||
std::print("Hello World! My name is {}\n", name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.