cmake request

Discussion in 'Feature Requests' started by Frank Mathis, Aug 3, 2016.

  1. Are there any plans to add cmake support (especially for Linux) ?
    This would greatly help with attempting to develop against the api for larger projects.
     
  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    CMake is convenient for projects where you are compiling lots source files, linking them and installing the resulting libraries or executables. MuJoCo is a precompiled library. The minimal makefile in the sample directory shows how to compile your code and link with MuJoCo. Using CMake for this will only introduce unnecessary complications. If you want to include MuJoCo in a large project that can benefit from CMake, you will have to write the CMake file corresponding to your project, and the MuJoCo part will be a small fraction of it -- so it is not clear how a MuJoCo-specific CMake file will help.

    So the answer is no, there is no official support planned. But if someone ends up doing this and posts an example on the forum that can be helpful to other users.
     
  3. Just in case it will be useful for someone else. Here is a template/example on how to use mujoco with cmake.
    For the template to work one must assign MUJOCO_PY_MJPRO_PATH environmental variable. I used this name because this variable is required for mujoco-py.
    Also uncomment/comment libraries which you would like to link depending on your project.


    cmake_minimum_required(VERSION 3.2)
    set(CMAKE_CXX_STANDARD 11)

    project(myproject)

    #Options
    set(SRCS main.cpp)
    set(USE_GL 1) #USE_GL==0 does not work for 131 version since there is no 'nogl' file
    set(BIN_NAME ${PROJECT_NAME}_exe)

    #Paths
    include_directories($ENV{MUJOCO_PY_MJPRO_PATH}/include)
    link_directories($ENV{MUJOCO_PY_MJPRO_PATH}/bin)

    #Showing path to MuJoCo for checking
    message(STATUS "MuJoCo path: " $ENV{MUJOCO_PY_MJPRO_PATH})

    #Finding main mujoco library
    if(${USE_GL})
    file(GLOB LIB_MUJOCO $ENV{MUJOCO_PY_MJPRO_PATH}/bin/libmujoco[0-9][0-9][0-9].so)
    else()
    file(GLOB LIB_MUJOCO $ENV{MUJOCO_PY_MJPRO_PATH}/bin/libmujoco[0-9][0-9][0-9]nogl.so)
    endif()
    #Showing mujoco library found
    message(STATUS "MuJoCo lib: " ${LIB_MUJOCO})

    add_executable(${BIN_NAME} ${SRCS})
    target_link_libraries(${BIN_NAME} ${LIB_MUJOCO})

    #Standard libraries for GL
    target_link_libraries(${PROJECT_NAME}_exe GL GLU glut )

    #Additional libraries from mujoco package
    target_link_libraries(${PROJECT_NAME}_exe libglew.so )
    target_link_libraries(${PROJECT_NAME}_exe libglfw.so )
    #target_link_libraries(${PROJECT_NAME}_exe libglewegl.so )
    #target_link_libraries(${PROJECT_NAME}_exe libglewosmesa.so)