CMake官方教程7--加入系统反射

1. 加入系统反射

  • CMakeList.txt
cmake_minimum_required(VERSION 3.15)# set the project name and version
project(Tutorial VERSION 1.0)# specify the C++ standard
add_library(tutorial_compiler_flags INTERFACE)
target_compile_features(tutorial_compiler_flags INTERFACE cxx_std_11)# add compiler warning flags just when building this project via
# the BUILD_INTERFACE genex
set(gcc_like_cxx "$<COMPILE_LANG_AND_ID:CXX,ARMClang,AppleClang,Clang,GNU,LCC>")
set(msvc_cxx "$<COMPILE_LANG_AND_ID:CXX,MSVC>")
target_compile_options(tutorial_compiler_flags INTERFACE"$<${gcc_like_cxx}:$<BUILD_INTERFACE:-Wall;-Wextra;-Wshadow;-Wformat=2;-Wunused>>""$<${msvc_cxx}:$<BUILD_INTERFACE:-W3>>"
)# configure a header file to pass some of the CMake settings
# to the source code
configure_file(TutorialConfig.h.in TutorialConfig.h)# add the MathFunctions library
add_subdirectory(MathFunctions)# add the executable
add_executable(Tutorial tutorial.cxx)target_link_libraries(Tutorial PUBLIC MathFunctions tutorial_compiler_flags)# add the binary tree to the search path for include files
# so that we will find TutorialConfig.h
target_include_directories(Tutorial PUBLIC"${PROJECT_BINARY_DIR}")# add the install targets
install(TARGETS Tutorial DESTINATION bin)
install(FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"DESTINATION include)# enable testing
include(CTest)# does the application run
add_test(NAME Runs COMMAND Tutorial 25)# does the usage message work?
add_test(NAME Usage COMMAND Tutorial)
set_tests_properties(UsagePROPERTIES PASS_REGULAR_EXPRESSION "Usage:.*number")# define a function to simplify adding tests
function(do_test target arg result)add_test(NAME Comp${arg} COMMAND ${target} ${arg})set_tests_properties(Comp${arg}PROPERTIES PASS_REGULAR_EXPRESSION ${result})
endfunction()
target_include_directories(Tutorial PUBLIC"${PROJECT_BINARY_DIR}")# add the install targets
install(TARGETS Tutorial DESTINATION bin)
install(FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"DESTINATION include)# enable testing
include(CTest)# does the application run
add_test(NAME Runs COMMAND Tutorial 25)# does the usage message work?
add_test(NAME Usage COMMAND Tutorial)
set_tests_properties(UsagePROPERTIES PASS_REGULAR_EXPRESSION "Usage:.*number")# define a function to simplify adding tests
function(do_test target arg result)add_test(NAME Comp${arg} COMMAND ${target} ${arg})set_tests_properties(Comp${arg}PROPERTIES PASS_REGULAR_EXPRESSION ${result})
endfunction()
  • MathFunctions/CMakeLists.txt
add_library(MathFunctions MathFunctions.cxx)# state that anybody linking to us needs to include the current source dir
# to find MathFunctions.h, while we don't.
target_include_directories(MathFunctionsINTERFACE ${CMAKE_CURRENT_SOURCE_DIR})# should we use our own math functions
option(USE_MYMATH "Use tutorial provided math implementation" ON)
if (USE_MYMATH)target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")# library that just does sqrtadd_library(SqrtLibrary STATICmysqrt.cxx)# link SqrtLibrary to tutorial_compiler_flagstarget_link_libraries(SqrtLibrary PUBLIC tutorial_compiler_flags)# TODO 1: Include CheckCXXSourceCompilesinclude(CheckCXXSourceCompiles)# TODO 2: Use check_cxx_source_compiles with simple C++ code to verify# availability of:# * std::log# * std::exp# Store the results in HAVE_LOG and HAVE_EXP respectively.# Hint: Sample C++ code which uses log:# #include <cmath># int main() {#   std::log(1.0);#   return 0;# }check_cxx_source_compiles("#include <cmath>int main() {std::log(1.0);return 0;}" HAVE_LOG)check_cxx_source_compiles("#include <cmath>int main() {std::exp(1.0);return 0;}" HAVE_EXP)# TODO 3: Conditionally on HAVE_LOG and HAVE_EXP, add private compile# definitions "HAVE_LOG" and "HAVE_EXP" to the SqrtLibrary target.# Hint: Use target_compile_definitions()if ( HAVE_LOG AND HAVE_EXP )target_compile_definitions(SqrtLibrary PRIVATE "HAVE_LOG" "HAVE_EXP")else()if ( NOT HAVE_LOG )message( WARNING "DONT HAVE LOG FUNC")endif()if ( NOT HAVE_EXP )message( WARNING "DONT HAVE EXP FUNC")endif()endif()target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
endif()# link MathFunctions to tutorial_compiler_flags
target_link_libraries(MathFunctions PUBLIC tutorial_compiler_flags)# install libs
set(installable_libs MathFunctions tutorial_compiler_flags)
if(TARGET SqrtLibrary)list(APPEND installable_libs SqrtLibrary)
endif()
install(TARGETS ${installable_libs} DESTINATION lib)
# install include headers
install(FILES MathFunctions.h DESTINATION include)

2. 测试代码可行性

check_cxx_source_compiles("#include <cmath>int main() {std::exp(1.0);return 0;}" HAVE_EXP)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/748671.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

yolov8 分割 模型 网络 模块图

下图是使用yolov8n-seg-p6.yaml imgsz1472 类别数2的情况下训练得到的静态导出的onnx文件使用netron工具可视化的结果 简单标注了yolov8n-seg-p6.yaml配置文件中各层和netron工具可视化的结果的对应关系

图解缓存淘汰算法 LRU、LFU | 最近最少使用、最不经常使用算法 | go语言实现

写在前面 无论是什么系统&#xff0c;在研发的过程中不可避免的会使用到缓存&#xff0c;而缓存一般来说我们不会永久存储&#xff0c;但是缓存的内容是有限的&#xff0c;那么我们如何在有限的内存空间中&#xff0c;尽可能的保留有效的缓存信息呢&#xff1f; 那么我们就可以…

前端基础——HTML傻瓜式入门(2)

该文章Github地址&#xff1a;https://github.com/AntonyCheng/html-notes 在此介绍一下作者开源的SpringBoot项目初始化模板&#xff08;Github仓库地址&#xff1a;https://github.com/AntonyCheng/spring-boot-init-template & CSDN文章地址&#xff1a;https://blog.c…

C/C++程序设计实验报告3 | 数组实验

本文整理自博主本科大一《C/C程序设计》专业课的课内实验报告&#xff0c;适合C语言初学者们学习、练习。 编译器&#xff1a;gcc 10.3.0 ---- 注&#xff1a; 1.虽然课程名为C程序设计&#xff0c;但实际上当时校内该课的内容大部分其实都是C语言&#xff0c;C的元素最多可能只…

stm32学习——串口通信中的奇偶校验位

常用的校验算法有奇偶校验、校验和、CRC&#xff0c;还有LRC、BCC等不常用的校验算法。 以串口通讯中的奇校验为例&#xff0c;如果数据中1的个数为奇数&#xff0c;则奇校验位0&#xff0c;否则为1。 例如原始数据为&#xff1a;0001 0011&#xff0c;数据中1的个数&#xf…

HarmonyOS NEXT星河版——还是Android上套个壳吗?

这真的是我2024年听过最搞笑的话,就在前几天&#xff0c;居然还有人说鸿蒙OS就是安卓套个壳&#xff0c;简直无语&#xff01; 你敢相信&#xff1f;就在前几天&#xff0c;我还听到有人说&#xff1a;鸿蒙os就是安卓上套一个壳。唉&#xff0c;我真是无语了。 哎&#xff0c…

如何在Windows11上通过PHPStudy小皮面板快速大家MySQL环境

首先&#xff0c;下载小皮面板&#xff1a;https://www.xp.cn/ 点Windows版本&#xff1a; 开始下载&#xff1a; 或者直接从百度网盘下载&#xff1a; 链接&#xff1a;https://pan.baidu.com/s/1gcaiK54yW7DcrYld22V06A 提取码&#xff1a;4oj8 –来自百度网盘超级会员V9…

【力扣】141. 环形链表

题目描述 给你一个链表的头节点 head &#xff0c;判断链表中是否有环。 如果链表中有某个节点&#xff0c;可以通过连续跟踪 next 指针再次到达&#xff0c;则链表中存在环。 为了表示给定链表中的环&#xff0c;评测系统内部使用整数 pos 来表示链表尾连接到链表中的位置&a…

Docker配置Nginx、tomcat、elasticsearch

配置nginx 需要先pull下来 #启动nginx -d 表示后台运行 -p 表示暴露端口&#xff0c;将80暴露为3344 [rootiZf8zhsqf64x47n1tpdy6oZ home]# docker run -d -p:3344:80 nginx 5dd62cea7681975d37d1a9867bc9776de0206519f624b461346ac83025656642 [rootiZf8zhsqf64x47n1tpdy6oZ…

Unity类银河恶魔城学习记录10-4 p92 Death of entity源代码

Alex教程每一P的教程原代码加上我自己的理解初步理解写的注释&#xff0c;可供学习Alex教程的人参考 此代码仅为较上一P有所改变的代码 【Unity教程】从0编程制作类银河恶魔城游戏_哔哩哔哩_bilibili PlayerStat using System.Collections; using System.Collections.Generi…

Spark-Transformation以及Action开发实战

文章目录 创建RDDTransformation以及ActionTransformation开发Action开发RDD持久化共享变量创建RDD RDD是Spark的编程核心,在进行Spark编程是,首要任务就是创建一个初始的RDDSpark提供三种创建RDD方式:集合、本地文件、HDFS文件 集合:主要用于本地测试,在实际部署到集群运…

51-31 VastGaussian,3D高斯大型场景重建

2024 年 2 月&#xff0c;清华大学、华为和中科院联合发布的 VastGaussian 模型&#xff0c;实现了基于 3D Gaussian Splatting 进行大型场景高保真重建和实时渲染。 Abstract 现有基于NeRF大型场景重建方法&#xff0c;往往在视觉质量和渲染速度方面存在局限性。虽然最近 3D…

C++第五弹---类与对象(二)

✨个人主页&#xff1a; 熬夜学编程的小林 &#x1f497;系列专栏&#xff1a; 【C语言详解】 【数据结构详解】【C详解】 类与对象 1、类对象模型 1.1、如何计算类对象的大小 1.2、类对象的存储方式猜测 1.3、结构体内存对齐规则 2、this指针 2.1、this指针的引出 2.2…

Cesium 获取 3dtileset的包围盒各顶点坐标

Cesium 获取 3dtileset的包围盒各顶点坐标 /*** 获取 3dtileset的包围盒各顶点坐标, z 方向取高度最低的位置* param {*} tileset* param {*} options* returns* ref https://blog.csdn.net/STANDBYF/article/details/135012273* ref https://community.cesium.com/t/accurate-…

双指针算法_移动零_

题目&#xff1a; 给定一个数组 num &#xff0c;编写一个函数将数组内部的数字0都移动到数组的末尾&#xff0c;同时保持非零元素的相对顺序&#xff01; 同时不能通过复制数组&#xff0c;开辟新的数组空间的情况下原地对数组进行操作 示例&#xff1a; 本题的原理&#x…

【New Release】PostgreSQL小版本(16.2, 15.6, 14.11, 13.14,12.18) 发布了

前言 PostgreSQL遵循小版本的发布规律&#xff0c;这一个季度的小版本又发布了。可以算作是2024年第一个季度的版本发布。如果总结其规律&#xff1a;大概就是2月、5月、8月、11月的样子。通常因为11月配合大版本的发布&#xff0c;它是起点&#xff0c;也有可能就是终点。起点…

Docker 中 Nginx 反向代理

本文主角&#xff1a;Nginx Proxy Manager 。 使用docker安装Nginx Proxy Manager。 1、找到C:\Windows\System32\drivers\etc下的hosts文件&#xff0c;添加 “域名 IP"即可。 使用vscode编辑文件&#xff0c;保存时会提示用管理员权限保存即可。 2、Nginx Proxy Mana…

力扣大厂热门面试算法题 36-38

36. 有效的数独&#xff0c;37. 解数独&#xff0c;38. 外观数列&#xff0c;每题做详细思路梳理&#xff0c;配套Python&Java双语代码&#xff0c; 2024.03.16 可通过leetcode所有测试用例。 目录 36. 有效的数独 解题思路 完整代码 Java Python 37. 解数独 解题思…

leetcode 判断是否为平衡二叉树

这个记得第一次写还是大二用c语言&#xff0c;当时非递归写了好久也没写完&#xff0c;用python递归思路简单&#xff0c;就是难想了一点&#xff0c;人生苦短&#xff0c;我用python哈哈哈.... 输入一棵二叉树的根节点&#xff0c;判断该树是不是平衡二叉树。如果某二叉树中任…

nmcli --help(nmcli -h)nmcli文档、nmcli手册

文章目录 nmcli --helpOPTION解释OBJECT解释1. g[eneral]&#xff1a;查看NetworkManager的状态2. n[etworking]&#xff1a;启用或禁用网络3. r[adio]&#xff1a;查看无线电状态&#xff08;例如&#xff0c;Wi-Fi&#xff09;4. c[onnection]&#xff1a;列出所有的网络连接…