其他分享
首页 > 其他分享> > git submodule 与cmake(以Gflags glog为例)

git submodule 与cmake(以Gflags glog为例)

作者:互联网

git submodule add http://172.16.10.13/source_dir/gflags submodules/gflags
git submodule add http://172.16.10.13/source_dir/glog submodules/glog
git submodule update --init --recursive
cmake_minimum_required (VERSION 2.8)

if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
    message(FATAL_ERROR "
    FATAL: In-source builds are not allowed.
           You should create a separate directory for build files.
           ")
endif()

project (test_pro)
aux_source_directory(src DIR_SRCS)
add_executable(test_pro ${DIR_SRCS})
#target_link_libraries(test_pro)
cmake_minimum_required (VERSION 2.8)

if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
    message(FATAL_ERROR "
    FATAL: In-source builds are not allowed.
           You should create a separate directory for build files.
           ")
endif()

project (test_pro)
aux_source_directory(src DIR_SRCS)

### LOCALCMAKE_TOOLCHAIN 编译平台选择 例如:cmake -DLOCALCMAKE_TOOLCHAIN:STRING=1804 .. ### 设置submodule编译输出的位置 set(CMAKE_BUILD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bld_${LOCALCMAKE_TOOLCHAIN}) #Glog Gflags 静态库位置 set(GLOG_LIBRARY ${CMAKE_BUILD_DIR}/glog/lib/libglog.a ) set(GFLAGS_LIBRARY ${CMAKE_BUILD_DIR}/gflags/lib/libgflags.a ) #Glog 自动化编译 add_dependencies(test_pro Glog) add_custom_command( WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/submodules/glog/build.static OUTPUT ${CMAKE_BUILD_DIR}/glog/include OUTPUT ${CMAKE_BUILD_DIR}/glog/lib/libglog.a COMMAND rm CMake* cmake* Makefile -rf COMMAND cmake -DCMAKE_INSTALL_PREFIX=${CMAKE_BUILD_DIR}/glog -DCMAKE_PREFIX_PATH=${CMAKE_BUILD_DIR}/gflags/ .. COMMAND make -j$(nproc) COMMAND make install) #Glog make install 安装输出文件 add_custom_target(Glog DEPENDS ${CMAKE_BUILD_DIR}/gflags/lib/libgflags.a DEPENDS ${CMAKE_BUILD_DIR}/glog/include DEPENDS ${CMAKE_BUILD_DIR}/glog/lib/libglog.a ) #Gflags 自动化编译 add_dependencies(test_pro Gflags) add_custom_command( WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/submodules/gflags/build.static OUTPUT ${CMAKE_BUILD_DIR}/gflags/include OUTPUT ${CMAKE_BUILD_DIR}/gflags/lib/libgflags.a COMMAND rm CMake* cmake* Makefile -rf COMMAND cmake -DCMAKE_INSTALL_PREFIX=${CMAKE_BUILD_DIR}/gflags -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} .. COMMAND make -j$(nproc) COMMAND make install) #Gflags make install 安装输出文件 add_custom_target(Gflags DEPENDS ${CMAKE_BUILD_DIR}/gflags/include DEPENDS ${CMAKE_BUILD_DIR}/gflags/lib/libgflags.a ) add_executable(test_pro ${DIR_SRCS}) #项目对Glog Gflags的依赖 target_link_libraries(test_pro ${GLOG_LIBRARY} ${GFLAGS_LIBRARY})

 

标签:Gflags,submodule,CMAKE,gflags,glog,BUILD,cmake,DIR
来源: https://www.cnblogs.com/rayfloyd/p/14329917.html