cmake/modules: 增加 NOTEPAD_BUILD_BY_SHARED 构建配方

增加 utils.cmake 进行获取在不同平台构建时的目标库的名称
This commit is contained in:
zinface 2023-02-22 14:40:16 +08:00
parent b531ed598c
commit fc50cf38a2
5 changed files with 67 additions and 7 deletions

View File

@ -18,7 +18,7 @@
set(NOTEPAD_PLUGIN @NOTEPAD_PLUGIN@)
set(NOTEPAD_BUILD_BY_QT5 @NOTEPAD_BUILD_BY_QT5@)
set(NOTEPAD_BUILD_BY_QT6 @NOTEPAD_BUILD_BY_QT6@)
set(NOTEPAD_BUILD_BY_SHARED FALSE)
set(NOTEPAD_BUILD_BY_SHARED @NOTEPAD_BUILD_BY_SHARED@)
set(NOTEPAD_PLUGIN_CORELIB @NOTEPAD_PLUGIN_CORELIB@)
# "Notepad 提供的插件安装目录(位置)"
set(NOTEPAD_PLUGIN_EXTERNAL_PLUGIN_INSTALL_DIRECTORY
@ -196,17 +196,18 @@ macro(add_notepad_plugin PLUGIN_VAR PLUGIN_SRC)
# NOTEPAD_PLUGIN_MANAGER
# Notepad--
if(WIN32)
if(WIN32 AND NOTEPAD_BUILD_BY_SHARED)
target_compile_definitions(${PLUGIN_VAR}
PUBLIC
NOTEPAD_PLUGIN_MANAGER
QSCINTILLA_DLL # Windows 使 QSci Q_DECL_IMPORT
# QSCINTILLA_EXPORT Q_DECL_IMPORT
# QSCINTILLA_DLL #
)
else()
target_compile_definitions(${PLUGIN_VAR}
PUBLIC NOTEPAD_PLUGIN_MANAGER)
endif(WIN32)
PUBLIC
NOTEPAD_PLUGIN_MANAGER)
endif(WIN32 AND NOTEPAD_BUILD_BY_SHARED)
endmacro(add_notepad_plugin PLUGIN_VAR PLUGIN_SRC)

View File

@ -4,6 +4,8 @@
# 1. libQSci.a
# 2. QSci
option(NOTEPAD_BUILD_BY_SHARED "指定 Notepad 将构建为动态库" OFF)
if(TRUE)
# add_subdirectory(${PROJECT_SOURCE_DIR}/src/qscint)
# file(GLOB MOC_HEADER src/qscint/src/Qsci/*.h)
@ -19,7 +21,11 @@ if(TRUE)
# src/qscint/src/Qsci
# FAIL: only *.ui will spark_file_glob(MOC_HEADER ...)
)
spark_add_library(QSci STATIC ${QSciSources} ${MOC_HEADER})
if(NOTEPAD_BUILD_BY_SHARED)
spark_add_library(QSci SHARED ${QSciSources} ${MOC_HEADER})
else()
spark_add_library(QSci STATIC ${QSciSources} ${MOC_HEADER})
endif(NOTEPAD_BUILD_BY_SHARED)
target_include_directories(QSci PRIVATE
src/qscint/scintilla/boostregex
src/qscint/scintilla/lexlib)

View File

@ -55,6 +55,12 @@ if(CMAKE_HOST_UNIX)
# CMake
set(NOTEPAD_PLUGIN_CORELIB QSci) # QSci QScintllia
#
include(cmake/platforms/utils.cmake)
get_current_platform_lib_name(NOTEPAD_PLUGIN_CORELIB_NAME
${NOTEPAD_BUILD_BY_SHARED}
QSci)
# CMake Notepad-- QT5
# Qt
# add_notepad_plugin
@ -108,3 +114,4 @@ if(CMAKE_HOST_UNIX)
# ------------------ INSTALL PLUGIN CONFIG ------------------ #
endif(CMAKE_HOST_UNIX)

View File

@ -0,0 +1,40 @@
# utils.cmake
#
# get_current_platform_lib_name <_VAR> <_IS_IS_SHREAD> <_LIB>
# _VAR
# _IS_IS_SHREAD
# _LIB
function(get_current_platform_lib_name _VAR _IS_SHREAD _LIB)
set(_LIB_NAME "")
if(WIN32)
set(_LIB_NAME ${_LIB}.lib)
elseif(UNIX AND NOT APPLE)
if(${_IS_SHREAD})
set(_LIB_NAME lib${_LIB}.so)
else()
set(_LIB_NAME lib${_LIB}.a)
endif(${_IS_SHREAD})
elseif(APPLE)
if(${_IS_SHREAD})
set(_LIB_NAME lib${_LIB}.dylib)
else()
set(_LIB_NAME lib${_LIB}.a)
endif(${_IS_SHREAD})
else()
message("ERROR: Unknow current platform")
set(_LIB_NAME ${_LIB})
endif()
message("[utils.cmake] get_current_platform_lib_name: ${_LIB}(${_LIB_NAME}) ")
set(${_VAR} ${_LIB_NAME} PARENT_SCOPE)
endfunction(get_current_platform_lib_name _VAR _IS_SHREAD _LIB)
# lib
# Windows
# .lib
# lib
# Linux
# .a .so
# lib
# MacOS
# .a .dylib
# lib

View File

@ -40,6 +40,12 @@ if(CMAKE_HOST_WIN32)
# CMake
set(NOTEPAD_PLUGIN_CORELIB QSci) # QSci QScintllia
#
include(cmake/platforms/utils.cmake)
get_current_platform_lib_name(NOTEPAD_PLUGIN_CORELIB_NAME
${NOTEPAD_BUILD_BY_SHARED}
QSci)
# CMake Notepad-- QT5
# Qt
# add_notepad_plugin