From b19af9809dc5097c19de8d288acb3c39c4eb8642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=A0=91=E6=96=B0?= Date: Sat, 31 Aug 2024 21:10:21 +0800 Subject: [PATCH] Optimize building process by cmake on Windows platforms. --- CMakeLists.txt | 5 ++- lib_acl/CMakeLists.txt | 26 ++++++++--- lib_acl_cpp/CMakeLists.txt | 41 +++++++++++++---- lib_fiber/c/CMakeLists.txt | 34 +++++++++++--- lib_fiber/cpp/CMakeLists.txt | 44 ++++++++++++++----- lib_fiber/cpp/src/detours/creatwth.cpp | 4 +- .../cpp/src/detours/{ => deps}/uimports.cpp | 0 lib_protocol/CMakeLists.txt | 44 +++++++++++++++---- 8 files changed, 154 insertions(+), 44 deletions(-) rename lib_fiber/cpp/src/detours/{ => deps}/uimports.cpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 77004eab3..0b5bb010d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ #cmake_minimum_required(VERSION 3.2.0) -cmake_minimum_required(VERSION 2.8.0) -project(Acl) +#cmake_minimum_required(VERSION 2.8.0) +cmake_minimum_required(VERSION 3.22.0) +project(acl) #message(${CMAKE_SYSTEM_NAME}) diff --git a/lib_acl/CMakeLists.txt b/lib_acl/CMakeLists.txt index 09d6bedb2..287d5f38c 100644 --- a/lib_acl/CMakeLists.txt +++ b/lib_acl/CMakeLists.txt @@ -1,5 +1,5 @@ -#cmake_minimum_required(VERSION 3.2.0) -cmake_minimum_required(VERSION 2.8.0) +cmake_minimum_required(VERSION 3.2.0) +#cmake_minimum_required(VERSION 2.8.0) project(acl) #set(CMAKE_BUILD_TYPE Release) @@ -166,6 +166,9 @@ elseif (${WIN_OS}) "-D_WINSOCK_DEPRECATED_NO_WARNINGS" "-DACL_WRITEABLE_CHECK" "-DACL_PREPARE_COMPILE") + if (ACL_BUILD_SHARED MATCHES "YES") + add_definitions("-DACL_DLL -DACL_EXPORTS") + endif() endif() if (ACL_CLIENT_ONLY MATCHES "YES") @@ -187,9 +190,14 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${acl_output_path}) add_library(acl_static STATIC ${acl_src}) if (${WIN_OS}) - SET_TARGET_PROPERTIES(acl_static PROPERTIES OUTPUT_NAME "libacl") + set_target_properties(acl_static PROPERTIES OUTPUT_NAME "libacl") + set_target_properties(acl_static PROPERTIES + OUTPUT_NAME "libacl" + ARCHIVE_OUTPUT_DIRECTORY ${acl_output_path}/static + LIBRARY_OUTPUT_DIRECTORY ${acl_output_path}/static + ) else() - SET_TARGET_PROPERTIES(acl_static PROPERTIES OUTPUT_NAME "acl") + set_target_properties(acl_static PROPERTIES OUTPUT_NAME "acl") endif() link_directories(${acl_output_path}) @@ -234,9 +242,15 @@ if (ACL_BUILD_SHARED MATCHES "YES") add_library(acl_shared SHARED ${acl_src}) if (${WIN_OS}) - SET_TARGET_PROPERTIES(acl_shared PROPERTIES OUTPUT_NAME "libacl") + set_target_properties(acl_shared PROPERTIES + OUTPUT_NAME "libacl" + RUNTIME_OUTPUT_DIRECTORY ${acl_output_path}/shared + ARCHIVE_OUTPUT_DIRECTORY ${acl_output_path}/shared + LIBRARY_OUTPUT_DIRECTORY ${acl_output_path}/shared + ) + set_target_properties(acl_shared PROPERTIES OUTPUT_NAME "libacl") else() - SET_TARGET_PROPERTIES(acl_shared PROPERTIES OUTPUT_NAME "acl") + set_target_properties(acl_shared PROPERTIES OUTPUT_NAME "acl") endif() if(CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Darwin") diff --git a/lib_acl_cpp/CMakeLists.txt b/lib_acl_cpp/CMakeLists.txt index 558986193..350400afd 100644 --- a/lib_acl_cpp/CMakeLists.txt +++ b/lib_acl_cpp/CMakeLists.txt @@ -1,5 +1,5 @@ -#cmake_minimum_required(VERSION 3.2.0) -cmake_minimum_required(VERSION 2.8.0) +cmake_minimum_required(VERSION 3.2.0) +#cmake_minimum_required(VERSION 2.8.0) project(acl_cpp) #set(CMAKE_BUILD_TYPE Release) @@ -238,6 +238,11 @@ elseif (${WIN_OS}) "-DHAS_POLARSSL_DLL" "-DHAS_MBEDTLS_DLL" "-DUSE_WIN_ICONV") + if (ACL_BUILD_SHARED MATCHES "YES") + add_definitions("-DACL_CPP_DLL -DACL_CPP_EXPORTS" + "-DACL_DLL -DHTTP_DLL -DICMP_DLL -DSMTP_DLL" + ) + endif() aux_source_directory(${src}/stdlib/internal lib_src) endif() @@ -255,9 +260,13 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${lib_output_path}) add_library(acl_cpp_static STATIC ${lib_src}) if (${WIN_OS}) - SET_TARGET_PROPERTIES(acl_cpp_static PROPERTIES OUTPUT_NAME "libacl_cpp") + set_target_properties(acl_cpp_static PROPERTIES + OUTPUT_NAME "libacl_cpp" + ARCHIVE_OUTPUT_DIRECTORY ${lib_output_path}/static + LIBRARY_OUTPUT_DIRECTORY ${lib_output_path}/static + ) else() - SET_TARGET_PROPERTIES(acl_cpp_static PROPERTIES OUTPUT_NAME "acl_cpp") + set_target_properties(acl_cpp_static PROPERTIES OUTPUT_NAME "acl_cpp") endif() link_directories(${lib_output_path}) @@ -302,12 +311,26 @@ if (ACL_BUILD_SHARED MATCHES "YES") -fvisibility=hidden -fvisibility-inlines-hidden) endif() - set(lc_flags "-Wl,-rpath,${CMAKE_INSTALL_PREFIX}/lib -L${lib_output_path}") - set(CMAKE_SHARED_LINKER_FLAGS "${lc_flags} ${sys_ldflags}") - add_library(acl_cpp_shared SHARED ${lib_src}) - target_link_libraries(acl_cpp_shared protocol acl) + if (${WIN_OS}) + link_directories(${lib_output_path}/shared) + endif() - SET_TARGET_PROPERTIES(acl_cpp_shared PROPERTIES OUTPUT_NAME "acl_cpp") + add_library(acl_cpp_shared SHARED ${lib_src}) + + if (${WIN_OS}) + set_target_properties(acl_cpp_shared PROPERTIES + OUTPUT_NAME "libacl_cpp" + RUNTIME_OUTPUT_DIRECTORY ${lib_output_path}/shared + ARCHIVE_OUTPUT_DIRECTORY ${lib_output_path}/shared + LIBRARY_OUTPUT_DIRECTORY ${lib_output_path}/shared + ) + target_link_libraries(acl_cpp_shared libprotocol libacl) + else() + set(lc_flags "-Wl,-rpath,${CMAKE_INSTALL_PREFIX}/lib -L${lib_output_path}") + set(CMAKE_SHARED_LINKER_FLAGS "${lc_flags} ${sys_ldflags}") + set_target_properties(acl_cpp_shared PROPERTIES OUTPUT_NAME "acl_cpp") + target_link_libraries(acl_cpp_shared protocol acl) + endif() if(CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Darwin") install(TARGETS acl_cpp_shared diff --git a/lib_fiber/c/CMakeLists.txt b/lib_fiber/c/CMakeLists.txt index bc4e547ec..2210b004f 100644 --- a/lib_fiber/c/CMakeLists.txt +++ b/lib_fiber/c/CMakeLists.txt @@ -1,5 +1,5 @@ -#cmake_minimum_required(VERSION 3.2.0) -cmake_minimum_required(VERSION 2.8.0) +cmake_minimum_required(VERSION 3.2.0) +#cmake_minimum_required(VERSION 2.8.0) project(fiber) #set(CMAKE_BUILD_TYPE Release) @@ -82,6 +82,9 @@ elseif (${WIN_OS}) "-DACL_WRITEABLE_CHECK" "-D_CRT_SECURE_NO_WARNINGS" "-DACL_PREPARE_COMPILE") + if (ACL_BUILD_SHARED MATCHES "YES") + add_definitions("-DFIBER_DLL -DFIBER_EXPORTS") + endif() endif() #if (CMAKE_BUILD_TYPE STREQUAL "") @@ -148,9 +151,13 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${lib_output_path}) add_library(fiber_static STATIC ${lib_src}) if (${WIN_OS}) - SET_TARGET_PROPERTIES(fiber_static PROPERTIES OUTPUT_NAME "libfiber") + set_target_properties(fiber_static PROPERTIES + OUTPUT_NAME "libfiber" + ARCHIVE_OUTPUT_DIRECTORY ${lib_output_path}/static + LIBRARY_OUTPUT_DIRECTORY ${lib_output_path}/static + ) else() - SET_TARGET_PROPERTIES(fiber_static PROPERTIES OUTPUT_NAME "fiber") + set_target_properties(fiber_static PROPERTIES OUTPUT_NAME "fiber") endif() link_directories(${lib_output_path}) @@ -188,9 +195,24 @@ if (ACL_BUILD_SHARED MATCHES "YES") endif() endif() - set(CMAKE_SHARED_LINKER_FLAGS "${sys_ldflags}") + if (${WIN_OS}) + link_directories(${lib_output_path}/shared) + endif() + add_library(fiber_shared SHARED ${lib_src}) - SET_TARGET_PROPERTIES(fiber_shared PROPERTIES OUTPUT_NAME "fiber") + + if (${WIN_OS}) + set_target_properties(fiber_shared PROPERTIES + OUTPUT_NAME "libfiber" + RUNTIME_OUTPUT_DIRECTORY ${lib_output_path}/shared + ARCHIVE_OUTPUT_DIRECTORY ${lib_output_path}/shared + LIBRARY_OUTPUT_DIRECTORY ${lib_output_path}/shared + ) + set(CMAKE_SHARED_LINKER_FLAGS "${sys_ldflags}") + else() + set_target_properties(fiber_shared PROPERTIES OUTPUT_NAME "fiber") + set(CMAKE_SHARED_LINKER_FLAGS "${sys_ldflags}") + endif() if(CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Darwin") install(TARGETS fiber_shared diff --git a/lib_fiber/cpp/CMakeLists.txt b/lib_fiber/cpp/CMakeLists.txt index 5139a3987..3258e446b 100644 --- a/lib_fiber/cpp/CMakeLists.txt +++ b/lib_fiber/cpp/CMakeLists.txt @@ -1,5 +1,5 @@ -#cmake_minimum_required(VERSION 3.2.0) -cmake_minimum_required(VERSION 2.8.0) +cmake_minimum_required(VERSION 3.2.0) +#cmake_minimum_required(VERSION 2.8.0) project(fiber_cpp) #set(CMAKE_BUILD_TYPE Release) @@ -72,6 +72,11 @@ elseif (${WIN_OS}) "-D_WINSOCK_DEPRECATED_NO_WARNINGS" "-DACL_WRITEABLE_CHECK" "-DACL_PREPARE_COMPILE") + if (ACL_BUILD_SHARED MATCHES "YES") + add_definitions("-DFIBER_CPP_DLL -DFIBER_CPP_EXPORTS" + "-DACL_DLL -DHTTP_DLL -DICMP_DLL -DSMTP_DLL -DACL_CPP_DLL -DFIBER_DLL" + ) + endif() endif() #if (CMAKE_BUILD_TYPE STREQUAL "") @@ -111,7 +116,7 @@ include_directories( ) if (${WIN_OS}) - set(sources ${src}) + set(sources ${src} ${src}/detours) else() set(sources ${src} ${src}/keeper) endif() @@ -135,9 +140,13 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${lib_output_path}) add_library(fiber_cpp_static STATIC ${lib_src}) if (${WIN_OS}) - SET_TARGET_PROPERTIES(fiber_cpp_static PROPERTIES OUTPUT_NAME "libfiber_cpp") + set_target_properties(fiber_cpp_static PROPERTIES + OUTPUT_NAME "libfiber_cpp" + ARCHIVE_OUTPUT_DIRECTORY ${lib_output_path}/static + LIBRARY_OUTPUT_DIRECTORY ${lib_output_path}/static + ) else() - SET_TARGET_PROPERTIES(fiber_cpp_static PROPERTIES OUTPUT_NAME "fiber_cpp") + set_target_properties(fiber_cpp_static PROPERTIES OUTPUT_NAME "fiber_cpp") endif() link_directories(${lib_output_path}) @@ -178,12 +187,27 @@ if (ACL_BUILD_SHARED MATCHES "YES") -fvisibility=hidden -fvisibility-inlines-hidden) endif() - set(lc_ldflags "-Wl,-rpath,${CMAKE_INSTALL_PREFIX}/lib -L${lib_output_path}") - set(CMAKE_SHARED_LINKER_FLAGS "${lc_ldflags} ${sys_ldflags}") - add_library(fiber_cpp_shared SHARED ${lib_src}) - target_link_libraries(fiber_cpp_shared acl_cpp protocol acl fiber) + if (${WIN_OS}) + link_directories(${lib_output_path}/shared) + endif() - SET_TARGET_PROPERTIES(fiber_cpp_shared PROPERTIES OUTPUT_NAME "fiber_cpp") + add_library(fiber_cpp_shared SHARED ${lib_src}) + + if (${WIN_OS}) + set_target_properties(fiber_cpp_shared PROPERTIES + OUTPUT_NAME "libfiber_cpp" + RUNTIME_OUTPUT_DIRECTORY ${lib_output_path}/shared + ARCHIVE_OUTPUT_DIRECTORY ${lib_output_path}/shared + LIBRARY_OUTPUT_DIRECTORY ${lib_output_path}/shared + ) + set(CMAKE_SHARED_LINKER_FLAGS "${lc_ldflags} ${sys_ldflags}") + target_link_libraries(fiber_cpp_shared libacl_cpp libprotocol libacl libfiber Ws2_32) + else() + set_target_properties(fiber_cpp_shared PROPERTIES OUTPUT_NAME "fiber_cpp") + set(lc_ldflags "-Wl,-rpath,${CMAKE_INSTALL_PREFIX}/lib -L${lib_output_path}") + set(CMAKE_SHARED_LINKER_FLAGS "${lc_ldflags} ${sys_ldflags}") + target_link_libraries(fiber_cpp_shared acl_cpp protocol acl fiber) + endif() if(CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Darwin") install(TARGETS fiber_cpp_shared diff --git a/lib_fiber/cpp/src/detours/creatwth.cpp b/lib_fiber/cpp/src/detours/creatwth.cpp index 05e111ac1..0d7e03d98 100644 --- a/lib_fiber/cpp/src/detours/creatwth.cpp +++ b/lib_fiber/cpp/src/detours/creatwth.cpp @@ -467,7 +467,7 @@ static BOOL RecordExeRestore(HANDLE hProcess, HMODULE hModule, DETOUR_EXE_RESTOR #define IMAGE_THUNK_DATAXX IMAGE_THUNK_DATA32 #define UPDATE_IMPORTS_XX UpdateImports32 #define DETOURS_BITS_XX 32 -#include "uimports.cpp" +#include "deps/uimports.cpp" #undef DETOUR_EXE_RESTORE_FIELD_XX #undef DWORD_XX #undef IMAGE_NT_HEADERS_XX @@ -484,7 +484,7 @@ static BOOL RecordExeRestore(HANDLE hProcess, HMODULE hModule, DETOUR_EXE_RESTOR #define IMAGE_THUNK_DATAXX IMAGE_THUNK_DATA64 #define UPDATE_IMPORTS_XX UpdateImports64 #define DETOURS_BITS_XX 64 -#include "uimports.cpp" +#include "deps/uimports.cpp" #undef DETOUR_EXE_RESTORE_FIELD_XX #undef DWORD_XX #undef IMAGE_NT_HEADERS_XX diff --git a/lib_fiber/cpp/src/detours/uimports.cpp b/lib_fiber/cpp/src/detours/deps/uimports.cpp similarity index 100% rename from lib_fiber/cpp/src/detours/uimports.cpp rename to lib_fiber/cpp/src/detours/deps/uimports.cpp diff --git a/lib_protocol/CMakeLists.txt b/lib_protocol/CMakeLists.txt index 6531b6b80..b53ee8844 100644 --- a/lib_protocol/CMakeLists.txt +++ b/lib_protocol/CMakeLists.txt @@ -1,5 +1,5 @@ -#cmake_minimum_required(VERSION 3.2.0) -cmake_minimum_required(VERSION 2.8.0) +cmake_minimum_required(VERSION 3.2.0) +#cmake_minimum_required(VERSION 2.8.0) project(protocol) #set(CMAKE_BUILD_TYPE Release) @@ -119,6 +119,13 @@ elseif (${WIN_OS}) "-D_WINSOCK_DEPRECATED_NO_WARNINGS" "-DACL_WRITEABLE_CHECK" "-DACL_PREPARE_COMPILE") + if (ACL_BUILD_SHARED MATCHES "YES") + add_definitions("-DHTTP_DLL -DHTTP_EXPORTS" + "-DICMP_DLL -DICMP_EXPORTS" + "-DSMTP_DLL -DSMTP_EXPORTS" + "-DACL_DLL" + ) + endif() endif() if (CMAKE_SYSTEM_NAME MATCHES "Android") @@ -135,9 +142,13 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${lib_output_path}) add_library(protocol_static STATIC ${lib_src}) if (${WIN_OS}) - SET_TARGET_PROPERTIES(protocol_static PROPERTIES OUTPUT_NAME "libprotocol") + set_target_properties(protocol_static PROPERTIES + OUTPUT_NAME "libprotocol" + ARCHIVE_OUTPUT_DIRECTORY ${lib_output_path}/static + LIBRARY_OUTPUT_DIRECTORY ${lib_output_path}/static + ) else() - SET_TARGET_PROPERTIES(protocol_static PROPERTIES OUTPUT_NAME "protocol") + set_target_properties(protocol_static PROPERTIES OUTPUT_NAME "protocol") endif() link_directories(${lib_output_path}) @@ -178,12 +189,27 @@ if (ACL_BUILD_SHARED MATCHES "YES") endif() endif() - set(lc_flags "-Wl,-rpath,${CMAKE_INSTALL_PREFIX}/lib -L${lib_output_path}") - set(CMAKE_SHARED_LINKER_FLAGS "${lc_flags} ${sys_ldflags}") - add_library(protocol_shared SHARED ${lib_src}) - target_link_libraries(protocol_shared acl) + if (${WIN_OS}) + link_directories(${lib_output_path}/shared) + endif() - SET_TARGET_PROPERTIES(protocol_shared PROPERTIES OUTPUT_NAME "protocol") + add_library(protocol_shared SHARED ${lib_src}) + + if (${WIN_OS}) + set_target_properties(protocol_shared PROPERTIES + OUTPUT_NAME "libprotocol" + RUNTIME_OUTPUT_DIRECTORY ${lib_output_path}/shared + ARCHIVE_OUTPUT_DIRECTORY ${lib_output_path}/shared + LIBRARY_OUTPUT_DIRECTORY ${lib_output_path}/shared + ) + set(CMAKE_SHARED_LINKER_FLAGS "${lc_flags} ${sys_ldflags}") + target_link_libraries(protocol_shared libacl Ws2_32) + else() + set_target_properties(protocol_shared PROPERTIES OUTPUT_NAME "protocol") + set(lc_flags "-Wl,-rpath,${CMAKE_INSTALL_PREFIX}/lib -L${lib_output_path}") + set(CMAKE_SHARED_LINKER_FLAGS "${lc_flags} ${sys_ldflags}") + target_link_libraries(protocol_shared acl) + endif() if(CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Darwin") install(TARGETS protocol_shared