0

I'm using a CMakeLists.txt to build for my C++ file I want to include the external library MuJoCo but the MuJoCo repo has no mujoco-config.cmake, or mujocoConfig.cmake file.
Is there another way to include it?

There is a cmake folder in the repo, pictured below. It has a mujocoConfig.cmake.in file in it. I don't know how to use it. I don't know if it or anything else in this cmake folder is what I need.

enter image description here

This is the mujocoConfig.cmake.in file.

# Copyright 2021 DeepMind Technologies Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

@PACKAGE_INIT@

include(CMakeFindDependencyMacro)
find_dependency(OpenGL)

if(NOT TARGET mujoco AND NOT @PROJECT_NAME@_BINARY_DIR)
  include("${CMAKE_CURRENT_LIST_DIR}/mujocoTargets.cmake")
endif()

check_required_components(mujoco)

This is my CMakeLists.txt, which is giving me a mujocoConfig not found error.

cmake_minimum_required(VERSION 3.5.1)
project(mujoco_gym)

set(CMAKE_CXX_STANDARD 14)
# It prevents the decay to C++98 when the compiler does not support C++14
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# It disables the use of compiler-specific extensions
# e.g. -std=c++14 rather than -std=gnu++14
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")

set(Mujoco_DIR mujoco)
find_package(Mujoco PATHS ${Mujoco_DIR} NO_DEFAULT REQUIRED)
if (Mujoco_FOUND)
    message(STATUS "Mujoco library found!")
    message(STATUS "    include path: ${MUJOCO_INCLUDE_DIRS}" \n)
else ()
    message(FATAL_ERROR "Could not locate Mujoco" \n)
endif()

target_include_directories(
        ${CMAKE_CURRENT_SOURCE_DIR}
)

file(GLOB SOURCE_FILES mujoco_gym.cpp)

#CMAKE_PROJECT_NAME is from 'project(mujoco_gym)' on the second line of this script
add_executable(${CMAKE_PROJECT_NAME} ${SOURCE_FILES})

target_link_libraries (
        ${CMAKE_PROJECT_NAME}
        ${MUJOCO_LIBRARIES}
)

Progress Update:
Progress Update:
Progress Update:

I found the mujocoConfig.cmake in the build folder after I built the mujoco library from source. (I couldn't find mujocoConfig.cmake at first because I was looking for it on GitHub.

Now I am finding the mujocoConfig.cmake with my CMakelists.txt but this mujocoConfig.cmake is looking for mujocoTargets.cmake.
It's in /mujoco/build/CMakeFiles/Export/lib/cmake/mujoco but I don't know how to point to it in CMakeLists.txt.

It's looking in the build folder

CMake Error at /home/iii/tor/m_gym/mujoco/build/mujocoConfig.cmake:45 (include):
  include could not find requested file:

    /home/iii/tor/m_gym/mujoco/build/mujocoTargets.cmake
Call Stack (most recent call first):
  CMakeLists.txt:24 (find_package)
Ant
  • 933
  • 2
  • 17
  • 33
  • 2
    You probably have to build and install mujoco, not bundle it with your sources. – Stephen Newell Jul 26 '22 at 19:36
  • I would think that was the case, but I can compile my own C++ file that includes MuJoCo when I run the Makefile in this [repo](https://github.com/deepmind/mujoco) . It's in the repo's `sample` file. It's quite small and fast to build. The problem is that I want to do this with cmake if possible. – Ant Jul 26 '22 at 19:38
  • 1
    The Config.cmake file is generated upon installtion. You can install the project, using CMake, and then use `find_package`, or you can use `add_subdirectory` (if the library supports it) – KamilCuk Jul 26 '22 at 19:56
  • Oh. I see it now in the build dir where I built it from source. Thank you. I was doing a search on GitHub for it. Thank you. I wonder if I should delete the question. – Ant Jul 26 '22 at 20:08
  • I'm using `mujocoConfig.cmake`, but it's looking for mujocoTargets.cmake. `include could not find requested file: mujocoTargets.cmake Call Stack (most recent call first):` This file doesn't exist. But there is a line in the CMakelists.txt # Generate and install the mujocoTargets.cmake file. This defines the targets as ` # IMPORTED libraries for downstream users. install( EXPORT ${PROJECT_NAME} DESTINATION ${CONFIG_PACKAGE_LOCATION} NAMESPACE mujoco:: FILE "${PROJECT_NAME}Targets.cmake" )` – Ant Jul 26 '22 at 21:17
  • It's looking for `mujocoTargets.cmake`, which is in `./mujoco/build/CMakeFiles/Export/lib/cmake/mujoco`. But I don't know how to point CMakelists.txt to it. – Ant Jul 26 '22 at 21:30
  • 2
    You have to install `mujoco`. That should put everything in a structure the project expects, and then you can point at *that* `mujocoConfig.cmake`. – Stephen Newell Jul 26 '22 at 21:34
  • Thank you @StephenNewell. I'm a bit new to cmake, so I'm not sure how to do that. I've updated the answer at the bottom of the OP. It's looking for mujocoTargets.cmake in the ../build folder but the file is in `/home/iii/tor/m_gym/mujoco/build/CMakeFiles/Export/lib/cmake/mujoco` – Ant Jul 26 '22 at 21:37

0 Answers0