你可以构建一些东西然后运行它,然后在执行之后通过使用客户目标和“add_dependencies”命令来构建其他东西。为了您的gcov情况下,你可以这样做:
profile.cxx
#include
int main(void) {
std::cout << "Hello from Generating Profile run" << std::endl;
return 0;
}
的CMakeLists.txt
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(profileExample C CXX)
# compile initial program
add_executable(profileGenerate profile.cxx)
set_target_properties(profileGenerate PROPERTIES COMPILE_FLAGS "-fprofile-
generate")
target_link_libraries(profileGenerate gcov)
add_executable(profileUse profile.cxx)
set_target_properties(profileUse PROPERTIES COMPILE_FLAGS "-fprofile-use")
target_link_libraries(profileUse gcov)
# custom target to run program
add_custom_target(profileGenerate_run
COMMAND pro