cmake_minimum_required(VERSION 3.14)
# name
set(MY_PROJECT_NAME mmbase)
#
project(${MY_PROJECT_NAME} LANGUAGES CXX)
#
message ("cmake:${PROJECT_NAME}")
#
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# debug suffix -d
set(CMAKE_DEBUG_POSTFIX -d)
# copy to
set(MY_SOURCE_LIB_DIR "${PROJECT_SOURCE_DIR}/../lib/")
# default Release
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE "Release")
message (
STATUS "${PROJECT_NAME} no CMAKE_BUILD_TYPE selected, defaulting to ${CMAKE_BUILD_TYPE} "
)
endif()
#
add_library(${PROJECT_NAME} SHARED
logs.h
logs.cpp
)
# windows c++ dll导出宏
target_compile_definitions(${PROJECT_NAME} PRIVATE MMBASE_LIBRARY=1)
# vs unicode
if(MSVC)
add_definitions("-DUNICODE" "-D_UNICODE")
target_compile_options(${PROJECT_NAME} PUBLIC "/ZI")
target_link_options(${PROJECT_NAME} PUBLIC "/INCREMENTAL")
endif()
# 生成后复制
if (WIN32)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD # Adds a post-build event to MyTest
COMMAND ${CMAKE_COMMAND} -E copy_if_different # which executes "cmake - E copy_if_different..."
"$<$<CONFIG:Debug>:debug/${PROJECT_NAME}-d.lib>" # <--this is in-file
"$<$<CONFIG:Release>:release/${PROJECT_NAME}.lib>" # <--this is in-file
"${MY_SOURCE_LIB_DIR}") # <--this is out-file path
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<$<CONFIG:Debug>:debug/${PROJECT_NAME}-d.dll>"
"$<$<CONFIG:Release>:release/${PROJECT_NAME}.dll>"
"${MY_SOURCE_LIB_DIR}")
else() # (WIN32)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<$<CONFIG:Debug>:lib${PROJECT_NAME}-d.so>"
"$<$<CONFIG:Release>:lib${PROJECT_NAME}.so>"
"${MY_SOURCE_LIB_DIR}")
endif() # (WIN32)
导出类声名
#if defined (WIN32) || defined(WIN64)
// windows
#if defined(MMBASE_LIBRARY)
# define MMBASESHARED_EXPORT __declspec(dllexport)
#else
# define MMBASESHARED_EXPORT __declspec(dllimport)
#endif
#else // defined (WIN32) || defined(WIN64)
// linux
# define MMBASESHARED_EXPORT
#endif // defined (WIN32) || defined(WIN64)
class MMBASESHARED_EXPORT Logs
{
}
本博客所有文章除特别声明外,均采用CC BY-NC-SA 4.0 许可协议。转载请注明来自 张拓的博客!