From 46d4bd8a5947d1cb09ce99b687ccd598cb7fc7a6 Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Thu, 11 Nov 2021 14:01:20 +0800 Subject: [PATCH] feat(windows): let sdk do not care about more macro on win GitOrigin-RevId: c522c2fd632b8b908e1c5641fad43f231c597d3a --- imperative/CMakeLists.txt | 1 - lite/CMakeLists.txt | 6 ------ lite/load_and_run/CMakeLists.txt | 4 ---- src/CMakeLists.txt | 4 ---- src/megbrain_build_config.h.in | 14 ++++---------- test/CMakeLists.txt | 3 +++ 6 files changed, 7 insertions(+), 25 deletions(-) diff --git a/imperative/CMakeLists.txt b/imperative/CMakeLists.txt index 8561187d5..cf1a8c354 100644 --- a/imperative/CMakeLists.txt +++ b/imperative/CMakeLists.txt @@ -29,7 +29,6 @@ if (APPLE) target_link_libraries(${MODULE_NAME} PRIVATE megengine_shared) elseif (MSVC OR WIN32) target_link_libraries(${MODULE_NAME} PRIVATE megengine_shared) - target_compile_definitions(${MODULE_NAME} PRIVATE MGE_DLL_IMPORT_DATA) message(STATUS "CMAKE_MSVC_RUNTIME_LIBRARY: ${CMAKE_MSVC_RUNTIME_LIBRARY}") set_target_properties(${MODULE_NAME} PROPERTIES MSVC_RUNTIME_LIBRARY "${CMAKE_MSVC_RUNTIME_LIBRARY}") else() diff --git a/lite/CMakeLists.txt b/lite/CMakeLists.txt index da4653883..b0966ea89 100644 --- a/lite/CMakeLists.txt +++ b/lite/CMakeLists.txt @@ -46,9 +46,6 @@ include_directories($) if(LITE_BUILD_WITH_MGE) target_link_libraries(lite_static PRIVATE megbrain megdnn ${MGE_CUDA_LIBS}) add_compile_definitions(LITE_BUILD_WITH_MGE=1) - if(WIN32 OR MSVC) - target_compile_definitions(lite_static PRIVATE MGE_DLL_IMPORT_DATA) - endif() message(STATUS "build lite with MegEngine.") else() target_link_libraries(lite_static PUBLIC flatbuffers) @@ -83,9 +80,6 @@ if(LITE_BUILD_WITH_MGE) else() target_link_libraries(lite_shared_whl PRIVATE megengine_shared) endif() - if(WIN32 OR MSVC) - target_compile_definitions(lite_shared_whl PRIVATE MGE_DLL_IMPORT_DATA) - endif() endif() if(ANDROID) target_link_libraries(lite_shared_whl PRIVATE log) diff --git a/lite/load_and_run/CMakeLists.txt b/lite/load_and_run/CMakeLists.txt index ad50c715e..d7b5b9d91 100644 --- a/lite/load_and_run/CMakeLists.txt +++ b/lite/load_and_run/CMakeLists.txt @@ -33,10 +33,6 @@ if(BUILD_SHARED_LIBS) target_link_libraries(load_and_run_depends_shared gflags) target_link_libraries(load_and_run_depends_shared megengine) - if(WIN32 OR MSVC) - target_compile_definitions(load_and_run_depends_shared PRIVATE MGE_DLL_IMPORT_DATA) - endif() - if(LITE_BUILD_WITH_RKNPU) #rknn sdk1.0.0 depend on libc++_shared, use gold to remove NEEDED so symbol check target_link_options(load_and_run_depends_shared PRIVATE "-fuse-ld=gold") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3a8340152..57664c747 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -224,10 +224,6 @@ if(WIN32 OR MSVC) target_compile_definitions(megdnn PRIVATE MGE_DLL_EXPORT) target_compile_definitions(megengine PRIVATE MGE_DLL_EXPORT) target_compile_definitions(megengine_shared PRIVATE MGE_DLL_EXPORT) - target_compile_definitions(megbrain PRIVATE MGE_DLL_EXPORT_DATA) - target_compile_definitions(megdnn PRIVATE MGE_DLL_EXPORT_DATA) - target_compile_definitions(megengine PRIVATE MGE_DLL_EXPORT_DATA) - target_compile_definitions(megengine_shared PRIVATE MGE_DLL_EXPORT_DATA) # please do not use WINDOWS_EXPORT_ALL_SYMBOLS, as symbols max than 65535 when build with CUDA #set_target_properties(megengine PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) #set_target_properties(megengine_shared PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) diff --git a/src/megbrain_build_config.h.in b/src/megbrain_build_config.h.in index 3be29df3f..d0e31de29 100644 --- a/src/megbrain_build_config.h.in +++ b/src/megbrain_build_config.h.in @@ -253,22 +253,16 @@ #ifdef WIN32 #ifdef MGE_DLL_EXPORT #define MGE_WIN_DECLSPEC_FUC __declspec(dllexport) -#else +#define MGE_WIN_DECLSPEC_DATA __declspec(dllexport) +#elif defined(MGE_WINDOWS_STATIC_LINK) #define MGE_WIN_DECLSPEC_FUC -#endif +#define MGE_WIN_DECLSPEC_DATA #else #define MGE_WIN_DECLSPEC_FUC -#endif - -#ifdef WIN32 -#if defined(MGE_DLL_EXPORT_DATA) -#define MGE_WIN_DECLSPEC_DATA __declspec(dllexport) -#elif defined(MGE_DLL_IMPORT_DATA) #define MGE_WIN_DECLSPEC_DATA __declspec(dllimport) -#else -#define MGE_WIN_DECLSPEC_DATA #endif #else +#define MGE_WIN_DECLSPEC_FUC #define MGE_WIN_DECLSPEC_DATA #endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2b13c9b45..dd4b2c7e3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -16,6 +16,9 @@ if (MGE_WITH_CUDA AND MGE_WITH_TRT) endif() add_executable(megbrain_test ${SOURCES}) +if(WIN32 OR MSVC) + target_compile_definitions(megbrain_test PRIVATE MGE_WINDOWS_STATIC_LINK) +endif() target_link_libraries(megbrain_test gtest gmock) target_link_libraries(megbrain_test megbrain megdnn ${MGE_CUDA_LIBS}) if (MGE_WITH_CUDA) -- GitLab