Note that there are some explanatory texts on larger screens.

plurals
  1. POCMake: How to differentiate between library files and unit tests for this library?
    primarykey
    data
    text
    <p>I have created a C++ library <code>MyLib</code> with the following structure:</p> <pre><code>MyLib/ |-- Module1/ |-- SubModule1/ |-- Tests/ |-- .cpp files (unit tests) |-- .cpp files (library sources) |-- Tests/ |-- .cpp files (unit tests) |-- .cpp files (library sources) |-- Module2/ |-- Tests/ |-- .cpp files (unit tests) |-- .cpp files (library sources) |-- ... |-- CMakeLists.txt </code></pre> <p>In words, the source files of the library are distributed in many directories and subdirectories. Each directory may contain a directory <code>Tests</code>, which contains unit tests for the modules in the parent directory.</p> <p>I am using CMake v2.8 to build the library (<code>MyLib.a</code>) and unit tests for this library (an executable file named <code>MyLibTests</code>). These are the relevant rules I use to achieve this:</p> <pre class="lang-none prettyprint-override"><code># Build MyLib. file(GLOB_RECURSE MyLib_SOURCES ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) # Filter out source files of unit tests. foreach(ITEM ${MyLib_SOURCES}) if(${ITEM} MATCHES Tests/*) list(REMOVE_ITEM MyLib_SOURCES ${ITEM}) endif() endforeach() add_library(MyLib STATIC ${MyLib_SOURCES}) # Build MyLibTests. file(GLOB_RECURSE MyLib_TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) # Filter out non-unit-tests source files. foreach(ITEM ${MyLib_TESTS_SOURCES}) if(NOT ${ITEM} MATCHES Tests/*) list(REMOVE_ITEM MyLib_TESTS_SOURCES ${ITEM}) endif() endforeach() add_executable(MyLibTests ${MyLib_TESTS_SOURCES}) target_link_libraries(MyLibTests MyLib ${UNIT_TESTS_FRAMEWORK_LIBS}) </code></pre> <p>Is there a better way of finding which <code>.cpp</code> files form the library and which <code>.cpp</code> files are unit tests for this library? I was not able to come up with a proper expression for <code>file(GLOB_RECURSE ...)</code> that would do it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload