我正在尝试在cmake中定义几个自定义#define
但由于某种原因,VS将它们识别为已定义的宏,但检查它是否已定义#ifdef
不起作用。
示例:
CMakeLists.txt
cmake_minimum_required(VERSION 3.7)
project(StormEngine VERSION "0.0.0")
set(CMAKE_CXX_STANDARD 17)
if (WIN32)
add_definitions(-DWIN32_BUILD)
elseif(WIN64)
add_definitions(-DWIN64_BUILD)
endif()
if (WIN32 OR WIN64)
add_definitions(-DWIN_BUILD)
endif()
set(SOURCE_FILES main.cpp)
add_executable(StormEngine ${SOURCE_FILES})
更新了CMakeLists.txt
注意:即使在下面的更改后,问题仍然存在。
cmake_minimum_required(VERSION 3.7)
project(StormEngine VERSION "0.0.0")
set(CMAKE_CXX_STANDARD 17)
if (WIN32)
add_definitions(-DWIN32_BUILD)
add_definitions(-DWIN_BUILD)
endif()
set(SOURCE_FILES main.cpp)
add_executable(StormEngine ${SOURCE_FILES})
的main.cpp
#include <iostream>
int main()
{
std::cout << "main called..." << std::endl;
#ifdef WIN_BUILD
std::cout << "Window Build" << std::endl;
#endif
return 0;
}
输出应该是:
main called...
Window Build
实际输出:
main called...
答案 0 :(得分:0)
如果您阅读例如this reference about CMake variables that describe the system,没有WIN64
或WIN
个变量。
使用WIN32
检测Windows(32位和64位)。