テスト用にサブディレクトリ内の実行可能ファイルをコンパイルしようとしてproject/model/tests
いますが、にあるモデルファイルをリンクする必要がありますproject/model
。しかし、私はそれを動作させることができません。親ディレクトリを正常に追加しましたが、cmakeは、親ディレクトリにあるfoo.cppのソースファイルが見つからないことを通知し続けますが、現在のディレクトリにあるbar.cppは正しく追加されます。
cmake_minimum_required(VERSION 2.6)
# get parent directory
get_filename_component(MODEL_DIR ${CMAKE_CURRENT_SOURCE_DIR} PATH)
# Locate GTest
find_package(GTest REQUIRED)
# Add parent directory
include_directories(${GTEST_INCLUDE_DIRS} ${MODEL_DIR})
link_directories(${MODEL_DIR})
# all included directories are printed out correctly
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
foreach(dir ${dirs})
message(STATUS "dir='${dir}'")
endforeach()
# foo.cpp, which is in the parent directory is not found
add_executable(runTests foo.cpp bar.cpp)
target_link_libraries(runTests ${GTEST_LIBRARIES} pthread)
ありがとうございました。