You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
4.4 KiB
CMake

project(${library_name} VERSION ${version_info} LANGUAGES CXX)
message(STATUS "begin ${library_name} version ${version_info}")
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
set(linked_library ${linked_library})
#设置输出目录
set_target_properties(${target_name}
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/libs"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/libs"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/libs"
FOLDER "lib")
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/../debug1)
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/../debug1)
#set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/bin")
#find_package(Qt5 5.9.9 EXACT COMPONENTS Core Sql Xml REQUIRED)
option(ENABLE_SOLUTION_FOLDERS "ENABLE_SOLUTION_FOLDERS" ON)
if(ENABLE_SOLUTION_FOLDERS)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMakeTargets")
endif()
#targetName
string(TOUPPER ${library_name} ExportName)
set(dllexport_local ${ExportName}_EXPORT)
#配置根据文件生成rc文件
#string(REGEX REPLACE "/$" "" CURRENT_FOLDER_ABSOLUTE ${CMAKE_CURRENT_SOURCE_DIR})
# get current relative dir name and set target name
set(config_utils_path ${CMAKE_CURRENT_SOURCE_DIR}/../utils)
#message(STATUS "config path ${config_utils_path}")
#message(STATUS "target source ${PROJECT_SOURCE_DIR}")
set(config_target_path ${PROJECT_SOURCE_DIR}/include)
set(export_name ${dllexport_local})
set(export_config_utils_path "${config_target_path}/config.h")
set(export_file_path "${config_target_path}/export_${library_name}.h")
if(BUILD_SHARED_LIBS)
configure_file("${config_utils_path}/export_define.h.in" ${export_file_path})
else()
configure_file("${config_utils_path}/export_define_null.h.in" ${export_file_path})
endif()
configure_file("${config_utils_path}/config.h.in" ${export_config_utils_path})
set(version_file_path "${CMAKE_CURRENT_SOURCE_DIR}/src/version.rc")
if(MSVC)
set(PRODUCT_NAME "LasTop ${library_name} Application")
set(LegalCopyRight "Copyright(C) 2022/8/17")
set(VERSION_REVISION 1)
configure_file("${config_utils_path}/version.rc.icon.in" "${version_file_path}")
endif(MSVC)
#add_subdirectory(thrid-lib)
set(version_file_path ${CMAKE_CURRENT_SOURCE_DIR}/src/version.rc)
add_executable(${library_name} ${version_file_path})
if (DEFINED Copy_Solution)
#拷贝代码目录
FILE(COPY ${inc_files}
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/include)
FILE(COPY ${src_files}
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/src)
#拷贝工程文件
FILE(COPY ${config_utils_path}/base.cmake DESTINATION ${CMAKE_CURRENT_SOURCE_DIR})
FILE(COPY ${config_utils_path}/install.cmake DESTINATION ${CMAKE_CURRENT_SOURCE_DIR})
FILE(COPY ${config_utils_path}/pack.cmake DESTINATION ${CMAKE_CURRENT_SOURCE_DIR})
endif()
set(inc_files ${inc_files} ${export_file_path})
set(src_files ${src_files} files.cmake install.cmake base.cmake pack.cmake)
#message("inc files" ${inc_files})
#target_link_libraries(${library_name} CSerialPort)
# remove prefix
set_target_properties(${library_name} PROPERTIES PREFIX "")
target_include_directories(${library_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(${library_name} PRIVATE ${include_directory})
target_include_directories(${library_name}
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include/${library_name}>
)
get_target_property(include_path ${library_name} INCLUDE_DIRECTORIES)
#message("include_path${include_path}")
target_sources(${library_name} PRIVATE ${export_config_utils_path} ${inc_files} ${src_files})
target_link_libraries(${library_name} ${linked_library})
set_target_properties (${library_name} PROPERTIES DEBUG_POSTFIX d)
target_compile_definitions(${library_name} PRIVATE ${dllexport_local}D)
#set_target_properties(${library_name} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/inc)
if (DEFINED Copy_Solution)
include(${config_utils_path}/install.cmake)
include(${config_utils_path}/pack.cmake)
else()
include(install.cmake)
include(pack.cmake)
endif()
message(STATUS "finish ${library_name}")
set_target_properties(${library_name} PROPERTIES
WIN32_EXECUTABLE YES
LINK_FLAGS "/ENTRY:mainCRTStartup")