123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- #国密加解密库
- message(STATUS "***** Find SM Library *****")
- #寻找头文件
- unset(SM_INCLUDE_DIR CACHE)
- find_path(SM_INCLUDE_DIR
- NAMES smclass.h
- PATHS ${CMAKE_CURRENT_LIST_DIR}/inc
- NO_DEFAULT_PATH
- )
- #查找源文件
- # find_path(SM_SOURCES_DIR
- # NAMES smclass.cpp
- # PATHS ${CMAKE_CURRENT_LIST_DIR}/src
- # NO_DEFAULT_PATH
- # )
- unset(SM_SOURCES CACHE)
- list(APPEND SM_SOURCES ${CMAKE_CURRENT_LIST_DIR}/src/smclass.cpp)
- #查找库文件,需要判断操作系统,位数
- if(CMAKE_SYSTEM_NAME MATCHES "Windows")
- if(CMAKE_SIZEOF_VOID_P EQUAL 8)
- if(CMAKE_BUILD_TYPE MATCHES "Debug")
- list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x64/with_debug_info/libSM_DLL.lib)
- list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x64/ucrtbased.dll)
- list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x64/vcruntime140d.dll)
- else()
- list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x64/libSM_DLL.lib)
- list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x64/ucrtbase.dll)
- list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x64/vcruntime140.dll)
- endif()
- elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
- if(CMAKE_BUILD_TYPE MATCHES "Debug")
- list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x86/with_debug_info/libSM_DLL.lib)
- list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x86/ucrtbased.dll)
- list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x86/vcruntime140d.dll)
- else()
- list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x86/libSM_DLL.lib)
- list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x86/ucrtbase.dll)
- list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/win/x86/vcruntime140.dll)
- endif()
- endif()
- #添加Linux版本
- elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
- if(CMAKE_BUILD_TYPE MATCHES "Debug")
- list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/linux/x64/libSM_Dll.so)
- else()
- list(APPEND SM_LIB_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/libs/linux/x64/libSM_Dll.so)
- endif()
- endif()
- # message(STATUS "SM_LIB_LIBRARY: ${SM_LIB_LIBRARY}")
- # message(STATUS "SM_INCLUDE_DIR: ${SM_INCLUDE_DIR}")
- # message(STATUS "SM_SOURCES: ${SM_SOURCES}")
- # message(STATUS "SM_LIB_LIBRARY: ${SM_LIB_LIBRARY}")
- #设置查找到后的变量
- if(SM_INCLUDE_DIR AND SM_SOURCES AND SM_LIB_LIBRARY)
- set(SM_FOUND TRUE)
- set(SM_VERSION "1.1.0")
- # message(STATUS "include : SM_INCLUDE_DIR")
- # message(STATUS "source : SM_SOURCES_DIR")
- # message(STATUS "Library : SM_LIB_LIBRARY")
- message(STATUS "target_link_directories(External::sm)")
- else()
- set(SM_FOUND FALSE)
- endif()
- message(STATUS "SM_LIBRARY FOUND: ${SM_FOUND}")
- message(STATUS "SM_LIBRARY Version: ${SM_VERSION}")
- message(STATUS "--------------------------------------------------")
- #导入目标
- if(SM_FOUND)
- if(NOT TARGET External::sm)
- add_library(External::sm UNKNOWN IMPORTED)
- #添加头文件
- set_target_properties(External::sm PROPERTIES
- INTERFACE_INCLUDE_DIRECTORIES "${SM_INCLUDE_DIR}")
- #添加库文件
- set_target_properties(External::sm PROPERTIES
- IMPORTED_LOCATION "${SM_LIB_LIBRARY}")
- #添加spdlog需要的依赖库
- # set_target_properties(External::sm PROPERTIES
- # INTERFACE_LINK_LIBRARIES "pthread")
- #添加源文件
- set_target_properties(External::sm PROPERTIES
- INTERFACE_SOURCES "${SM_SOURCES}")
- endif()
- endif()
- # 标记这些变量为高级变量
- mark_as_advanced(
- SM_INCLUDE_DIR
- SM_LIB_LIBRARY
- SM_SOURCES
- )
|