config libigl in qt through cmake under ubuntu

1. download libigl

open terminal, turn to the directory where you want libigl download, then type:

  1. git clone --recursive https://github.com/libigl/libigl.git  
2. open qtcreator, File->Open File or Project..., choose the CMakeList.txt in tutorial directory. 


3. After that, we get into CMake Wizard step, click Run CMake


then click Finsh

4. some stuff about CMakeList.txt

here I would like go into the CMakeList.txt file. If you just want to build this project as soon as possible, you just skip over this step.

Note: the comments marked in red are written by me.


cmake_minimum_required(VERSION 2.8.12)
#project name
project(libigl_tutorials)

#some options, just skip over

### libIGL options: choose between header only and compiled static library
option(LIBIGL_USE_STATIC_LIBRARY "Use LibIGL as static library" ON)
option(LIBIGL_WITH_VIEWER      "Use OpenGL viewer"  ON)
option(LIBIGL_WITH_NANOGUI     "Use Nanogui menu"   OFF)

### libIGL options: choose your dependencies (by default everything is OFF, in this example we need the viewer) ###
option(LIBIGL_WITH_BBW              "Use BBW"            ON)
#try to find CGAL
find_package(CGAL QUIET)
option(LIBIGL_WITH_CGAL             "Use CGAL"           "${CGAL_FOUND}")
option(LIBIGL_WITH_COMISO           "Use CoMiso"         ON)
option(LIBIGL_WITH_CORK             "Use CORK"           OFF)
option(LIBIGL_WITH_EMBREE           "Use Embree"         ON)
option(LIBIGL_WITH_LIM              "Use LIM"            ON)
find_package(MATLAB QUIET)
option(LIBIGL_WITH_MATLAB           "Use Matlab"         "${MATLAB_FOUND}")
option(LIBIGL_WITH_MOSEK            "Use MOSEK"          "${MOSEK_FOUND}")
option(LIBIGL_WITH_OPENGL           "Use OpenGL"         ON)
option(LIBIGL_WITH_PNG              "Use PNG"            ON)
option(LIBIGL_WITH_TETGEN           "Use Tetgen"         ON)
option(LIBIGL_WITH_TRIANGLE         "Use Triangle"       ON)
option(LIBIGL_WITH_XML              "Use XML"            ON)
### End   to be tested ----

### libIGL options: decide if you want to use the functionalities that depends on cgal
if(LIBIGL_WITH_CGAL) # Do not remove or move this block, cgal strange build system fails without it
  find_package(CGAL REQUIRED)
  set(CGAL_DONT_OVERRIDE_CMAKE_FLAGS TRUE CACHE BOOL "CGAL's CMAKE Setup is super annoying ")
  include(${CGAL_USE_FILE})
endif()

### Adding libIGL: choose the path to your local copy libIGL ###
### This is going to compile everything you requested ###
#this sentence is quite important, that subdirectory also has a CMakeList.txt which will set environments like ${LIBIGL_INCLUDE_DIRS}
add_subdirectory("${PROJECT_SOURCE_DIR}/../shared/cmake" "libigl")


### Output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")

### Compilation flags: adapt to your needs ###
if(MSVC)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /bigobj") ### Enable parallel compilation
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR} )
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR} )
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /w") # disable all warnings (not ideal but...)
else()
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") #### Libigl requires a modern C++ compiler that supports c++11
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "../" )
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w") # disable all warnings (not ideal but...)
endif()

# Enable openMP if possible
#find_package(OpenMP)
#if (OPENMP_FOUND AND NOT WIN32)
#  set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
#  set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
#endif()


### Prepare the build environment
#set including path

include_directories(${LIBIGL_INCLUDE_DIRS})
MESSAGE( STATUS "LIBIGL_INCLUDE_DIRS:         " ${LIBIGL_INCLUDE_DIRS} )


add_definitions(${LIBIGL_DEFINITIONS})
### Choose which chapters to compile ###

#here you can off ones you don't want to compile
option(TUTORIALS_CHAPTER1 "Compile chapter 1" ON)
option(TUTORIALS_CHAPTER2 "Compile chapter 2" ON)
option(TUTORIALS_CHAPTER3 "Compile chapter 3" ON)
option(TUTORIALS_CHAPTER4 "Compile chapter 4" ON)
option(TUTORIALS_CHAPTER5 "Compile chapter 5" ON)
option(TUTORIALS_CHAPTER6 "Compile chapter 6" ON)
option(TUTORIALS_CHAPTER7 "Compile chapter 7" ON)

# Store location of tutorial/shared directory
set(TUTORIAL_SHARED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/shared CACHE PATH "location of shared tutorial resources")
add_definitions("-DTUTORIAL_SHARED_PATH=\"${TUTORIAL_SHARED_PATH}\"")

include_directories(${CMAKE_CURRENT_SOURCE_DIR})

# Chapter 1
if(TUTORIALS_CHAPTER1)
  add_subdirectory("101_FileIO")
  add_subdirectory("102_DrawMesh")
  add_subdirectory("103_Events")
  add_subdirectory("104_Colors")
  add_subdirectory("105_Overlays")
  add_subdirectory("106_ViewerMenu")
endif()

