CMAKE语法:add_definitions、add_compile_options

前言:

  • CMAKE命令通用理解:
command(\<target> [E] <A|B|C>)   

尖括号<> 必选变量,<target>;
方括号[] 可选变量,[E];
竖线| 或的意思,A|B|C;

1、add_library(<name> [STATIC|SHARED|MODULE] source1 [source2 …])
作用: 生成库文件(动态库.so、静态库.a等)
用法:

add_library(so_name SHARED abc.cpp)    
aux_source_directory(. DIR_SRCS)  
add_library(abc STATIC ${DIR_SRCS})  

参考资料:
1、CMAKE:add_library

2、add_definitions、add_compile_definitions、target_compile_definitions用法:
作用:

  • add_definitions&add_compile_definitions: 为当前以下层路径的所有源文件和target增加编译定义
  • target_compile_definitions:为指定target增加编译定义

用法:

target_compile_definitions(<target> <INTERFACE|PUBLIC|PRIVATE> [items1])  

例:

add_definitions(-DFOO)  
add_compile_definitions(FOO) 
target_compile_definitions(target PUBLIC FOO) 

参考资料:
1、 add_definitions
2、add_compile_definitions
3、target_compile_definitions

3、add_compile_options()用法
作用: 设置编译器编译选项

3.1、CMAKE_CXX_FLAGS、CMAKE_C_FLAG

用法: 单独设置C++或C的编译选项,编译选项放在“”内,同时要将“${CMAKE_C_FLAGS}字段保留

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") 
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-Werror ")    

3.2、add_compile_options()
用法: 针对所有编译器设置编译选项

add_compile_options(-std=c++11)  

参考文件:
1、cmake:设置编译选项的讲究

4、message([<mode>] “message text” …)
作用: 写在cmkae/Cmakelist.txt文件中,执行时输出日志
用法:

用法解释
message(STATUS “message text”)状态信息
message(“message text”)一般通知
message(FATAL_ERROR “message text”)验证错误,停止编译
message(WARNING “message text”)警告,继续编译

5、execute_process
作用: 执行子进程
用法:

execute_process(COMMAND <cmd1> [args1...]] [WORKING_DIRECTORY <directory>])  

例:

execute_process(COMMAND python ${ABC_PATH}/test1.py WORKING_DIRECTORY ${AA_PATH}/ABC)  

命令解析:${AA_PATH}/ABC路径下执行test1.py脚本

参考资料:
1、CMAKE: execute_process

  • 5
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Visual studio 2012 下 sqlite3的工程文件,生成32或64位的sqlite3库 This page explains how to compile SQLite with Microsoft Visual Studio.NET (aka VS.NET). Download Download and unzip the file sqlite_source.zip (or sqlite-amalgamation-x_x_x_x.zip). Do not use the .tar.gz files because they have not been pre-processed for use with Windows. Create a starter DLL project File > New > Project. Under Project Types, select Visual C++ Projects and then Win32. Choose the project template "Win32 Project". Give the project a name and click OK. When the "Win32 Application Wizard" appears, choose Application Settings. set the Application Type to DLL and check the box that says "Empty project". Click Finish. You now have a blank DLL project. Add the SQLite files to the project Project > Add Existing Item. Add all the .c and .h files that you unzipped, except for: tclsqlite.c and shell.c. Note: You may add tclsqlite.c and shell.c, but then you have to define the preprocessor-symbol NO_TCL. Click Project -> Properties, navigate to the C/C++-folder and choose "Preprocessor". In the field that says "Preprocessor definitions" add NO_TCL to the existing string, separated by a semicolon. Under "Code Generation" for "Runtime Library" make sure to pick static linking. /MTd (release) or /MTd (debug) Make a .DEF file A .def file should be placed in the project directory. Get the def file by downloading the zipped sqlite DLL file under the "Precompiled Binaries For Windows" in the download page. Add the sqlite[3].def file to the project. Under Project > Properties navigate to the Linker folder and choose "Input". In the field that says "Module Definition File" type sqlite[3].def. NOTE: You have to do this twice, once for the Debug configuration and once for the Release configuration. Compile! The next 3 steps maybe be required by some. I was able to build the DLL and produce a .lib file only following the above 12 steps. for VS 2005. In order to build the lib file so that an application can link against the sqlite[3].dll you will need to add a step to the post-build event. Right click on Project, select Properties, expand Build Events and type "LIB /DEF:\sqlite[3].def" into the Command line field, both for debug and release configurations, where is the location to the file sqlite[3].def. To compile 3.3.7(this may apply to other versions too), I had to do this extra step: Add the project directory to the include path, here's how to do it in details: Under Project > Properties navigate to the C/C++ folder and choose "General", In the field "Additional Include Directories" type "."(a single dot, which is the current directory) Repeat for each configuration (debug/release/Win32/x64). To compile 3.6.14.1 (maybe others too), I also had to: Go to Project > Properties. Open the C/C++ then Preprocessor folder. Add "SQLITE_ENABLE_COLUMN_METADATA" to the list of preprocessor definitions. Repeat for each configuration (debug/release/Win32/x64). How to make the SQLITE.EXE command-line utility There are some slight changes if you wanted to build the sqlite.exe command-line utility, instead of the DLL. To do that, when you're creating the project and you get to the "Win32 Application Wizard", choose "Console Application" instead of "DLL". Then, when you are adding files to the project, also add shell.c. Finally, don't include the .DEF file. The sqllite def for version 2 is. EXPORTS sqlite_open sqlite_close sqlite_exec sqlite_last_insert_rowid sqlite_error_string sqlite_interrupt sqlite_complete sqlite_busy_handler sqlite_busy_timeout sqlite_get_table sqlite_free_table sqlite_mprintf sqlite_vmprintf sqlite_exec_printf sqlite_exec_vprintf sqlite_get_table_printf sqlite_get_table_vprintf sqlite_freemem sqlite_libversion sqlite_libencoding sqlite_changes sqlite_create_function sqlite_create_aggregate sqlite_function_type sqlite_user_data sqlite_aggregate_context sqlite_aggregate_count sqlite_set_result_string sqlite_set_result_int sqlite_set_result_double sqlite_set_result_error sqliteMalloc sqliteFree sqliteRealloc sqlite_set_authorizer sqlite_trace sqlite_compile sqlite_step sqlite_finalize sqlite_progress_handler sqlite_reset sqlite_last_statement_changes

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值