zoukankan      html  css  js  c++  java
  • CMake: (二) 常见配置


    生成文件输出目录

    可执行文件的输出目录

    SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../bin) 
    

    上面的语句能设置可执行文件的输出目录
    Win + VS环境下,会自动在你所设置的目录后面扩展一层 <CONFIG> 目录,所以最终生成的Debug版本程序会在 ${PROJECT_SOURCE_DIR}/../bin/Debug 目录下,Release版本程序会在 ${PROJECT_SOURCE_DIR}/../bin/Release 目录下.

    Linux + GCC环境下,无论是Debug还是Release,生成的可执行程序会直接放在你所设置的目录下,不会有差异.

    库文件的输出目录

    SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../lib)
    

    上面的语句能设置库文件的输出目录
    Win + VS环境下,会自动在你所设置的目录后面扩展一层 <CONFIG> 目录,所以最终生成的Debug版本库会在 ${PROJECT_SOURCE_DIR}/../lib/Debug 目录下,Release版本库会在 ${PROJECT_SOURCE_DIR}/../lib/Release 目录下.

    Linux + GCC环境下,无论是Debug还是Release,生成的库文件会直接放在你所设置的目录下,不会有差异.

    Debug/Release可执行文件的输出目录

    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/../bin)
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/../bin)
    

    上面两条语句分别设置了Debug版本和Release版本可执行文件的输出目录,一旦设置上面的属性,在任何环境下生成的可执行文件都将直接放在你所设置的目录.

    库文件的输出目录

    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/../lib)  
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/../lib)
    

    上面两条语句分别设置了Debug版本和Release版本库文件的输出目录,一旦设置上面的属性,在任何环境下生成的库文件都将直接放在你所设置的目录.

    库文件的后缀名

    set(CMAKE_DEBUG_POSTFIX "_d") 
    set(CMAKE_RELEASE_POSTFIX "_r")
    

    上面两条语句分别设置了Debug版本和Release版本下库文件的后缀名.

    可执行文件的后缀名

    set_target_properties(${TARGET_NAME} PROPERTIES DEBUG_POSTFIX "_d") 
    set_target_properties(${TARGET_NAME} PROPERTIES RELEASE_POSTFIX "_r")
    

    上面两条语句分别设置了Debug版本和Release版本下可执行文件的后缀名


    默认编译、链接选项

    cmake_minimum_required(VERSION 3.2)
    
    message(STATUS "CMAKE_C_FLAGS = " ${CMAKE_C_FLAGS})
    message(STATUS "CMAKE_C_FLAGS_DEBUG = " ${CMAKE_C_FLAGS_DEBUG})
    message(STATUS "CMAKE_C_FLAGS_MINSIZEREL = " ${CMAKE_C_FLAGS_MINSIZEREL})
    message(STATUS "CMAKE_C_FLAGS_RELEASE = " ${CMAKE_C_FLAGS_RELEASE})
    message(STATUS "CMAKE_C_FLAGS_RELWITHDEBINFO = " ${CMAKE_C_FLAGS_RELWITHDEBINFO})
    
    message(STATUS "CMAKE_CXX_FLAGS = " ${CMAKE_CXX_FLAGS})
    message(STATUS "CMAKE_CXX_FLAGS_DEBUG = " ${CMAKE_CXX_FLAGS_DEBUG})
    message(STATUS "CMAKE_CXX_FLAGS_MINSIZEREL = " ${CMAKE_CXX_FLAGS_MINSIZEREL})
    message(STATUS "CMAKE_CXX_FLAGS_RELEASE = " ${CMAKE_CXX_FLAGS_RELEASE})
    message(STATUS "CMAKE_CXX_FLAGS_RELWITHDEBINFO = " ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
    
    message(STATUS "CMAKE_EXE_LINKER_FLAGS = " ${CMAKE_EXE_LINKER_FLAGS})
    message(STATUS "CMAKE_EXE_LINKER_FLAGS_DEBUG = " ${CMAKE_EXE_LINKER_FLAGS_DEBUG})
    message(STATUS "CMAKE_EXE_LINKER_FLAGS_MINSIZEREL = " ${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL})
    message(STATUS "CMAKE_EXE_LINKER_FLAGS_RELEASE = " ${CMAKE_EXE_LINKER_FLAGS_RELEASE})
    message(STATUS "CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO = " ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO})
    
    message(STATUS "CMAKE_MODULE_LINKER_FLAGS = " ${CMAKE_MODULE_LINKER_FLAGS})
    message(STATUS "CMAKE_MODULE_LINKER_FLAGS_DEBUG = " ${CMAKE_MODULE_LINKER_FLAGS_DEBUG})
    message(STATUS "CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL = " ${CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL})
    message(STATUS "CMAKE_MODULE_LINKER_FLAGS_RELEASE = " ${CMAKE_MODULE_LINKER_FLAGS_RELEASE})
    message(STATUS "CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO = " ${CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO})
    
    message(STATUS "CMAKE_SHARED_LINKER_FLAGS = " ${CMAKE_SHARED_LINKER_FLAGS})
    message(STATUS "CMAKE_SHARED_LINKER_FLAGS_DEBUG = " ${CMAKE_SHARED_LINKER_FLAGS_DEBUG})
    message(STATUS "CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL = " ${CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL})
    message(STATUS "CMAKE_SHARED_LINKER_FLAGS_RELEASE = " ${CMAKE_SHARED_LINKER_FLAGS_RELEASE})
    message(STATUS "CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO = " ${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO})
    
    message(STATUS "CMAKE_STATIC_LINKER_FLAGS = " ${CMAKE_STATIC_LINKER_FLAGS})
    message(STATUS "CMAKE_STATIC_LINKER_FLAGS_DEBUG = " ${CMAKE_STATIC_LINKER_FLAGS_DEBUG})
    message(STATUS "CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL = " ${CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL})
    message(STATUS "CMAKE_STATIC_LINKER_FLAGS_RELEASE = " ${CMAKE_STATIC_LINKER_FLAGS_RELEASE})
    message(STATUS "CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO = " ${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO})
    

    输出结果为


    参考

    1. 阿汤的博客
  • 相关阅读:
    平凡的世界
    MySql启动,提示:Plugin 'FEDERATED' is disabled....Cannot allocate memory for the buffer pool
    MySql开启慢查询报错:Could not open /var/log/slow_query.log for logging (error 13).
    ie浏览器,背景色兼容解决方法
    基于Bootstrap、Jquery的自适应导航栏
    chmod、chown、chgrp的意思
    Can't connect to MySQL server on localhost (0)
    mysql-bin引起mysql不能启动
    文件类型检测
    从数据库中查询规则
  • 原文地址:https://www.cnblogs.com/flyinggod/p/13713358.html
Copyright © 2011-2022 走看看