Skip to content

Commit 7141a34

Browse files
committed
process
Signed-off-by: TymianekPL <[email protected]>
1 parent 0843dc7 commit 7141a34

File tree

8 files changed

+52
-23
lines changed

8 files changed

+52
-23
lines changed

CMakeLists.txt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required (VERSION 3.29)
1+
cmake_minimum_required (VERSION 3.29)
22
project(StarProject LANGUAGES CXX)
33

44
set(CMAKE_CXX_STANDARD 23)
@@ -10,13 +10,15 @@ if (POLICY CMP0141) # MSVC hot-reload schenanigans
1010
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
1111
endif()
1212

13-
if (MSVC)
14-
add_compile_options(/experimental:module /EHsc /utf-8)
15-
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
16-
add_compile_options(-fmodules-ts -stdlib=libc++)
17-
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
18-
add_compile_options(-fmodules-ts)
13+
if(MSVC)
14+
string(REPLACE "/RTC1" "" OLD_FLAGS "${CMAKE_CXX_FLAGS_DEBUG}")
15+
set(CMAKE_CXX_FLAGS_DEBUG "${OLD_FLAGS}")
16+
add_compile_options(/permissive- /Zc:preprocessor /JMC /std:c++latest /GR- /GS- /EHsc-)
17+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
18+
add_compile_options(-ffreestanding -nostdinc++ -fno-exceptions -fno-rtti)
19+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
20+
add_compile_options(-ffreestanding -nostdinc++ -fno-exceptions -fno-rtti)
1921
endif()
2022

2123
add_subdirectory(starlib)
22-
add_subdirectory(testing)
24+
add_subdirectory(testing)

starlib/CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
add_library(starlib STATIC)
1+
add_library(starlib STATIC)
22

33
# Add module sources
44
target_sources(starlib
55
PUBLIC
66
FILE_SET cxx_modules TYPE CXX_MODULES FILES
77
starlib.ixx
8+
process.ixx
89
PRIVATE
910
starlib.cpp
10-
)
11+
process.cpp
12+
"process.ixx")
1113

1214
target_include_directories(starlib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
15+
16+
if(MSVC)
17+
target_link_options(starlib PRIVATE /NODEFAULTLIB)
18+
else()
19+
target_link_libraries(starlib PRIVATE -nostdlib++)
20+
endif()

starlib/process.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module;
2+
#ifdef _WIN32
3+
#include <Windows.h>
4+
#else
5+
#error Unsupported platform
6+
#endif
7+
8+
module process;
9+
10+
void starlib::process::Exit(int code)
11+
{
12+
#ifdef _WIN32
13+
ExitProcess(static_cast<UINT>(code));
14+
#else
15+
#error Unsupported platform
16+
#endif
17+
}

starlib/process.ixx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export module process;
2+
3+
namespace starlib::process
4+
{
5+
export [[noreturn]] void Exit(int code);
6+
}

starlib/starlib.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module starlib;
22

3-
int starlib::Meow(void)
3+
extern "C" void DefaultMain(void)
44
{
5-
return 1234;
5+
starlib::process::Exit(1);
66
}

starlib/starlib.ixx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
export module starlib;
22

3-
namespace starlib
4-
{
5-
export int Meow();
6-
}
3+
export import process;

testing/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@ target_sources(testing
66
)
77

88
target_link_libraries(testing PRIVATE starlib)
9+
10+
if(MSVC)
11+
target_link_options(testing PRIVATE /NODEFAULTLIB /ENTRY:DefaultMain)
12+
else()
13+
target_link_libraries(testing PRIVATE -nostdlib++)
14+
endif()

testing/main.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
11
import starlib;
2-
3-
#include <print>
4-
5-
int main(void)
6-
{
7-
std::println("Meow() -> {}", starlib::Meow());
8-
}

0 commit comments

Comments
 (0)