How to add command line options for mingw32-make from CMakeLists.txt?

696 Views Asked by At

I'm trying to build a little cross-platform application using curses. To use curses cross-platform, I'm using the instructions from this answer. It's almost working, except that on Windows (when running cmake -G "MinGW Makefiles" .. && cmake --build . from my build folder), I get a bunch of errors about PCONSOLE_SCREEN_BUFFER_INFOEX not being defined. To fix this error, pdcurses says to set INFOEX=N in the mingw32-make call. I can compile it fine using mingw32-make -f Makefile INFOEX=N, but I can't figure out how to pass INFOEX=N from CMakeLists.txt.

1

There are 1 best solutions below

1
On

A quick search through the repository indicates that the value is only used to add the HAVE_NO_INFOEX compiler definition. To allow the user to pass a configuration when configuring your project, you should add a cache variable which allows to pass the value when configuring the project (cmake -D VARIABLE_NAME=VALUE -G "MinGW Makefiles" ..).

Adjusting the CMakeLists.txt file presented in the linked answer it could be done like this:

...

if (WIN32)
    # variable set to False unless provided by user
    set(PDCURSES_INFOEX_MISSING False CACHE BOOL "Does pdcurses need to define CONSOLE_SCREEN_BUFFER_INFOEX?")
endif()

add_library(PDcurses
         # all of the sources
         ...
)

if (WIN32 AND PDCURSES_INFOEX_MISSING)
    target_compile_definitions(PDcurses PRIVATE HAVE_NO_INFOEX)
endif()

...
cmake -D PDCURSES_INFOEX_MISSING=True -G "MinGW Makefiles" ..

Note: If you want to avoid requiring the user to make this choice and possibly getting it wrong you could also use try_compile to check, source including windows.h and using CONSOLE_SCREEN_BUFFER_INFOEX would compile or not for windows target system...