chore: update cmake build scripts

- update cmake build scripts
- the install part of build scripts may still have issues.
This commit is contained in:
yyc12345 2024-06-03 14:24:05 +08:00
parent 67bd445885
commit 642db411f5
4 changed files with 108 additions and 20 deletions

View File

@ -1,8 +1,38 @@
cmake_minimum_required(VERSION 3.12)
project(YYCCommonplace LANGUAGES CXX)
project(YYCC
VERSION 1.0.0
LANGUAGES CXX
)
# Add core static library in build
# Import 2 build targets
add_subdirectory(src)
# Add testbench code in build
add_subdirectory(testbench)
# Install project package infos
# Package target
install(EXPORT YYCCommonplaceTargets
FILE YYCCommonplaceTargets.cmake
NAMESPACE YYCC::
DESTINATION lib/cmake/YYCCommonplace
)
# Package configuration file
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
YYCCommonplaceConfigVersion.cmake
VERSION ${PACKAGE_VERSION}
COMPATIBILITY SameMinorVersion
)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/YYCCommonplaceConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/YYCCommonplaceConfig.cmake"
INSTALL_DESTINATION lib/cmake/YYCCommonplace
)
# Copy to install destination
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/YYCCommonplaceConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/YYCCommonplaceConfigVersion.cmake"
DESTINATION
lib/cmake/YYCCommonplace
)

View File

@ -0,0 +1,2 @@
# Add the targets file
include("${CMAKE_CURRENT_LIST_DIR}/YYCCommonplaceTargets.cmake")

View File

@ -1,23 +1,38 @@
# Setup file lists up
set(YYCC_HEADER ${CMAKE_CURRENT_LIST_DIR})
set(YYCC_SRC
ConsoleHelper.cpp
DialogHelper.cpp
EncodingHelper.cpp
ExceptionHelper.cpp
IOHelper.cpp
ParserHelper.cpp
StringHelper.cpp
)
# Create static library
add_library(YYCCommonplace
${YYCC_SRC}
add_library(YYCCommonplace STATIC "")
# Setup static library sources
target_sources(YYCCommonplace
PRIVATE
# Headers
# Common headers
${CMAKE_CURRENT_LIST_DIR}/ConsoleHelper.hpp
${CMAKE_CURRENT_LIST_DIR}/DialogHelper.hpp
${CMAKE_CURRENT_LIST_DIR}/EncodingHelper.hpp
${CMAKE_CURRENT_LIST_DIR}/ExceptionHelper.hpp
${CMAKE_CURRENT_LIST_DIR}/IOHelper.hpp
${CMAKE_CURRENT_LIST_DIR}/ParserHelper.hpp
${CMAKE_CURRENT_LIST_DIR}/StringHelper.hpp
# Windows including guard pair
${CMAKE_CURRENT_LIST_DIR}/WinImportPrefix.hpp
${CMAKE_CURRENT_LIST_DIR}/WinImportSuffix.hpp
# Misc
${CMAKE_CURRENT_LIST_DIR}/YYCCInternal.hpp
${CMAKE_CURRENT_LIST_DIR}/YYCCommonplace.hpp
# Sources
${CMAKE_CURRENT_LIST_DIR}/ConsoleHelper.cpp
${CMAKE_CURRENT_LIST_DIR}/DialogHelper.cpp
${CMAKE_CURRENT_LIST_DIR}/EncodingHelper.cpp
${CMAKE_CURRENT_LIST_DIR}/ExceptionHelper.cpp
${CMAKE_CURRENT_LIST_DIR}/IOHelper.cpp
${CMAKE_CURRENT_LIST_DIR}/ParserHelper.cpp
${CMAKE_CURRENT_LIST_DIR}/StringHelper.cpp
)
# Setup header infomations
target_include_directories(YYCCommonplace
PUBLIC
${YYCC_HEADER}
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
# Setup C++ standard
set_target_properties(YYCCommonplace
@ -37,3 +52,32 @@ target_compile_options(YYCCommonplace
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/utf-8>
)
# Install project
# Install binary
install(TARGETS YYCCommonplace
EXPORT YYCCommonplaceTargets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)
# Install headers
install(
FILES
# Common headers
${CMAKE_CURRENT_LIST_DIR}/ConsoleHelper.hpp
${CMAKE_CURRENT_LIST_DIR}/DialogHelper.hpp
${CMAKE_CURRENT_LIST_DIR}/EncodingHelper.hpp
${CMAKE_CURRENT_LIST_DIR}/ExceptionHelper.hpp
${CMAKE_CURRENT_LIST_DIR}/IOHelper.hpp
${CMAKE_CURRENT_LIST_DIR}/ParserHelper.hpp
${CMAKE_CURRENT_LIST_DIR}/StringHelper.hpp
# Windows including guard pair
${CMAKE_CURRENT_LIST_DIR}/WinImportPrefix.hpp
${CMAKE_CURRENT_LIST_DIR}/WinImportSuffix.hpp
# Misc
${CMAKE_CURRENT_LIST_DIR}/YYCCInternal.hpp
${CMAKE_CURRENT_LIST_DIR}/YYCCommonplace.hpp
DESTINATION include
)

View File

@ -1,6 +1,9 @@
# Create executable testbench
add_executable(Testbench
main.cpp
add_executable(Testbench "")
# Setup testbench sources
target_sources(Testbench
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/main.cpp
)
# Add YYCC as its library
target_include_directories(Testbench
@ -23,3 +26,12 @@ target_compile_options(Testbench
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/utf-8>
)
# Install binary
install(TARGETS Testbench
EXPORT TestbenchTargets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)