如何使用CMake构建一个OpenSceneGraph项目?

时间:2022-04-06 00:38:29

I have just downloaded the OpenSceneGraph source, unzip it into "~/OpenSceneGraph-3.0.1" directory and use CMake to create an out-of-source eclipse make project in "~/OpenSceneGraph-3.0.1-build-eclipse-cdt" directory. When I execute "make" in "~/OpenSceneGraph-3.0.1-build-eclipse-cdt" directory, OpenSceneGraph builds successfully. I have not run "sudo make install" as I do not want to install OpenSceneGraph tightly into my Ubuntu system.

我刚刚下载了OpenSceneGraph源代码,将其解压到“~/OpenSceneGraph-3.0.1”目录中,并使用CMake在“~/OpenSceneGraph-3.0.1-build-eclipse-cdt”目录中创建一个源代码外的eclipse make项目。当我执行“make”in ~/ openscenegraph- 3.0.1 build-eclipse-cdt”目录时,OpenSceneGraph将成功构建。我没有运行“sudo make install”,因为我不想把OpenSceneGraph严格地安装到我的Ubuntu系统中。

Now I want to use CMake to create a project using the compiled OpenSceneGraph libraries. I use the following codes in CMakeLists.txt :

现在,我想使用CMake创建一个使用已编译的OpenSceneGraph库的项目。我在CMakeLists中使用了以下代码。txt:

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT( test_proj )
FIND_PACKAGE(OpenSceneGraph)
ADD_EXECUTABLE(test test.cpp )
INCLUDE_DIRECTORIES(${OPENSCENEGRAPH_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(test ${OPENSCENEGRAPH_LIBRARIES} )

But it seems that OpenSceneGraph could not be found by CMake.

但是,似乎CMake并没有找到OpenSceneGraph。

Does anyone know how CMake could find the compiled OpenSceneGraph libraries in the "~/OpenSceneGraph-3.0.1-build-eclipse-cdt" directory and use it to create projects as if I have tightly installed OpenSceneGraph using "sudo make install". Thanks for any suggestion.

有谁知道CMake如何在“~/ openscenegraph- 3.1 -build-eclipse-cdt”目录中找到编译好的OpenSceneGraph库,并使用它来创建项目,就好像我使用“sudo make install”紧密地安装了OpenSceneGraph一样。谢谢你的建议。

1 个解决方案

#1


4  

You don't need to install OpenSceneGraph system-wide. Just choose a CMAKE_INSTALL_PREFIX that suits you (eg. ~/osg).

您不需要在系统范围内安装OpenSceneGraph。只需选择适合您的CMAKE_INSTALL_PREFIX(例如。~ /用osg)。

Using the install command makes sure that everything is correctly in place (i.e. in the correct directory structure) for FindOpenSceneGraph.cmake (the script CMake invokes when you call FIND_PACKAGE( OpenSceneGraph ) ) to find it.

使用install命令确保FindOpenSceneGraph的所有内容都正确(即在正确的目录结构中)。cmake(当您调用FIND_PACKAGE(OpenSceneGraph)时,脚本cmake会调用它来找到它。

Then, you should point any of OSG_DIR, OSGDIR, or OSG_ROOT as environment variable and point it to your install location, so CMake knows where to look for it.

然后,您应该将任何OSG_DIR、OSGDIR或OSG_ROOT作为环境变量指向您的安装位置,以便CMake知道在哪里查找它。

Edit: @Hugues: I'll try to make it a bit clearer:

编辑:@Hugues:我会尽量说得更清楚一点:

Setup up OpenSceneGraph:

设置OpenSceneGraph:

  1. Get OSG source.
  2. 用OSG源。
  3. When running CMake for it, choose a CMAKE_INSTALL_PREFIX that suits you, eg. ~/osg if you don't want a system-wide installation in (default) /usr/local. Do it either by stating -DCMAKE_INSTALL_PREFIX=/home/hugues/osg on the command-line or by setting it using a gui tool like ccmake or cmake-gui.
  4. 运行CMake时,选择适合您的CMAKE_INSTALL_PREFIX,例如。~/osg如果不希望在(默认)/usr/ local中进行系统范围的安装。通过在命令行上声明-DCMAKE_INSTALL_PREFIX=/home/hugues/osg,或者使用像ccmake或cmake-gui这样的gui工具来设置它。
  5. Run make install to build and install OSG.
  6. 运行make install来构建和安装OSG。
  7. Set the environment variable OSG_DIR to whatever you pointed CMAKE_INSTALL_PREFIX. (export OSG_DIR=<whereever_you_installed_osg>)
  8. 将环境变量OSG_DIR设置为您所指定的CMAKE_INSTALL_PREFIX。(出口OSG_DIR = < whereever_you_installed_osg >)

Setup your project:

设置您的项目:

  1. In your CMakeLists.txt, use FIND_PACKAGE( OpenSceneGraph ) (add desired optional arguments as desired).
  2. 在你CMakeLists。txt,使用FIND_PACKAGE(OpenSceneGraph)(根据需要添加所需的可选参数)。
  3. Use the resulting variables (like ${OpenSceneGraph_LIBRARIES} in the appropriate places in your cmake file.
  4. 在cmake文件的适当位置使用结果变量(如${OpenSceneGraph_LIBRARIES})。
  5. Run CMake for your project.
  6. 为你的项目运行CMake。

#1


4  

You don't need to install OpenSceneGraph system-wide. Just choose a CMAKE_INSTALL_PREFIX that suits you (eg. ~/osg).

您不需要在系统范围内安装OpenSceneGraph。只需选择适合您的CMAKE_INSTALL_PREFIX(例如。~ /用osg)。

Using the install command makes sure that everything is correctly in place (i.e. in the correct directory structure) for FindOpenSceneGraph.cmake (the script CMake invokes when you call FIND_PACKAGE( OpenSceneGraph ) ) to find it.

使用install命令确保FindOpenSceneGraph的所有内容都正确(即在正确的目录结构中)。cmake(当您调用FIND_PACKAGE(OpenSceneGraph)时,脚本cmake会调用它来找到它。

Then, you should point any of OSG_DIR, OSGDIR, or OSG_ROOT as environment variable and point it to your install location, so CMake knows where to look for it.

然后,您应该将任何OSG_DIR、OSGDIR或OSG_ROOT作为环境变量指向您的安装位置,以便CMake知道在哪里查找它。

Edit: @Hugues: I'll try to make it a bit clearer:

编辑:@Hugues:我会尽量说得更清楚一点:

Setup up OpenSceneGraph:

设置OpenSceneGraph:

  1. Get OSG source.
  2. 用OSG源。
  3. When running CMake for it, choose a CMAKE_INSTALL_PREFIX that suits you, eg. ~/osg if you don't want a system-wide installation in (default) /usr/local. Do it either by stating -DCMAKE_INSTALL_PREFIX=/home/hugues/osg on the command-line or by setting it using a gui tool like ccmake or cmake-gui.
  4. 运行CMake时,选择适合您的CMAKE_INSTALL_PREFIX,例如。~/osg如果不希望在(默认)/usr/ local中进行系统范围的安装。通过在命令行上声明-DCMAKE_INSTALL_PREFIX=/home/hugues/osg,或者使用像ccmake或cmake-gui这样的gui工具来设置它。
  5. Run make install to build and install OSG.
  6. 运行make install来构建和安装OSG。
  7. Set the environment variable OSG_DIR to whatever you pointed CMAKE_INSTALL_PREFIX. (export OSG_DIR=<whereever_you_installed_osg>)
  8. 将环境变量OSG_DIR设置为您所指定的CMAKE_INSTALL_PREFIX。(出口OSG_DIR = < whereever_you_installed_osg >)

Setup your project:

设置您的项目:

  1. In your CMakeLists.txt, use FIND_PACKAGE( OpenSceneGraph ) (add desired optional arguments as desired).
  2. 在你CMakeLists。txt,使用FIND_PACKAGE(OpenSceneGraph)(根据需要添加所需的可选参数)。
  3. Use the resulting variables (like ${OpenSceneGraph_LIBRARIES} in the appropriate places in your cmake file.
  4. 在cmake文件的适当位置使用结果变量(如${OpenSceneGraph_LIBRARIES})。
  5. Run CMake for your project.
  6. 为你的项目运行CMake。