You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
207 lines
5.4 KiB
207 lines
5.4 KiB
include(CMakeParseArguments)
|
|
# zadd_library(
|
|
#
|
|
# # #################### 目标文件 #################
|
|
# TARGET
|
|
# ...
|
|
#
|
|
# # #################### 依赖 ####################
|
|
# DEPENDENCIES
|
|
# ...
|
|
#
|
|
# # #################### 头文件路径 ###############
|
|
# INCLUDE_DIRECTORIES
|
|
# ...
|
|
#
|
|
# # #################### 链接的第三方库 ############
|
|
# LINK_LIBRARIES
|
|
# ...
|
|
#
|
|
# # #################### 源文件 ##################
|
|
# SRC
|
|
# ...
|
|
# )
|
|
|
|
function(zadd_library)
|
|
set(oneValueArgs NAME TARGET)
|
|
set(multiValueArgs
|
|
INSTALL
|
|
SRC
|
|
DEPENDENCIES
|
|
DEFINES
|
|
LINK_LIBRARIES
|
|
LINK_DIRECTORIES
|
|
INCLUDE_DIRECTORIES)
|
|
|
|
|
|
|
|
|
|
cmake_parse_arguments(ZAL "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
|
message("=================================================================")
|
|
message("= add_library: ${ZAL_TARGET}")
|
|
message("=================================================================")
|
|
message("CMAKE_C_COMPILER : ${CMAKE_C_COMPILER}")
|
|
message("CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
|
|
if(ZAL_TARGET)
|
|
message("ADD TARGET:${ZAL_TARGET}")
|
|
else()
|
|
message(FATAL_ERROR,"ZAL not set target")
|
|
endif()
|
|
|
|
if(ZAL_INSTALL)
|
|
message("INSTALL : ${ZAL_INSTALL}")
|
|
endif()
|
|
|
|
if(ZAL_SRC)
|
|
# message("SRC: ${ZAL_SRC}")
|
|
# message("SRC:")
|
|
# foreach(EACH ${ZAL_SRC})
|
|
# message(" ${EACH}")
|
|
# endforeach(EACH)
|
|
else()
|
|
message(FATAL_ERROR,"ZAL not set src")
|
|
endif()
|
|
|
|
add_library(${ZAL_TARGET} ${ZAL_SRC})
|
|
|
|
|
|
if(ZAL_DEFINES)
|
|
message("DEFINES:")
|
|
foreach(EACH ${ZAL_DEFINES})
|
|
message(" ${EACH}")
|
|
endforeach(EACH)
|
|
target_compile_definitions(${ZAL_TARGET} PRIVATE ${ZAL_DEFINES})
|
|
endif()
|
|
|
|
if(ZAL_DEPENDENCIES)
|
|
message("DEPENDENCIES:")
|
|
foreach(EACH ${ZAL_DEPENDENCIES})
|
|
message(" ${EACH}")
|
|
endforeach(EACH)
|
|
add_dependencies(${ZAL_TARGET} ${ZAL_DEPENDENCIES})
|
|
endif()
|
|
|
|
if(ZAL_LINK_LIBRARIES)
|
|
message("LINK_LIBRARIES:")
|
|
foreach(EACH ${ZAL_LINK_LIBRARIES})
|
|
message(" ${EACH}")
|
|
endforeach(EACH)
|
|
target_link_libraries(${ZAL_TARGET} ${ZAL_LINK_LIBRARIES})
|
|
endif()
|
|
|
|
if(ZAL_LINK_DIRECTORIES)
|
|
message("LINK_DIRECTORIES:")
|
|
foreach(EACH ${ZAL_LINK_DIRECTORIES})
|
|
message(" ${EACH}")
|
|
endforeach(EACH)
|
|
target_link_directories(${ZAL_TARGET} PRIVATE ${ZAL_LINK_DIRECTORIES})
|
|
endif()
|
|
|
|
if(ZAL_INCLUDE_DIRECTORIES)
|
|
message("INCLUDE_DIRECTORIES:")
|
|
foreach(EACH ${ZAL_INCLUDE_DIRECTORIES})
|
|
message(" ${EACH}")
|
|
endforeach(EACH)
|
|
target_include_directories(${ZAL_TARGET} PRIVATE ${ZAL_INCLUDE_DIRECTORIES})
|
|
endif()
|
|
|
|
if(ZAL_INSTALL)
|
|
install(TARGETS ${ZAL_TARGET} DESTINATION ${ZAL_INSTALL})
|
|
endif()
|
|
message("")
|
|
message("")
|
|
|
|
endfunction(zadd_library)
|
|
|
|
|
|
|
|
function(zadd_share_library)
|
|
set(oneValueArgs NAME TARGET)
|
|
set(multiValueArgs
|
|
INSTALL
|
|
SRC
|
|
DEPENDENCIES
|
|
DEFINES
|
|
LINK_LIBRARIES
|
|
LINK_DIRECTORIES
|
|
INCLUDE_DIRECTORIES)
|
|
|
|
|
|
|
|
|
|
cmake_parse_arguments(ZAL "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
|
message("=================================================================")
|
|
message("= add_library: ${ZAL_TARGET}")
|
|
message("=================================================================")
|
|
message("CMAKE_C_COMPILER : ${CMAKE_C_COMPILER}")
|
|
message("CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
|
|
if(ZAL_TARGET)
|
|
message("ADD TARGET:${ZAL_TARGET}")
|
|
else()
|
|
message(FATAL_ERROR,"ZAL not set target")
|
|
endif()
|
|
|
|
if(ZAL_INSTALL)
|
|
message("INSTALL : ${ZAL_INSTALL}")
|
|
endif()
|
|
|
|
if(ZAL_SRC)
|
|
# message("SRC: ${ZAL_SRC}")
|
|
# message("SRC:")
|
|
# foreach(EACH ${ZAL_SRC})
|
|
# message(" ${EACH}")
|
|
# endforeach(EACH)
|
|
else()
|
|
message(FATAL_ERROR,"ZAL not set src")
|
|
endif()
|
|
|
|
add_library(${ZAL_TARGET} SHARED ${ZAL_SRC})
|
|
|
|
|
|
if(ZAL_DEFINES)
|
|
message("DEFINES:")
|
|
foreach(EACH ${ZAL_DEFINES})
|
|
message(" ${EACH}")
|
|
endforeach(EACH)
|
|
target_compile_definitions(${ZAL_TARGET} PRIVATE ${ZAL_DEFINES})
|
|
endif()
|
|
|
|
if(ZAL_DEPENDENCIES)
|
|
message("DEPENDENCIES:")
|
|
foreach(EACH ${ZAL_DEPENDENCIES})
|
|
message(" ${EACH}")
|
|
endforeach(EACH)
|
|
add_dependencies(${ZAL_TARGET} ${ZAL_DEPENDENCIES})
|
|
endif()
|
|
|
|
if(ZAL_LINK_LIBRARIES)
|
|
message("LINK_LIBRARIES:")
|
|
foreach(EACH ${ZAL_LINK_LIBRARIES})
|
|
message(" ${EACH}")
|
|
endforeach(EACH)
|
|
target_link_libraries(${ZAL_TARGET} ${ZAL_LINK_LIBRARIES})
|
|
endif()
|
|
|
|
if(ZAL_LINK_DIRECTORIES)
|
|
message("LINK_DIRECTORIES:")
|
|
foreach(EACH ${ZAL_LINK_DIRECTORIES})
|
|
message(" ${EACH}")
|
|
endforeach(EACH)
|
|
target_link_directories(${ZAL_TARGET} PRIVATE ${ZAL_LINK_DIRECTORIES})
|
|
endif()
|
|
|
|
if(ZAL_INCLUDE_DIRECTORIES)
|
|
message("INCLUDE_DIRECTORIES:")
|
|
foreach(EACH ${ZAL_INCLUDE_DIRECTORIES})
|
|
message(" ${EACH}")
|
|
endforeach(EACH)
|
|
target_include_directories(${ZAL_TARGET} PRIVATE ${ZAL_INCLUDE_DIRECTORIES})
|
|
endif()
|
|
|
|
if(ZAL_INSTALL)
|
|
install(TARGETS ${ZAL_TARGET} DESTINATION ${ZAL_INSTALL})
|
|
endif()
|
|
message("")
|
|
message("")
|
|
|
|
endfunction(zadd_share_library)
|