Skip to content

Commit

Permalink
Tell msvc to not spawn a terminal and remove wWinMain (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
CBenoit authored Oct 15, 2023
1 parent 4ade9ae commit 3bdd2d4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 38 deletions.
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ set_target_properties(
#target_compile_options(ninja-clown PRIVATE "-fsanitize=address")
#target_link_options(ninja-clown PRIVATE "-fsanitize=address")

# Do not open console on Windows
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC"))
# https://learn.microsoft.com/en-us/cpp/build/reference/subsystem-specify-subsystem
# https://learn.microsoft.com/en-us/cpp/build/reference/entry-entry-point-symbol
target_link_options(ninja-clown PRIVATE
"/SUBSYSTEM:WINDOWS"
"/ENTRY:mainCRTStartup"
)
elseif(MINGW)
# https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/x86-Windows-Options.html
target_link_options(ninja-clown PRIVATE "-mwindows")
endif()

target_include_directories(ninja-clown PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/ ${CMAKE_CURRENT_LIST_DIR}/bindings/c/)
target_include_directories(ninja-clown SYSTEM PUBLIC
${IMGUI_SFML_INCLUDE_DIR}
Expand Down
40 changes: 2 additions & 38 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,13 @@

#include "state_holder.hpp"

int actual_main(std::vector<std::string> &args);

#ifdef USE_WINMAIN
#include <shellapi.h>
#include <tchar.h>
#include <windows.h>

INT WINAPI wWinMain(HINSTANCE, HINSTANCE, LPWSTR, INT) {

int argc;
LPWSTR *lpArgv = CommandLineToArgvW(GetCommandLineW(), &argc);

std::vector<std::string> args;
args.reserve(argc);
for (int i = 0; i < argc; ++i) {
size_t size = wcslen(lpArgv[i]) + 1;
std::string arg;
arg.resize(size);
wcstombs_s(nullptr, arg.data(), arg.size(), lpArgv[i], size);
args.emplace_back(std::move(arg));
}
LocalFree(lpArgv);
return actual_main(args);
}
#else
int main(int argc, char *argv[]) {
std::vector<std::string> args;
args.reserve(argc);
while ((argc--) != 0) {
args.emplace_back(*argv++);
}
return actual_main(args);
}
#endif

int actual_main([[maybe_unused]] std::vector<std::string> &args) {
int main() {
spdlog::default_logger()->set_level(spdlog::level::trace);
// TODO: ajouter un logger à spdlog qui fait des popups pour les erreurs

state::holder game{"resources/autorun.ncs"};
game.run();
game.wait();

return 0;

// todo : ajouter un logger à spdlog qui fait des popups pour les erreurs
}

0 comments on commit 3bdd2d4

Please sign in to comment.