c++ - How to link an exe project to the classes in another exe project -


suppose want unit testing on classes in executable don't want refactor them out lib can add lib using target_link_libraries( target library ) in cmake.

how give test class access other classes?

1) build test project source files other project? thing

  include_directories(${otherexeprojectdir})    set( source_files       main.cpp      tests.h      tests.cpp      ${otherexeprojectdir}/otherclass1.h      ${otherexeprojectdir}/otherclass2.h    ) 

2) link test project obj files other project? sort of add_library( otherclass.obj ) craziness?

3)

if main executable source locations simple or flat, work:

cmake_minimum_required(version 3.9) project(tests)  # main executable source location properties get_target_property(exe_sources exe sources) get_target_property(exe_source_dir exe source_dir)  # remove main entry point file list(remove_item exe_sources main.cpp)  # add test sources add_executable(test1 test1.cpp)  # add exe sources test (assumes sources relative paths) foreach(src in lists exe_sources)   target_sources(test1 private "${exe_source_dir}/${src}") endforeach()  # add exe include directories test target_include_directories(test1 private    ${exe_source_dir}   $<target_property:exe,include_directories>) 

otherwise general solution is, unfortunately, rely on external information, e.g. top level source file locations or adding own source properties main executable target.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -