Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
559 views
in Technique[技术] by (71.8m points)

cmake - Overwrite subdirectory's variable CMAKE_BINARY_DIR

I use Googletest library as a git submodule and I would like to move its build artifacts in a designated folder, however inside of googletest/CMakeLists.txt (that I would like to avoid changing) it hardcodes artifacts path to

${CMAKE_BUILD_DIR}/lib

and unfortunately maintainers didn't use ${CMAKE_CURRENT_BUILD_DIR} instead to add their artifacts in their local build path that I specify using add_subdirectory command in my own CMakeLists.txt:

add_subdirectory(${VENDOR_SOURCE_DIR}/googletest ${VENDOR_BINARY_DIR}/googletest)

Some artifacts respect the second path, but those hardcoded with aforementioned line don't.

Is there a way to overwrite Googletest's local value of ${CMAKE_BUILD_DIR} without forking/modifying the library's CMakeLists.txt?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can set dir on gtest target:

function target_set_dir(target dir)
    set_target_properties(${target} PROPERTIES
        CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${dir}
        CMAKE_LIBRARY_OUTPUT_DIRECTORY ${dir}
        CMAKE_RUNTIME_OUTPUT_DIRECTORY ${dir}
    )
endfunction()

target_set_dir(gtest ${CMAKE_BUILD_DIR]/gtest})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...