# Chapter 2
if(TUTORIALS_CHAPTER2)
  add_subdirectory("201_Normals")
  add_subdirectory("202_GaussianCurvature")
  add_subdirectory("203_CurvatureDirections")
  add_subdirectory("204_Gradient")
  add_subdirectory("205_Laplacian")
endif()

# Chapter 3
if(TUTORIALS_CHAPTER3)
  add_subdirectory("301_Slice")
  add_subdirectory("302_Sort")
  add_subdirectory("303_LaplaceEquation")
  add_subdirectory("304_LinearEqualityConstraints")
  add_subdirectory("305_QuadraticProgramming")
  add_subdirectory("306_EigenDecomposition")
endif()

# Chapter 4
if(TUTORIALS_CHAPTER4)
  add_subdirectory("401_BiharmonicDeformation")
  add_subdirectory("402_PolyharmonicDeformation")
  if(LIBIGL_WITH_BBW)
    add_subdirectory("403_BoundedBiharmonicWeights")
  endif()
  add_subdirectory("404_DualQuaternionSkinning")
  add_subdirectory("405_AsRigidAsPossible")
  add_subdirectory("406_FastAutomaticSkinningTransformations")
  add_subdirectory("407_BiharmonicCoordinates")
endif()

# Chapter 5
if(TUTORIALS_CHAPTER5)
  add_subdirectory("501_HarmonicParam")
  add_subdirectory("502_LSCMParam")
  add_subdirectory("503_ARAPParam")
  if(LIBIGL_WITH_COMISO)
    add_subdirectory("504_NRosyDesign")
    add_subdirectory("505_MIQ")
    add_subdirectory("506_FrameField")
  endif()
  add_subdirectory("507_PolyVectorField")
  add_subdirectory("508_ConjugateField")
  add_subdirectory("509_Planarization")
  add_subdirectory("510_Integrable")
endif()

# Chapter 6
if(TUTORIALS_CHAPTER6)
  if(LIBIGL_WITH_XML)
    add_subdirectory("601_Serialization")
  endif()
  if(LIBIGL_WITH_MATLAB)
    add_subdirectory("602_Matlab")
  endif()
  if(LIBIGL_WITH_TRIANGLE)
    add_subdirectory("604_Triangle")
  endif()
  if(LIBIGL_WITH_TETGEN)
    add_subdirectory("605_Tetgen")
  endif()
  if(LIBIGL_WITH_EMBREE)
    add_subdirectory("606_AmbientOcclusion")
    add_subdirectory("607_Picking")
    add_subdirectory("706_FacetOrientation")
  endif()
  if(LIBIGL_WITH_LIM)
    add_subdirectory("608_LIM")
  endif()
  if(LIBIGL_WITH_CGAL)
    add_subdirectory("609_Boolean")
    add_subdirectory("610_CSGTree")
  endif()
endif()

# Chapter 7
if(TUTORIALS_CHAPTER7)
  add_subdirectory("701_Statistics")
  add_subdirectory("702_WindingNumber")
  add_subdirectory("703_Decimation")
  add_subdirectory("704_SignedDistance")
  add_subdirectory("705_MarchingCubes")
endif()


5. up to now, there should be a 'Makefile' file in /home/tjiang/Workspace/libigl/build-tutorial-5_5_1-Default. This file will guide the compiler how to generate execute file.


6.after all this set, we can build the project



### 如何在Ubuntu上使用CMake打包Qt项目 #### 准备工作 为了成功地使用CMake来打包Qt项目,在Ubuntu环境中需先确认已正确安装了必要的工具和库。这包括但不限于Qt开发环境以及CMake本身[^3]。 #### 创建CMakeLists.txt文件 在一个典型的Qt项目结构中,`CMakeLists.txt` 文件是核心部分之一。该文件定义了项目的编译规则和其他设置。对于一个简单的Qt Widgets应用程序而言,此文件可能如下所示: ```cmake cmake_minimum_required(VERSION 3.5) project(MyProject VERSION 1.0 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED) add_executable(${PROJECT_NAME} main.cpp mainwindow.cpp mainwindow.h resources.qrc) target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Gui Qt5::Widgets) ``` 上述脚本指定了最低版本需求、项目名称及其使用的编程语言标准;接着查找并链接所需的Qt模块;最后指定源码位置及目标可执行文件名[^2]。 #### 配置资源文件 如果项目中有QRC格式的资源文件,则应在 `resources.qrc` 中声明这些资源的位置,并通过调用 `qt5_add_resources()` 或者更现代的方式将其加入到构建过程中。注意,随着新版本的发展,推荐的做法可能会有所变化,请参照官方文档获取最新指导。 #### 打包过程 完成以上步骤之后,可以通过命令行运行 `cpack` 来创建安装程序或分发包。在此之前,建议调整CPACK相关变量以适应特定的需求,比如设定软件包的名字、描述等信息: ```cmake include(CPack) set(CPACK_PACKAGE_VERSION_MAJOR "1") set(CPACK_PACKAGE_VERSION_MINOR "0") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "My Project Description.") ... ``` 这样做的好处是可以自动生成适用于不同平台(如Debian/RedHat风格Linux发行版)的二进制包,简化部署流程[^4]。 #### 构建与测试 确保一切配置无误后,可以利用以下指令来进行实际操作: - 清理旧有产物:`make clean` - 编译工程:`cmake . && make` - 运行应用验证功能正常与否 - 使用 `cpack` 命令生成最终的产品包
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值