cmake增加编译宏


通过增加编译宏实现条件编译

ADD_DEFINITIONS(-D宏名称 -D宏名称......)

camke文件如下:

  1.  
    cmake_minimum_required( VERSION 2.8)
  2.  
    PROJECT ( hello)
  3.  
    SET( SRC_LIST main.c)
  4.  
    MESSAGE( STATUS "This is BINARY dir " ${HELLO_BINARY_DIR})
  5.  
    MESSAGE( STATUS "This is SOURCE dir " ${HELLO_SOURCE_DIR})
  6.  
    add_definitions( -Dhha -Dbbb)
  7.  
    ADD_EXECUTABLE( hello ${SRC_LIST})

源代码如下:

  1.  
    #include<stdio.h>
  2.  
    int main()
  3.  
    {
  4.  
    #ifdef hha
  5.  
    printf("include hhahah.\n");
  6.  
    #endif
  7.  
    #ifdef bbb
  8.  
    printf("include bbbbbb.\n");
  9.  
    #endif
  10.  
    printf("hello,word.\n");
  11.  
    return 0;
  12.  
    }

输出结果:


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM