Wednesday, 15 April 2015

c++ - CMake link single class in another project -



c++ - CMake link single class in another project -

its 1 of first c++ projects , got problems cmake.

i have myproject executeable , got project tests boost unit tests. tried next way, failed. cant have 2 executeables way , dont know how prepare fix it.

this cmake of myproject

project (myproject) find_package( boost 1.48.0 components thread ) set(myproject_srcs main.cpp foo.h foo.cpp) add_executable(myproject ${myproject_srcs}) target_link_libraries(myproject ${boost_libraries})

this cmake of tests

project (tests) find_package( boost 1.48.0 components thread unit_test_framework) find_package( boost 1.48.0 components thread ) include_directories("../myproject") set(test_srcs test.cpp ) add_executable(tests ${test_srcs}) target_link_libraries(tests ${boost_libraries} myproject) add_test( example_test tests )

cmake error @ tests/cmakelists.txt:13 (target_link_libraries): target "myproject" of type executable may not linked another target. 1 may link static or shared libraries, or executables enable_exports property set.

i tried "enable_exports property set", think did wrong.

you shouldn't link executable file tests, instead need include source files of main project in tests source list:

set(test_srcs test.cpp ../myproject/foo.cpp)

target_link_libraries(tests ${boost_libraries} )

p.s. useful when want analyze test coverage.

c++ cmake shared-libraries static-libraries

No comments:

Post a Comment