많은 자동 최적화를 수행하려면 -fprofile-generate
먼저 플래그를 사용하여 프로그램을 컴파일 한 다음 실행하여 프로필을 생성 한 다음 -fprofile-use
대신 프로그램을 다시 컴파일 할 수 있기를 원합니다 .
즉, CMAKE_CXX_FLAGS
매번 두 가지씩 프로그램을 연속으로 두 번 컴파일하고 싶습니다 .
CMake를 사용하여 어떻게 할 수 있습니까?
고객 대상과 "add_dependencies"명령을 사용하여 무언가를 빌드 한 다음 실행 한 다음 실행 후 다른 것을 빌드 할 수 있습니다. gcov 케이스의 경우 다음과 같이 할 수 있습니다.
profile.cxx
#include <iostream>
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 profileGenerate
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "run Profile Generate"
SOURCES profile.cxx
)
#create depency for profileUse on profileGenerate_run
add_dependencies(profileUse profileGenerate_run)
빌드-> 실행-> 빌드를 보여주는 출력
Este artículo se recopila de Internet, indique la fuente cuando se vuelva a imprimir.
En caso de infracción, por favor [email protected] Eliminar
Déjame decir algunas palabras