[Gmsh] Link C++ code to gmsh

Christophe Geuzaine cgeuzaine at ulg.ac.be
Wed Nov 30 21:03:50 CET 2011


On 18 Nov 2011, at 20:43, Martin Vymazal wrote:

> Dear gmsh users and developers,
> 
> I'd like to write a little c++ driver that calls gmsh for (re-)meshing of some simple geometries. I have gmsh installed in /opt/gmsh and I wrote this cmake file:
> 
> cmake_minimum_required(VERSION 2.8)
> project(gmshdriver C CXX)
> 
> set(GMSH_ROOT /opt/gmsh)
> if ( DEFINED GMSH_ROOT)
>  find_path( GMSH_INCLUDE_DIR Gmsh.h PATHS ${GMSH_ROOT}/include/gmsh NO_DEFAULT_PATH )
> endif()
> 
> find_path( GMSH_INCLUDE_DIR Gmsh.h )
> include_directories( ${GMSH_INCLUDE_DIR} )
> 
> find_library( GMSH_LIB NAMES Gmsh PATHS ${GMSH_ROOT}/lib )
> 
> add_executable(test src/main.cpp)
> target_link_libraries( test ${GMSH_LIB} )
> 
> I'm a wondering if this is sufficient in case I call gmsh functions which require third-party functionality (petsc, OpenCascade etc). I expect to run into linking problems.
> 
> One solution would be to modify the CMakeLists.txt of gmsh and add a subdirectory with my sources. Then I'll have access to cmake variables like ${EXTERNAL_LIBRARIES} and ${EXTERNAL_INCLUDES}.
> 
> Can you tell me what's the best way to do this? Any comments, suggestions or sample CMake files are welcome. Thank you very much.
> 

Hi Martin - No need to modify Gmsh's CMakeList.txt file: just include Gmsh as a subproject of your own project. See e.g. the examples in gmsh/utils/api_demos.

Hope this helps,

Christophe

> Best regards,
> 
>   Martin Vymazal
> 
> 
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
> 
> 
> 
> _______________________________________________
> gmsh mailing list
> gmsh at geuz.org
> http://www.geuz.org/mailman/listinfo/gmsh

-- 
Prof. Christophe Geuzaine
University of Liege, Electrical Engineering and Computer Science 
http://www.montefiore.ulg.ac.be/~geuzaine