Skip to content

Commit f073f02

Browse files
committed
freestanding
Signed-off-by: TymianekPL <tymi@tymi.org>
1 parent 0843dc7 commit f073f02

File tree

5 files changed

+31
-13
lines changed

5 files changed

+31
-13
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 /Za /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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
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.ixx")
1112

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

starlib/starlib.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ int starlib::Meow(void)
44
{
55
return 1234;
66
}
7+
8+
extern "C" void DefaultMain(void)
9+
{
10+
11+
}

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: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import starlib;
22

3-
#include <print>
4-
53
int main(void)
64
{
7-
std::println("Meow() -> {}", starlib::Meow());
5+
return starlib::Meow();
86
}

0 commit comments

Comments
 (0)