Open HiroIshida opened 4 years ago
bullet3/examples/pybullet/CMakeLists.txtは、bullet3/examples/CMakeLists.txtから呼び出されます。
https://github.com/bulletphysics/bullet3/blob/6b6cfa6f03a54de484e15520f0a86ea81c9831ae/examples/CMakeLists.txt#L7 (リンク切れを防ぐため、masterブランチの現在の最新コミットを参照しています)
で、その前にbullet3/examples/SharedMemory/CMakeLists.txtを呼び出しているので、ここで何かやっているんじゃないだろうかという気分になります。
https://github.com/bulletphysics/bullet3/blob/6b6cfa6f03a54de484e15520f0a86ea81c9831ae/examples/CMakeLists.txt#L3
ただ、bullet3/examples/SharedMemory/CMakeLists.txtを見ても、ADD_EXECUTABLE
しかなくて、ADD_LIBRARY
がないので困りました。
https://github.com/bulletphysics/bullet3/blob/6b6cfa6f03a54de484e15520f0a86ea81c9831ae/examples/SharedMemory/CMakeLists.txt
困ったので、git cloneしてみて、grepを試みます。
$ git clone https://github.com/bulletphysics/bullet3.git
$ cd bullet3/
$ grep -r "PhysicsClientC_API.cpp" |grep CMake
examples/SharedMemory/CMakeLists.txt: PhysicsClientC_API.cpp
examples/ExampleBrowser/CMakeLists.txt: ../SharedMemory/PhysicsClientC_API.cpp
examples/TwoJoint/CMakeLists.txt: ../../examples/SharedMemory/PhysicsClientC_API.cpp
Extras/BulletRobotics/CMakeLists.txt: ../../examples/SharedMemory/PhysicsClientC_API.cpp
test/SharedMemory/CMakeLists.txt: ../../examples/SharedMemory/PhysicsClientC_API.cpp
どうやら、SharedMemoryディレクトリの上層・下層とは別の場所からも、SharedMemoryディレクトリの中身が参照されているようです。
ヒットしたものの一つであるbullet3/Extras/BulletRobotics/CMakeLists.txtを見ると、BulletRobotics_SRCS
にbullet3/examples/SharedMemory/PhysicsClientC_API.cppが入っています。
https://github.com/bulletphysics/bullet3/blob/6b6cfa6f03a54de484e15520f0a86ea81c9831ae/Extras/BulletRobotics/CMakeLists.txt#L122
で、このBulletRobotics_SRCS
がコンパイルされ、BulletRoboticsライブラリが生成されています。
https://github.com/bulletphysics/bullet3/blob/6b6cfa6f03a54de484e15520f0a86ea81c9831ae/Extras/BulletRobotics/CMakeLists.txt#L242
ここで、 bullet3/examples/pybullet/CMakeLists.txtを見返すと、BulletRoboticsライブラリがpybulletライブラリにリンクされています。 https://github.com/bulletphysics/bullet3/blob/6b6cfa6f03a54de484e15520f0a86ea81c9831ae/examples/pybullet/CMakeLists.txt#L78 よって、pybulletライブラリにリンクされたBulletRoboticsライブラリ経由で、PhysicsClientC_API.h/cppの関数が使えることがわかります。
なお、BulletRoboticsライブラリがpybulletライブラリにリンクされるまでは、pybullet_SRCS
にPhysicsClientC_API.h/cppが含まれていたようなので、この時の方がわかりやすかったのかもしれないですね。
https://github.com/bulletphysics/bullet3/commit/fde6cffecc8fcead423a3ebdc101457289531bf2#diff-8a5a760f3e46c787d2f11c67db1dcefdL85
前提
pybulletのshared objectを作る際に, CMakeLIsts.txt 内は次のようになっています.
同じディレクトリ内にあるpybullet.cの中では
みたいな感じでSharedMemoryディレクトリ以下のヘッダがincludeされています.
質問
こういう場合に上記のヘッダ内関数を使うためには, [方法1]
pybullet_SRCS
にみたいにソースファイルを追加するという方法と, [方法2] SharedMemoryディレクトリ内のオブジェクトをまとめたライブラリ, 例えば
SharedMemory.so
を作って, 上記のTARGET_LINK_LIBRARIES
にSharedMemory
を追加する, という2つの方法が考えられると思うんだけど, 上記のpyullet.so
をビルドするためのCMakefile内はこのどちらもなされていなくて, どうやって,../SharedMemory/PhysicsClientC_API.cpp
を使っているのか疑問なので教えてもらえないでしょうか.