cmake编译发布lib 和 bin

cmake 编译文件,参考:
lightgbm

if(USE_GPU OR APPLE)
  MESSAGE( STATUS "this is use_gpu or apple")
  cmake_minimum_required(VERSION 3.14)
else()
 MESSAGE( STATUS "this is not  use_gpu or not use apple")
 cmake_minimum_required(VERSION 3.8)
endif()

project(open_source)

OPTION(USE_MPI "Enable MPI-based parallel learning" OFF)
OPTION(USE_GPU "Enable Gpu training" OFF)

if(APPLE)
  OPTION(APPLE_OUTPUT_DYLIB "Output dylib shared library" OFF)
  MESSAGE( STATUS "apple if use dylib:" ${APPLE_OUTPUT_DYLIB})
endif(APPLE)

# check the compiler version
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8.2")
     MESSAGE(FATAL_ERROR "INsufficient gcc version")
  else()
   MESSAGE(STATUS "CMAKE_CXX_COMPILER_VERSION:" ${CMAKE_CXX_COMPILER_VERSION})
  endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.8")
    message(FATAL_ERROR "INsufficient clang version")
   else()
     message(STATUS "CMAKE_CXX_COMPILER_VERSION:" ${CMAKE_CXX_COMPILER_VERSION})
   endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
  if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.1.0")
     message(FATAL_ERROR "INsufficient apple clang version")
   else()
      message(STATUS "CMAKE_CXX_COMPILER_VERSION:" ${CMAKE_CXX_COMPILER_VERSION})
   endif()
endif()

if(USE_SWIG)
  message(STATUS "use_swig!!!")
endif()

file(GLOB SOURCES
    src/application/*.cpp
)

add_executable(open_source src/main.cpp ${SOURCES})
add_library(_open_source SHARED src/c_api.cpp ${SOURCES})

message(STATUS "PROJECT_SOURCE_DIR:"${PROJECT_SOURCE_DIR})

SET(OPEN_SOURCE_HEADER_DIR ${PROJECT_SOURCE_DIR}/include)

SET(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}/output)
message(STATUS "CMAKE_INSTALL_PREFIX:" ${CMAKE_INSTALL_PREFIX})

SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR})
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR})

include_directories(${OPEN_SOURCE_HEADER_DIR})

install(TARGETS open_source _open_source
       RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
       LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
       ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)

install(DIRECTORY ${OPEN_SOURCE_HEADER_DIR}/open_source DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
发布了445 篇原创文章 · 获赞 180 · 访问量 113万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览