1.cmake相对路径

在android平台可以采用相对路径的方式
在windows平台相对路径不能生效,需要通过绝对路径获取。我采用的方法是获取当前目录工程根目录,然后获取上级目录的方法(比较笨),网友还提供了通过STRING方法,然后通过正则获取想要的目录

#获取CMAKE_SOURCE_DIR上级目录
get_filename_component(PARENT_DIR ${CMAKE_SOURCE_DIR} DIRECTORY)

message(STATUS $)

2.cmake设置ios安装路径

set_target_properties(test PROPERTIES BUILD_WITH_INSTALL_RPATH 1 INSTALL_NAME_DIR "@rpath")

3.cmake打印信息

message(STATUS "CMAKE_SOURCE_DIR:$!")-->打印正常信息

4.cmake各种目录设置

  • 方法1:
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/Lib)
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/Lib)
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/Bin)

  • 方法2:
    set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/Bin)
    set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/Lib)

  • 方法3:(分别设置debug和release目录)
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR}/Lib)
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR}/Lib)
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR}/Bin)
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_SOURCE_DIR}/Lib)
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_SOURCE_DIR}/Lib)
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_SOURCE_DIR}/Bin)