conan dependency
from conans import ConanFile, CMake, tools, load
import re
class testConan(ConanFile):
name = "test"
version = "1.0.0"
author = "xxx"
description = "conan test"
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "xcode", "visual_studio"
def configure(self):
if self.settings.os == "Windows":
self.settings.compiler = "Visual Studio"
self.settings.compiler.version = 16
else:
raise Exception("Error: not support os!")
def imports(self):
if self.settings.os == "Windows":
self.copy("*.lib", "./lib", "lib")
self.copy("*.pdb", "./lib", "lib")
self.copy("*.winmd", "./lib", "lib")
self.copy("*gen/*.hpp", "./include", "include", "common")
self.copy("*.hpp", "./include", "include", "utility")
self.copy("*.h", "./include", "include", "curl")
self.copy("*.h", "./include", "include", "rapidjson")
self.copy("*.h", "./include", "include", "crashDump")
self.copy("*.h", "./include", "include", "lib7z")
self.copy("*.h", "./include", "include", "quill")
self.copy("*.h", "./include/pthread", "include", "pthread")
self.copy("*.hpp", "./include", "include", "mio")
self.copy("*.*", "./include", "include", "odb")
self.copy("*.dll", "./bin", "bin")
self.copy("*WebView*.exe", "./bin", "bin")
self.copy("webrtc_shared.dll.pdb", "./bin", "pdb")
def requirements(self):
if self.settings.os == "Windows":
self.requires("libcurl/7.87.0")
else:
raise Exception("Error: not support os!")
def package(self):
self.copy("*", dst="include", src="./out/include/", keep_path=True)
self.copy("*", dst="lib", src="./out/lib/", keep_path=True)
self.copy("*", dst="bin", src="./out/bin/", keep_path=True)
def package_info(self):
self.cpp_info.libs = tools.collect_libs(self)
cmake
cmake_minimum_required(VERSION 3.6.0)
set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/output) # 设置install 时候的路径
project(testProject LANGUAGES CXX)
# conan config
include(./archtectures/conanbuildinfo.cmake)
conan_basic_setup(TARGETS NO_OUTPUT_DIRS)
include_directories(${CONAN_INCLUDE_DIRS})
include_directories(${CONAN_INCLUDE_DIRS_UTILITY}/optional)
include_directories(${CONAN_INCLUDE_DIRS_UTILITY}/stringify)
include_directories(${CONAN_INCLUDE_DIRS_UTILITY}/json)
link_directories(${CONAN_LIB_DIRS})
# output pdb
set(CMAKE_CXX_FLAGS_RELEASE "/MD /Zi /Od /DNDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Od")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
message("CMAKE_INSTALL_PREFIX= ${CMAKE_INSTALL_PREFIX}")
# For build target
file (GLOB_RECURSE SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.c??)
add_library(testProject STATIC ${SRC_FILES})
# insatll
SET(targets)
SET(targets ${targets} testProject)
INSTALL(TARGETS ${targets}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
DESTINATION include/
FILES_MATCHING PATTERN *.h**)
file(GLOB_RECURSE PDB_FILES ${PROJECT_BINARY_DIR}
FILES_MATCHING PATTERN *.pdb)
INSTALL(FILES ${PDB_FILES}
DESTINATION lib)
build script
conan install . -s os=Windows -s build_type=${build_type} -r conancenter --update --install-folder archtectures
cmake -Bbuild -G "Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=${build_type}
cmake --build build --target install --config ${build_type}