linux(ubuntu) configuration openmesh--cmakelits

Summary

Since I am not very familiar with cmakelists, on the other hand, openmesh's cmakelists configuration results are really different from other libraries, and there are no good tutorials on the web, which took me a long time to match.
Play the result directly:

Openmesh-CMakelists

# openmesh
list (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_module)
find_package( OpenMesh REQUIRED)
include_directories( ${OpenMesh_INCLUDE_DIRS} )

# After add_executable
target_link_libraries( t ${OpenMesh_LIBS} OpenMeshCore OpenMeshTools) 

The key is how / cmake_module finds it; I actually changed the directory name, cmake_module used to be cmake
We'll look for it now (I didn't delete openmesh after sudo make install, and if you do, I don't know what I can do about it at this time):

$ locate FindOpenMesh.cmake
/home/ai/Downloads/OpenMesh-6.3/cmake/FindOpenMesh.cmake
$ cd /home/ai/Downloads/OpenMesh-6.3/cmake
$ ls
ACGCommon.cmake    FindGLEW.cmake        FindOpenMP.cmake
ACGCompiler.cmake  FindGLUT.cmake        fixbundle.cmake.in
ACGDoxygen.cmake   FindGoogleTest.cmake  fixbundle.cmake.win.in
ACGOutput.cmake    FindOpenMesh.cmake    OpenMeshPackage.cmake

You can see what we want, so put this cmake folder under the same folder as main.cpp and rename it to cmake_module.

Test:

#include <iostream>
// -------------------- OpenMesh  
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>
// ----------------------------------------------------------------------------  
typedef OpenMesh::PolyMesh_ArrayKernelT<>  MyMesh;
// ----------------------------------------------------------------------------  
// Build a simple cube and write it to std::cout  

int main()
{
    MyMesh mesh;
    // generate vertices  
    MyMesh::VertexHandle vhandle[8];
    vhandle[0] = mesh.add_vertex(MyMesh::Point(-1, -1,  1));
    vhandle[1] = mesh.add_vertex(MyMesh::Point( 1, -1,  1));
    vhandle[2] = mesh.add_vertex(MyMesh::Point( 1,  1,  1));
    vhandle[3] = mesh.add_vertex(MyMesh::Point(-1,  1,  1));
    vhandle[4] = mesh.add_vertex(MyMesh::Point(-1, -1, -1));
    vhandle[5] = mesh.add_vertex(MyMesh::Point( 1, -1, -1));
    vhandle[6] = mesh.add_vertex(MyMesh::Point( 1,  1, -1));
    vhandle[7] = mesh.add_vertex(MyMesh::Point(-1,  1, -1));
    // generate (quadrilateral) faces  
    std::vector<MyMesh::VertexHandle>  face_vhandles;
    face_vhandles.clear();
    face_vhandles.push_back(vhandle[0]);
    face_vhandles.push_back(vhandle[1]);
    face_vhandles.push_back(vhandle[2]);
    face_vhandles.push_back(vhandle[3]);
    mesh.add_face(face_vhandles);

    face_vhandles.clear();
    face_vhandles.push_back(vhandle[7]);
    face_vhandles.push_back(vhandle[6]);
    face_vhandles.push_back(vhandle[5]);
    face_vhandles.push_back(vhandle[4]);
    mesh.add_face(face_vhandles);
    face_vhandles.clear();
    face_vhandles.push_back(vhandle[1]);
    face_vhandles.push_back(vhandle[0]);
    face_vhandles.push_back(vhandle[4]);
    face_vhandles.push_back(vhandle[5]);
    mesh.add_face(face_vhandles);
    face_vhandles.clear();
    face_vhandles.push_back(vhandle[2]);
    face_vhandles.push_back(vhandle[1]);
    face_vhandles.push_back(vhandle[5]);
    face_vhandles.push_back(vhandle[6]);
    mesh.add_face(face_vhandles);
    face_vhandles.clear();
    face_vhandles.push_back(vhandle[3]);
    face_vhandles.push_back(vhandle[2]);
    face_vhandles.push_back(vhandle[6]);
    face_vhandles.push_back(vhandle[7]);
    mesh.add_face(face_vhandles);
    face_vhandles.clear();
    face_vhandles.push_back(vhandle[0]);
    face_vhandles.push_back(vhandle[3]);
    face_vhandles.push_back(vhandle[7]);
    face_vhandles.push_back(vhandle[4]);
    mesh.add_face(face_vhandles);
    OpenMesh::IO::write_mesh(mesh, "output.off");
    // write mesh to output.obj  
    try
    {
        if ( !OpenMesh::IO::write_mesh(mesh, "output.off") )
        {
            std::cerr << "Cannot write mesh to file 'output.off'" << std::endl;
            return 1;
        }
    }
    catch( std::exception& x )
    {
        std::cerr << x.what() << std::endl;
        return 1;
    }
    std::cout << "nice"<<std::endl;
    return 0;
}  

I use clion, so the output.off file is not in the same folder as main.cpp, but under <projectname>/cmake-build-debug:

You can see output.off, which is a square placed in openmesh, and that's it

Reference resources:

cmake cannot find package
OpenMesh Learning Notes 1 Installation Configuration and Getting Started Example
Make Writing for Common Libraries in SLAM (How to Add Dependent Libraries)

Keywords: cmake sudo

Added by jjjamie on Thu, 27 Feb 2020 18:43:48 +0200