Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions nob.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,6 @@ void print_available_commands(Commands commands)
}
}

#if defined(_WIN32) && defined(_MSC_VER) && defined(__cplusplus)
// TODO: I don't know why, but when you compile nob.c with
// cl.exe /std:c++20 /TP nob.c
// It just can't find the declaration of SetConsoleOutputCP().
// This is probably something about how we include windows.h in nob.h
extern "C" {
WINBASEAPI BOOL WINAPI SetConsoleOutputCP(_In_ UINT wCodePageID);
}
#endif

int main(int argc, char **argv)
{
#ifdef _WIN32
Expand Down
24 changes: 22 additions & 2 deletions nob.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@
#include <time.h>

#ifdef _WIN32
// TODO: We currently mix ANSI (xxxA) and macro-based Windows APIs. By undefining
// UNICODE, generic APIs resolve to their ANSI variants, but some code directly
// calls xxxA functions. This inconsistency limits Unicode path support on Windows.
// A better approach would be to consistently use wide-character (W) APIs with
// explicit UTF-8 <-> UTF-16 conversion.
# undef UNICODE
# define WIN32_LEAN_AND_MEAN
# define _WINUSER_
# define _WINGDI_
Expand All @@ -166,6 +172,16 @@
# include <direct.h>
# include <io.h>
# include <shellapi.h>
// TODO: SetConsoleOutputCP is declared in consoleapi2.h, but defining _WINCON_
// prevented windows.h from including it. The manual include below is a temporary
// workaround. The correct fix is to remove all private SDK guards and only keep
// WIN32_LEAN_AND_MEAN.
# include <consoleapi2.h>
# undef _WINUSER_
# undef _WINGDI_
# undef _IMM_
# undef _WINCON_
# undef WIN32_LEAN_AND_MEAN
#else
# ifdef __APPLE__
# include <mach-o/dyld.h>
Expand Down Expand Up @@ -821,8 +837,12 @@ NOBDEF char *nob_temp_running_executable_path(void);
#endif // nob_cc_flags

#ifndef nob_cc_output
# if defined(_MSC_VER) && !defined(__clang__)
# define nob_cc_output(cmd, output_path) nob_cmd_append(cmd, nob_temp_sprintf("/Fe:%s", (output_path)), nob_temp_sprintf("/Fo:%s", (output_path)))
# if defined(_MSC_VER)
# if defined(__clang__)
# define nob_cc_output(cmd, output_path) nob_cmd_append(cmd, nob_temp_sprintf("-o%s.exe", (output_path)))
# else
# define nob_cc_output(cmd, output_path) nob_cmd_append(cmd, nob_temp_sprintf("/Fe:%s", (output_path)), nob_temp_sprintf("/Fo:%s", (output_path)))
# endif
# else
# define nob_cc_output(cmd, output_path) nob_cmd_append(cmd, "-o", (output_path))
# endif
Expand Down
15 changes: 13 additions & 2 deletions shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,25 @@

#if defined(__cplusplus)
#if defined(_MSC_VER)
#define nob_cc_flags(cmd) cmd_append(cmd, "/std:c++20", "/TP", "/W4", "/nologo", "/D_CRT_SECURE_NO_WARNINGS", "-I.")
#if defined(__clang__)
// TODO: Clang targeting MSVC in C++ mode warns about missing field initializers
// and missing braces when using C-style {0} initialization. Suppress for now.
#define nob_cc_flags(cmd) cmd_append(cmd, "-x", "c++", "-Wall", "-Wextra", "-Wswitch-enum", \
"-Wno-missing-field-initializers", "-Wno-missing-braces", "-D_CRT_SECURE_NO_WARNINGS", "-I.")
#else
#define nob_cc_flags(cmd) cmd_append(cmd, "/utf-8", "/std:c++20", "/TP", "/W4", "/nologo", "/D_CRT_SECURE_NO_WARNINGS", "-I.")
#endif
#else
#define nob_cc(cmd) cmd_append(cmd, "cc", "-x", "c++")
#define nob_cc_flags(cmd) cmd_append(cmd, "-Wall", "-Wextra", "-Wno-missing-field-initializers", "-Wswitch-enum", "-ggdb", "-I.");
#endif
#else // __cplusplus
#if defined(_MSC_VER)
#define nob_cc_flags(cmd) cmd_append(cmd, "/TC", "/W4", "/nologo", "/D_CRT_SECURE_NO_WARNINGS", "-I.")
#if defined(__clang__)
#define nob_cc_flags(cmd) cmd_append(cmd, "-Wall", "-Wextra", "-Wswitch-enum", "-std=c99", "-D_CRT_SECURE_NO_WARNINGS", "-I.")
#else
#define nob_cc_flags(cmd) cmd_append(cmd, "/utf-8", "/TC", "/W4", "/nologo", "/D_CRT_SECURE_NO_WARNINGS", "-I.")
#endif
#elif defined(__APPLE__) || defined(__MACH__)
// TODO: "-std=c99", "-D_POSIX_C_SOURCE=200112L" didn't work for MacOS, don't know why, don't really care that much at the moment.
// Anybody who does feel free to investigate.
Expand Down