Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tell msvc to not spawn a terminal and remove wWinMain #5

Merged
merged 1 commit into from
Oct 15, 2023
Merged
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
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
}