设定cmake输出目录

对于我来说,我使用的是cmake 3.5,但below(set variable)不起作用:

 

set(

      ARCHIVE_OUTPUT_DIRECTORY "/home/xy/cmake_practice/lib/"

      LIBRARY_OUTPUT_DIRECTORY "/home/xy/cmake_practice/lib/"

      RUNTIME_OUTPUT_DIRECTORY "/home/xy/cmake_practice/bin/"

)

但这有效(set set_target_properties):

 

set_target_properties(demo5

    PROPERTIES

    ARCHIVE_OUTPUT_DIRECTORY "/home/xy/cmake_practice/lib/"

    LIBRARY_OUTPUT_DIRECTORY "/home/xy/cmake_practice/lib/"

    RUNTIME_OUTPUT_DIRECTORY "/home/xy/cmake_practice/bin/"

)

 

这个函数也没起作用

FUNCTION(SET_OUTPUT_DIR customDir)
    MESSAGE("${customDir}")
    SET (OUTPUT_DIR "${customDir}")
    SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_DIR}")
    SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_DIR}")
    SET (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${OUTPUT_DIR}")
    foreach (OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
        STRING (TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG)
        SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} "${OUTPUT_DIR}")
        SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} "${OUTPUT_DIR}")
        SET (CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} "${OUTPUT_DIR}")
    endforeach ()
    MESSAGE (STATUS "Output path: ${OUTPUT_DIR}")
ENDFUNCTION()

 

posted on 2020-09-13 05:47  莫水千流  阅读(1172)  评论(0编辑  收藏  举报