Flags for language <LANG>when building for the <CONFIG>configuration.
SET(CMAKE_C_FLAGS_DEBUG "-g -D_DEBUG -O0")
SET(CMAKE_C_FLAGS_RELEASE "-g -DNDEBUG -O3")
SET(CMAKE_CXX_FLAGS_DEBUG "-g -D_DEBUG -O0")
SET(CMAKE_CXX_FLAGS_RELEASE "-g -DNDEBUG -O3")
一、使用工具:CMake、编程工具
二、方法步骤:
1、添加头文件目录INCLUDE_DIRECTORIES
2、它相当于g++选项中的-I参数的作用,也相当于环境变量中增加路径到CPLUS_INCLUDE_PATH变量的作用。
include_directories(../../../thirdparty/comm/include)
三、注意事项:CMake支持大写、小写、混合大小写的命令。
给你个例子:project(NumRandom)
cmake_minimum_required(VERSION 2.8)
add_definitions(-D_UNICODE -DUNICODE)
add_definitions("/wd4819")
if(NOT ${CMAKE_BUILD_TYPE} MATCHES "Debug")
set(WINDOWS WIN32)
add_definitions(-D_IRR_STATIC_LIB_)
set(LIBRARIES Irrlicht_S.lib)
else()
set(LIBRARIES Irrlicht.lib)
endif()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
foreach(flag_var
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif()
endforeach()
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${WINDOWS} ${SRC_LIST})
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/ENTRY:mainCRTStartup")
target_link_libraries(${PROJECT_NAME} ${LIBRARIES})
以及一个target的调用方法:
cmd /C "if not exist Build (mkdir Build &&chdir Build &&cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=MinSizeRel .. &&nmake verbose=1) else chdir Build &&cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=MinSizeRel .. &&nmake"
注意其中的:-DCMAKE_BUILD_TYPE=MinSizeRel
转载
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)