[英]How to add command line options for mingw32-make from CMakeLists.txt?
I'm trying to build a little cross-platform application using curses.我正在尝试使用 curses 构建一个小的跨平台应用程序。 To use curses cross-platform, I'm using the instructions from this answer .要跨平台使用 curses,我使用了这个答案中的说明。 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. 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.为了修复这个错误,pdcurses 说在mingw32-make
调用中设置INFOEX=N
。 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
.我可以使用mingw32-make -f Makefile INFOEX=N
很好地编译它,但我不知道如何从CMakeLists.txt
传递INFOEX=N
。
A quick search through the repository indicates that the value is only used to add the HAVE_NO_INFOEX
compiler definition.快速搜索存储库表明该值仅用于添加HAVE_NO_INFOEX
编译器定义。 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"..
).要允许用户在配置项目时传递配置,您应该添加一个缓存变量,允许在配置项目时传递值( cmake -D VARIABLE_NAME=VALUE -G "MinGW Makefiles"..
)。
Adjusting the CMakeLists.txt
file presented in the linked answer it could be done like this:调整链接答案中显示的CMakeLists.txt
文件,可以这样完成:
...
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...注意:如果您想避免要求用户做出此选择并可能出错,您还可以使用try_compile
来检查,包括windows.h
的源代码和使用CONSOLE_SCREEN_BUFFER_INFOEX
是否可以编译 windows 目标系统...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.