c++ - CMake Add (Test) Executable - Stack Overflow
stackoverflow.com › questions › 41811674include_directories(include) file(GLOB SOURCE "src/*.cc") file(GLOB TEST "test/*.cc") add_executable(interest_calc ${SOURCE}) add_executable(interest_calc_test "src/interest_calc.cc" ${TEST}) Since both src and test directories contain main functions, I have to manually add source files to the "test" executable. Is there another, non-manual, way to add required source files to the "test" executable?
Examples - CMake
https://cmake.org/examplescmake_minimum_required (VERSION 2.8.11) project (HELLO) # Recurse into the "Hello" and "Demo" subdirectories. This does not actually # cause another cmake executable to run. The same process will walk through # the project's entire directory structure. add_subdirectory (Hello) add_subdirectory (Demo)
cmake Tutorial => Executables
riptutorial.com › cmake › exampleTo create a build target producing an executable, one should use the add_executable command: add_executable (my_exe main.cpp utilities.cpp) This creates a build target, e.g. make my_exe for GNU make, with the appropriate invocations of the configured compiler to produce an executable my_exe from the two source files main.cpp and utilities.cpp. By default, all executable targets are added to the builtin all target ( all for GNU make, BUILD_ALL for MSVC).
Examples - CMake
cmake.org › examplesFinally, in the ./Demo directory, the third and final CMakeLists.txt file is created: # Add executable called "helloDemo" that is built from the source files # "demo.cxx" and "demo_b.cxx". The extensions are automatically found. add_executable (helloDemo demo.cxx demo_b.cxx) # Link the executable to the Hello library.
cmake Tutorial => Executables
https://riptutorial.com/cmake/example/10592/executablesTo create a build target producing an executable, one should use the add_executable command: add_executable (my_exe main.cpp utilities.cpp) This creates a build target, e.g. make my_exe for GNU make, with the appropriate invocations of the configured compiler to produce an executable my_exe from the two source files main.cpp and utilities.cpp.
add_executable — CMake 3.23.0-rc4 Documentation
cmake.org › latest › commandAdds an executable target called <name> to be built from the source files listed in the command invocation. The <name> corresponds to the logical target name and must be globally unique within a project. The actual file name of the executable built is constructed based on conventions of the native platform (such as <name>.exe or just <name>).