From 89f76d562fc9c9bf518df229b8c55726592f85df Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Mon, 2 Nov 2020 20:04:08 +0800 Subject: [PATCH 1/2] no message --- CMakeLists.txt | 116 +++++++++++++++---------------------------------- conanfile.py | 23 ++++++---- 2 files changed, 51 insertions(+), 88 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ba9af44..a420e35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,84 +1,40 @@ -cmake_minimum_required(VERSION 3.11) -message( "current compiler " ${CMAKE_CXX_COMPILER_ID}) -message("current CXX compiler is " ${CMAKE_CXX_COMPILER}) -message("current X compiler is " ${CMAKE_CXX_COMPILER}) -message("current make is " ${CMAKE_MAKE_PROGRAM}) -enable_language(CXX) -project(generallib) -add_subdirectory(general) -SET(SRC_SDK sdk_main.c test/src/heapsort/main.c)#生成动态库需要至少包含一个源文件 -add_library(generallib STATIC $ ${SRC_SDK}) -message("CMAKE_BINARY_DIR is " ${CMAKE_BINARY_DIR}) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/libd) -link_directories(general/third/lib) -set_target_properties(generallib PROPERTIES LINKER_LANGUAGE CXX) -target_link_libraries(generallib public - -Wl,--whole-archive - libevent.a - -Wl,--no-whole-archive -) -message("current path is" ${CMAKE_CURRENT_SOURCE_DIR}) -IF (WIN32) - if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - message("using clang") - elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - message("using gcc") - add_custom_command ( - TARGET generallib POST_BUILD - COMMAND ar -x - ${CMAKE_CURRENT_SOURCE_DIR}/libd/libevent.a - COMMENT "package library ar -x ${CMAKE_CURRENT_SOURCE_DIR}/libd/libevent.a " - ) +from conans import ConanFile, CMake, tools +from conans import tools - add_custom_command ( - TARGET generallib POST_BUILD - COMMAND ar rc libgeneral.a *.obj - COMMENT "package library ar rc *.o " - ) - add_custom_command( - TARGET generallib POST_BUILD - COMMAND del *.o *.obj - COMMENT "remove all step library" - ) - # using GCC - elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") - message("using asm") - elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") - message("using msvc") - endif() +class GenerallibConan(ConanFile): + source_folder = "pkgsrc" + name = "generallib" + version = "1.0" + license = "GPL" + author = "caiyuzheng" + url = "https://gitee.com/290198252/generallib" + description = "a simple cpp basic library" + exports_sources = "general*", "test*" + generators = "cmake_find_package" -endif() + def source(self): + tools.rmdir("pkgsrc") + git = tools.Git(folder=self.source_folder + "/pkgsrc") + git.clone("https://gitee.com/290198252/generallib.git") -# copy header files -SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/obj) + def package(self): + self.copy(pattern ="*.h", dst="include", src="general",keep_path=True) + self.copy(pattern ="*.hpp", dst="include", src="general",keep_path=True) -set(COPYITEM inc) -file(GLOB INCLUDES ${PROJECT_SOURCE_DIR}/inc/*) -file(COPY ${INCLUDES} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc - FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ) -message("include dir " ${INCLUDES}) - -file(GLOB PatternINCLUDES ${PROJECT_SOURCE_DIR}/general/src/pattern/*) -file(COPY ${PatternINCLUDES} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc - FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ) -message( "copy pattern library" ${PatternINCLUDES}) -file(GLOB EncryptINCLUDES ${PROJECT_SOURCE_DIR}/general/src/encrypt/*.h) -file(COPY ${EncryptINCLUDES} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc - FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ) -file(GLOB MathINCLUDES ${PROJECT_SOURCE_DIR}/general/src/math/*.hpp) -message( "copy math library" ${MathINCLUDES}) -add_custom_command(TARGET generallib PRE_LINK - COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/general/src/math/eigen ${LIBRARY_OUTPUT_PATH}/inc/math/eigen) -message( "copy third library") -file(GLOB THIRD ${PROJECT_SOURCE_DIR}/general/third/include/*) -file(COPY ${THIRD} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc/third/ - FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ) -message( "copy net ") - -file(GLOB NET ${PROJECT_SOURCE_DIR}/general/src/net/*.h) -file(COPY ${NET} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc/ - FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ) - -file(GLOB ALGORITHM ${PROJECT_SOURCE_DIR}/general/src/algorithm/*) -file(COPY ${ALGORITHM} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc/ - FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ) + def build(self): + cmake = CMake(self) + print("path " + self.source_folder + " is where the package built") + print("build env is ",tools.get_env("BUILD_ENV")) + tools.rmdir(tools.unix_path(self.package_folder)+"/build") + tools.mkdir(tools.unix_path(self.package_folder)+"/build") + if tools.os_info.is_windows: + print("current os windows") + if tools.os_info.is_cygwin: + print("cygwin build") + if tools.get_env("BUILD_ENV")=="msys": + print("msys build") + tools.run_in_windows_bash(self, subsystem="msys",cwd="pkgsrc",msys_mingw=True,bashcmd="cmake build -G\"MinGW Makefiles\" " + tools.unix_path(self.source_folder + "/pkgsrc")) + tools.run_in_windows_bash(self, subsystem="msys",cwd="pkgsrc",msys_mingw=True,bashcmd="cmake --build . ") + + def requirements(self): + self.requires("libevent/2.1.2", private=True, override=False) \ No newline at end of file diff --git a/conanfile.py b/conanfile.py index 187a3c1..a933bd2 100644 --- a/conanfile.py +++ b/conanfile.py @@ -12,7 +12,7 @@ class GenerallibConan(ConanFile): exports_sources = "general*", "test*" def source(self): tools.rmdir("pkgsrc") - git = tools.Git(folder=self.source_folder) + git = tools.Git(folder=self.source_folder + "/pkgsrc") git.clone("https://gitee.com/290198252/generallib.git") def package(self): @@ -21,11 +21,18 @@ class GenerallibConan(ConanFile): def build(self): cmake = CMake(self) - # same as cmake.configure(source_folder=self.source_folder, build_folder=self.build_folder) - cmake.configure(source_folder="pkgsrc", build_folder="build") - cmake.build() - cmake.test() - cmake.install() - + print("path " + self.source_folder + " is where the package built") + print("build env is ",tools.get_env("BUILD_ENV")) + tools.rmdir(tools.unix_path(self.package_folder)+"/build") + tools.mkdir(tools.unix_path(self.package_folder)+"/build") + if tools.os_info.is_windows: + print("current os windows") + if tools.os_info.is_cygwin: + print("cygwin build") + if tools.get_env("BUILD_ENV")=="msys": + print("msys build") + tools.run_in_windows_bash(self, subsystem="msys",cwd="pkgsrc",msys_mingw=True,bashcmd="cmake build -G\"MinGW Makefiles\" " + tools.unix_path(self.source_folder + "/pkgsrc")) + tools.run_in_windows_bash(self, subsystem="msys",cwd="pkgsrc",msys_mingw=True,bashcmd="cmake --build . ") + def requirements(self): - self.build_requires("tool_win/0.1@user/stable") + self.requires("libevent/2.1.2", private=True, override=False) \ No newline at end of file From c8488d3918e5e2d094e0d0f60108b6fd2550e0ce Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Mon, 2 Nov 2020 20:07:45 +0800 Subject: [PATCH 2/2] no message --- CMakeLists.txt | 117 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 81 insertions(+), 36 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a420e35..822b36a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,40 +1,85 @@ -from conans import ConanFile, CMake, tools -from conans import tools +cmake_minimum_required(VERSION 3.11) +message( "current compiler " ${CMAKE_CXX_COMPILER_ID}) +message("current CXX compiler is " ${CMAKE_CXX_COMPILER}) +message("current X compiler is " ${CMAKE_CXX_COMPILER}) +message("current make is " ${CMAKE_MAKE_PROGRAM}) +enable_language(CXX) +project(generallib) +add_subdirectory(general) +SET(SRC_SDK sdk_main.c test/src/heapsort/main.c)#生成动态库需要至少包含一个源文件 +add_library(generallib STATIC $ ${SRC_SDK}) +message("CMAKE_BINARY_DIR is " ${CMAKE_BINARY_DIR}) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/libd) +link_directories(general/third/lib) +set_target_properties(generallib PROPERTIES LINKER_LANGUAGE CXX) +target_link_libraries(generallib public + -Wl,--whole-archive + libevent.a + -Wl,--no-whole-archive +) +find_package(libevent) +message("current path is" ${CMAKE_CURRENT_SOURCE_DIR}) +IF (WIN32) + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + message("using clang") + elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + message("using gcc") + add_custom_command ( + TARGET generallib POST_BUILD + COMMAND ar -x + ${CMAKE_CURRENT_SOURCE_DIR}/libd/libevent.a + COMMENT "package library ar -x ${CMAKE_CURRENT_SOURCE_DIR}/libd/libevent.a " + ) -class GenerallibConan(ConanFile): - source_folder = "pkgsrc" - name = "generallib" - version = "1.0" - license = "GPL" - author = "caiyuzheng" - url = "https://gitee.com/290198252/generallib" - description = "a simple cpp basic library" - exports_sources = "general*", "test*" - generators = "cmake_find_package" + add_custom_command ( + TARGET generallib POST_BUILD + COMMAND ar rc libgeneral.a *.obj + COMMENT "package library ar rc *.o " + ) + add_custom_command( + TARGET generallib POST_BUILD + COMMAND del *.o *.obj + COMMENT "remove all step library" + ) + # using GCC + elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") + message("using asm") + elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + message("using msvc") + endif() - def source(self): - tools.rmdir("pkgsrc") - git = tools.Git(folder=self.source_folder + "/pkgsrc") - git.clone("https://gitee.com/290198252/generallib.git") +endif() - def package(self): - self.copy(pattern ="*.h", dst="include", src="general",keep_path=True) - self.copy(pattern ="*.hpp", dst="include", src="general",keep_path=True) +# copy header files +SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/obj) - def build(self): - cmake = CMake(self) - print("path " + self.source_folder + " is where the package built") - print("build env is ",tools.get_env("BUILD_ENV")) - tools.rmdir(tools.unix_path(self.package_folder)+"/build") - tools.mkdir(tools.unix_path(self.package_folder)+"/build") - if tools.os_info.is_windows: - print("current os windows") - if tools.os_info.is_cygwin: - print("cygwin build") - if tools.get_env("BUILD_ENV")=="msys": - print("msys build") - tools.run_in_windows_bash(self, subsystem="msys",cwd="pkgsrc",msys_mingw=True,bashcmd="cmake build -G\"MinGW Makefiles\" " + tools.unix_path(self.source_folder + "/pkgsrc")) - tools.run_in_windows_bash(self, subsystem="msys",cwd="pkgsrc",msys_mingw=True,bashcmd="cmake --build . ") - - def requirements(self): - self.requires("libevent/2.1.2", private=True, override=False) \ No newline at end of file +set(COPYITEM inc) +file(GLOB INCLUDES ${PROJECT_SOURCE_DIR}/inc/*) +file(COPY ${INCLUDES} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc + FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ) +message("include dir " ${INCLUDES}) + +file(GLOB PatternINCLUDES ${PROJECT_SOURCE_DIR}/general/src/pattern/*) +file(COPY ${PatternINCLUDES} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc + FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ) +message( "copy pattern library" ${PatternINCLUDES}) +file(GLOB EncryptINCLUDES ${PROJECT_SOURCE_DIR}/general/src/encrypt/*.h) +file(COPY ${EncryptINCLUDES} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc + FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ) +file(GLOB MathINCLUDES ${PROJECT_SOURCE_DIR}/general/src/math/*.hpp) +message( "copy math library" ${MathINCLUDES}) +add_custom_command(TARGET generallib PRE_LINK + COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/general/src/math/eigen ${LIBRARY_OUTPUT_PATH}/inc/math/eigen) +message( "copy third library") +file(GLOB THIRD ${PROJECT_SOURCE_DIR}/general/third/include/*) +file(COPY ${THIRD} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc/third/ + FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ) +message( "copy net ") + +file(GLOB NET ${PROJECT_SOURCE_DIR}/general/src/net/*.h) +file(COPY ${NET} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc/ + FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ) + +file(GLOB ALGORITHM ${PROJECT_SOURCE_DIR}/general/src/algorithm/*) +file(COPY ${ALGORITHM} DESTINATION ${LIBRARY_OUTPUT_PATH}/inc/ + FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_WRITE GROUP_READ WORLD_READ)