0

so I've been developing an application in debug for a little while and I've come to the point where I need to check the release status, so I did a little research and found out how to use CMake's build types (I'm kinda new to CMake so bear with me). Basically I use:

cmake -DCMAKE_BUILD_TYPE=Release .. -G Ninja

But for some reason, the console (which I only use for logging) is still opening. How can I avoid this? I mean, I'm using GLFW to create a window, and I only want that window opening, not the console. Ideally, the console would only open in debug builds, but I don't know how to achieve this, is there some sort of compiler flag? I'm using Clang btw.

Here's the CMakeLists.txt:

CMAKE_MINIMUM_REQUIRED(VERSION 3.21)

SET(CMAKE_EXPORT_COMPILE_COMMANDS ON)

SET(CMAKE_CXX_STANDARD 20)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)

PROJECT(App VERSION 1.0.0)

# Engine
ADD_LIBRARY(engine
    src/engine/graphics.cpp
)

TARGET_INCLUDE_DIRECTORIES(engine PUBLIC src/engine)

# Vulkan
FIND_PACKAGE(Vulkan REQUIRED)

TARGET_INCLUDE_DIRECTORIES(engine PUBLIC ${Vulkan_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(engine ${Vulkan_LIBRARIES})

# GLFW
SET(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
SET(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
SET(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)

ADD_SUBDIRECTORY(dependencies/glfw)

TARGET_LINK_LIBRARIES(engine glfw)

# Executable
ADD_EXECUTABLE(app src/main.cpp)

TARGET_LINK_LIBRARIES(app engine)
Karlos
  • 197
  • 7
  • If you are looking for a way to disable console in CMake projects, then see [that question](https://stackoverflow.com/questions/2753761/how-do-i-tell-cmake-not-to-create-a-console-window) and its answers. If you are trying to implement some of these answers in your code, but it doesn't work, then we need to see your code. – Tsyvarev Feb 14 '22 at 16:43
  • @Tsyvarev my app is nothing, just a GLFW window and some basic Vulkan rendering to it. I've already tried `cmake -DCMAKE_CXX_FLAGS="-mwindows"` .. – Karlos Feb 14 '22 at 16:49
  • I meant your CMake code (`CMakeLists.txt`). – Tsyvarev Feb 14 '22 at 16:51
  • @Tsyvarev I just edited my post, there's the code – Karlos Feb 14 '22 at 17:29
  • `-mwindows` goes into linker flags (`CMAKE_EXE_LINKER_FLAGS` I think?), not into compiler flags. – HolyBlackCat Feb 14 '22 at 17:32
  • @HolyBlackCat I just tried it, still not working ;( – Karlos Feb 14 '22 at 17:43
  • It should work. Try building a simple app directly from the terminal. – HolyBlackCat Feb 14 '22 at 17:43
  • @HolyBlackCat I'm thinking maybe its cause I'm using Clang, and maybe Clang's flags for hiding the console are different or something?.. idk – Karlos Feb 14 '22 at 17:45
  • Did you get a error when using this flag, or no effect? *"maybe Clang's flags for hiding the console are different"* Depends on how you-re using Clang. If in MSVC-compatible mode (the default on Windows, assuming the official Clang build), then yes, the flag might be different. Otherwise `-mwindows` should work. – HolyBlackCat Feb 14 '22 at 17:53
  • @HolyBlackCat No errors, still the same, I added it to the CMakeLists.txt like this `SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -mwindows")` – Karlos Feb 14 '22 at 17:57
  • `target_link_options(app PRIVATE -mwindows)`; and pack it into an if to only be used in release builds – Daniel Jour Feb 14 '22 at 20:01

0 Answers0