C++ Makefile/CMakeLists.txt

Discussion in 'Simulation' started by sc13cs, Oct 15, 2018.

  1. Hi,

    I have MuJoco installed on Ubuntu computer under ~/.mujoco/mujoco200. I would like to start writing a C++ program to control MuJoco.

    I would like to write a Makefile/CMakeLists.txt file to compile my program. I cannot find an example of how to do it. I tried to write the following CMakeLists.txt file:

    cmake_minimum_required(VERSION 2.8.3)
    project(mujoco_demo)

    add_compile_options(-std=c++11) # CMake 2.8.12 or newer

    if( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )
    add_definitions("-fno-strict-aliasing -Wall")
    endif( CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX )

    find_package(Boost ${OpenRAVE_Boost_VERSION} EXACT)
    find_package(ompl REQUIRED)
    find_package(Mujoco REQUIRED MODULE)

    include_directories(${Boost_INCLUDE_DIRS} ${OMPL_INCLUDE_DIRS} ${Eigen_INCLUDE_DIRS})
    link_directories(${Boost_LIBRARY_DIRS} ${OMPL_LIBRARY_DIRS})
    add_executable(mujoco_demo basic.cpp)
    target_link_libraries(mujoco ${OMPL_LIBRARIES} -lboost_system INTERFACE Mujoco::Mujoco)
    install(TARGETS mujoco DESTINATION .)

    But I get the following error:
    No "FindMujoco.cmake" found in CMAKE_MODULE_PATH.

    So I guess I am doing something wrong.

    In general, I copied from your website the basic.cpp file and I placed in an arbitrary location (say ~/Desktop). I would like to write Makefile or CMakeLists.txt file to compile the basic.cpp (i.e set the dependencies such that I can compile a MuJoco program correctly).

    Thanks in advance.
     
  2. I figure out that there is a Makefile available under the mjpro200 folder, however, I am still interested in a CMakeLists.txt file. Will be easy for someone to provide an intial starting point of having a CMakeLists.txt file for compiling MuJoCo C++ for the community?
     
  3. This might get you started

    Code:
    set(USE_GL 1) #USE_GL==0 does not work for 131 version since there is no 'nogl' file
    set(BIN_NAME ${PROJECT_NAME})
    
    link_directories(${CMAKE_SOURCE_DIR}/lib/200/)
    find_library(GLFW libglfw.so.3 HINTS lib/200/)
    message(STATUS "GLFW lib found at: " ${GLFW})
    
    #Showing path to MuJoCo for checking
    message(STATUS "MuJoCo path: " ${CMAKE_SOURCE_DIR}/lib/200/)
    
    #Finding main mujoco library
    if(${USE_GL})
    file(GLOB LIB_MUJOCO lib/200/libmujoco[0-9][0-9][0-9].so)
    else()
    file(GLOB LIB_MUJOCO lib/200/libmujoco[0-9][0-9][0-9]nogl.so)
    endif()
    #Showing mujoco library found
    message(STATUS "MuJoCo lib found at: " ${LIB_MUJOCO})
    
    
    target_link_libraries(${PROJECT_NAME}
      ${LIB_MUJOCO}
      ${GLFW}
      libGL.so
      libglew.so)
    
    
    I placed all the mujoco libs in a directory called lib/200

    Note: This is partially copied from a older forum thread I don't seem to be able to find anymore
     
    sc13cs likes this.