@@ -26,6 +26,7 @@ if(MSVC)
2626else ()
2727
2828include (CheckCCompilerFlag)
29+ option (GITLEDGER_USE_NOSTDLIB "Link executables with -nostdlib (non-MSVC)"  OFF )
2930# Project policy: strict warnings, C99, no fun, visibility hidden. 
3031set (PROJECT_WARNING_FLAGS -Wall -Wextra -Werror -pedantic -Wshadow -Wconversion -fvisibility=hidden -std=c99)
3132check_c_compiler_flag("-Wno-fun"  COMPILER_SUPPORTS_WNOFUN)
@@ -54,10 +55,14 @@ add_library(gitledger STATIC ${LIBGITLEDGER_SOURCES} ${LIBGITLEDGER_HEADERS})
5455target_compile_options (gitledger PRIVATE  ${PROJECT_WARNING_FLAGS} )
5556target_compile_definitions (gitledger PRIVATE  GITLEDGER_BUILD=1)
5657function (add_nostdlib target )
57-   if (NOT  MSVC )
58+   if (GITLEDGER_USE_NOSTDLIB  AND   NOT  MSVC )
5859    target_link_options (${target}  PRIVATE  -nostdlib)
5960  endif ()
6061endfunction ()
62+ if (NOT  MSVC )
63+   # Keep library pure/freestanding from the linker perspective. 
64+   target_link_options (gitledger PRIVATE  -nostdlib)
65+ endif ()
6166
6267if (GITLEDGER_VENDOR_LIBGIT2)
6368    message (FATAL_ERROR "Vendored libgit2 support is not implemented yet.\n " 
@@ -130,7 +135,6 @@ if(BUILD_TESTING)
130135    add_test (NAME  gitledger_cli_smoke COMMAND  gitledger_tests)
131136    add_test (NAME  error COMMAND  gitledger_error_test)
132137endif ()
133- add_nostdlib(gitledger)
134138add_nostdlib(gitledger_version_test)
135139add_nostdlib(gitledger_tests)
136140add_nostdlib(mg-ledger)
0 commit comments