- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在构建一个中型 C++ 库,而我的 CMakeLists.txt
文件开始变得有点长。我正在阅读 Robert Martin 的书 The Clean Coder,他在书中讨论了为了代码维护和可读性而采用干净编码风格的元素。
所以我想看看我是否可以将我的 CMakeLists.txt 文件分解成一组较小的文件——当我运行构建命令时它们会集成。然后我可以只管理这些较小的文件,就像我将类分解成单独的文件一样。现在作为警告,我不会为库的不同元素构建单独的可执行文件。我只是在构建一个库,其中包含我在其他项目中需要的一组类和函数。
这是我当前的 CMakeLists.txt 文件。然后我会展示我想如何分解它。
cmake_minimum_required(VERSION 3.7)
project(tvastrCpp)
set (tvastrCpp_VERSION_MAJOR 0)
set (tvastrCpp_VERSION_MINOR 1)
# Find CGAL
find_package(CGAL REQUIRED COMPONENTS Core) # If the dependency is required, use REQUIRED option - if it's not found CMake will issue an error
include( ${CGAL_USE_FILE} )
include(ExternalProject)
set(CMAKE_CXX_STANDARD 14)
find_package(Eigen3 3.1.0)
if (EIGEN3_FOUND)
include( ${EIGEN3_USE_FILE} )
endif()
find_package(Boost 1.58.0 REQUIRED COMPONENTS system filesystem program_options chrono timer date_time REQUIRED)
if(NOT Boost_FOUND)
message(FATAL_ERROR "NOTICE: This demo requires Boost and will not be compiled.")
endif()
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
ExternalProject_Add(
catch
PREFIX ${CMAKE_BINARY_DIR}/catch
GIT_REPOSITORY https://github.com/philsquared/Catch.git
TIMEOUT 10
UPDATE_COMMAND ${GIT_EXECUTABLE} pull
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
LOG_DOWNLOAD ON
)
ExternalProject_Get_Property(catch source_dir)
set(CATCH_INCLUDE_DIR ${source_dir}/single_include CACHE INTERNAL "Path to include folder for Catch")
INCLUDE_DIRECTORIES ( "${EIGEN3_INCLUDE_DIR}" )
file(GLOB lib_SRC RELATIVE "lib" "*.h" "*.cpp")
file(GLOB test_SRC RELATIVE "tests" "*.h" "*.cpp")
# need to fix the instruction below to reference library
set(SOURCE_FILES ${lib_SRC})
add_library(tvastrCpp SHARED ${SOURCE_FILES})
add_executable(${PROJECT_NAME} main.cpp random_mat_vector_generator.h random_mat_vector_generator.cpp)
add_executable(my_tests testcases.cpp RipsComplex.h RipsComplex.cpp random_mat_vector_generator.h random_mat_vector_generator.cpp)
add_executable(gd_validator gudhi_validator.cpp)
TARGET_LINK_LIBRARIES( gd_validator ${Boost_LIBRARIES} )
enable_testing(true)
add_test(NAME cooltests COMMAND my_tests)
现在我想为基本设置部分创建一个单独的文件:
settings.txt:
cmake_minimum_required(VERSION 3.7)
project(tvastrCpp)
set (tvastrCpp_VERSION_MAJOR 0)
set (tvastrCpp_VERSION_MINOR 1)
然后是寻找 CGAL 库的单独部分:
find_cgal.txt:
find_package(CGAL REQUIRED COMPONENTS Core) # If the dependency is required, use REQUIRED option - if it's not found CMake will issue an error
include( ${CGAL_USE_FILE} )
include(ExternalProject)
set(CMAKE_CXX_STANDARD 14)
find_package(Eigen3 3.1.0)
if (EIGEN3_FOUND)
include( ${EIGEN3_USE_FILE} )
endif()
等等。
最佳答案
将您的 CMakeLists.txt 拆分为:
项目的顶级文件:
可重用函数文件:
源文件:
测试:
我有一个包含一个 CMakeLists.txt 的小项目和一个包含最多 10 个文件的库的大型项目。
关于c++ - 我可以从一组较小的文件构建 CMakeLists.txt 吗(以提高 CMakeLists.txt 的可读性和可维护性),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43442129/
我正在开发一个 RSS 阅读器应用程序,我想为我的用户提供一致的文章体验(即新的 Safari 阅读器)。是否有适用于此的 API?我知道可读性,但我不确定这是否是我所需要的。 最佳答案 刚刚正在为我
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 5 年前。 Improve
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Should a function have only one return statement? 我的老师
我是编程和入门CS50在线类(class)的新手。 在第2讲中,David介绍了CS50 IDE,我现在第一次将其用于问题集2-可读性。但是,当我尝试运行一个简单的“hello,world”程序时,遇
我是java编程新手。我只想要该页面的网页内容。但我得到的程序给了我 html 标签,其中包含我不想要的内容。 谁能帮我解决这个问题吗? 谢谢。 我的代码如下所示: import java.net.*
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 9 年前。 Improve
这个问题是关于 URL 命名中的 SEO,我只想知道 SEO 真的比用户体验更重要吗?你们会认为 SEO 应该走多远的限制会破坏人们的体验。就像这个例子一样,我有一个页面包含有关正在或已经在我的网站上
为了提高创建和销毁对象时的性能,可以使用池化。 在某些情况下,我不想深入研究自定义分配器或 char[] 等低级技术。 另一种方法是创建对象池。 但是,这种技术不适用于类内字段(内联)初始化。 起初,
我想知道是否有一种方法可以修改JS中对象的现有属性,以便我们可以使它们在赋值后不可变。 基本上,我有一个对象,我想卡住该对象的现有属性,但允许添加新属性。 是否可以卡住现有属性,或者我是否需要像这样使
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
在我的 ColdFusion 代码中,我养成了始终将变量作用域视为默认作用域的习惯(即,当另一个作用域不适合时)。我的理解是,这提高了效率,因为 ColdFusion 处理器不必花费周期来确定变量所包
所以我编写了这些测试,看看使用原型(prototype)会快多少...... function User() { return { name: "Dave",
我正在开发一个 asp.net 内容管理系统,我们需要 Flesch-Kincaid grade level用户可用的统计信息。我已经做了很多搜索,但我还没有找到任何可行的方法来实现它。我最接近的是
您好,我正在尝试实现 Readability API在我的应用程序中,但我得到的只是状态代码 500 - “未知问题”。我的响应正文是一个 html 页面,上面写着“页面不可用”。 我正在使用 Res
我编写了这段 PHP 代码来将 Flesch-Kincaid 可读性分数实现为一个函数: function readability($text) { $total_sentences = 1;
即使我认为这可能只是个人品味的问题,我想知道您更喜欢(以及为什么)在选择列表中使用逗号。 一开始: select first_name ,last_name ,address
我希望得到一些关于如何编写更美观的 javascript 和 jQuery 代码并获得更多可读性的建议。 在这种情况下,我希望在列表元素中插入表格。列表和表格都是通过脚本动态添加的。 我有一些这样的代
我已经以这种方式解析了以下 RSS ( http://timesofindia.indiatimes.com/rss.cms )- 我的代码- News Parser
我是一名优秀的程序员,十分优秀!