chore: update build script.

- update CMake build script to make install statement is more legal.
- add Windows-only build script for creating CMake used package and MSVC used package on Windows.
- documentation will be added in the next commit.
This commit is contained in:
yyc12345 2024-07-22 13:56:00 +08:00
parent 9e5bd370c4
commit 052fa7f4d1
7 changed files with 99 additions and 35 deletions

View File

@ -8,19 +8,18 @@ project(YYCC
option(YYCC_BUILD_TESTBENCH "Build testbench of YYCCommonplace." OFF)
option(YYCC_BUILD_DOC "Build document of YYCCommonplace." OFF)
# Detect MSVC IDE environment.
# If we in it, we should add configuration and build type in install path.
if (CMAKE_GENERATOR MATCHES "Visual Studio")
# Do Visual Studio specific
set(YYCC_INSTALL_PATH_LIB lib/${CMAKE_VS_PLATFORM_NAME}/$<CONFIG>)
set(YYCC_INSTALL_PATH_BIN bin/${CMAKE_VS_PLATFORM_NAME})
else()
# Other stuff
set(YYCC_INSTALL_PATH_LIB lib)
set(YYCC_INSTALL_PATH_BIN bin)
endif()
# Setup install path from CMake provided install path for convenient use.
include(GNUInstallDirs)
set(YYCC_INSTALL_INCLUDE_PATH ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH
"Public header install path relative to CMAKE_INSTALL_PREFIX unless set to an absolute path.")
set(YYCC_INSTALL_LIB_PATH ${CMAKE_INSTALL_LIBDIR} CACHE PATH
"Library install path relative to CMAKE_INSTALL_PREFIX unless set to an absolute path.")
set(YYCC_INSTALL_BIN_PATH ${CMAKE_INSTALL_BINDIR} CACHE PATH
"Binary install path relative to CMAKE_INSTALL_PREFIX unless set to an absolute path.")
set(YYCC_INSTALL_DOC_PATH ${CMAKE_INSTALL_DOCDIR} CACHE PATH
"Non-arch doc install path relative to CMAKE_INSTALL_PREFIX unless set to an absolute path.")
# Import 2 build targets
# Import 3 build targets
add_subdirectory(src)
if (YYCC_BUILD_TESTBENCH)
add_subdirectory(testbench)
@ -29,12 +28,12 @@ if (YYCC_BUILD_DOC)
add_subdirectory(doc)
endif ()
# Install project package infos
# Package target
# Install target and package
# Install target
install(EXPORT YYCCommonplaceTargets
FILE YYCCommonplaceTargets.cmake
NAMESPACE YYCC::
DESTINATION lib/cmake/YYCCommonplace
DESTINATION ${YYCC_INSTALL_LIB_PATH}/cmake/YYCCommonplace
)
# Package configuration file
include(CMakePackageConfigHelpers)
@ -46,14 +45,14 @@ write_basic_package_version_file(
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/YYCCommonplaceConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/YYCCommonplaceConfig.cmake"
INSTALL_DESTINATION lib/cmake/YYCCommonplace
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/YYCCommonplace
)
# Copy to install destination
# Copy package files to install destination
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/YYCCommonplaceConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/YYCCommonplaceConfigVersion.cmake"
DESTINATION
lib/cmake/YYCCommonplace
${CMAKE_INSTALL_LIBDIR}/cmake/YYCCommonplace
)

View File

@ -1,2 +1,7 @@
# Add the targets file
@PACKAGE_INIT@
# Include targets file
include("${CMAKE_CURRENT_LIST_DIR}/YYCCommonplaceTargets.cmake")
check_required_components(YYCCommonplace)

View File

@ -14,5 +14,5 @@ add_custom_target (YYCCDocumentation
# Install built documentation
install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html
DESTINATION doc
DESTINATION ${YYCC_INSTALL_DOC_PATH}
)

View File

@ -7,37 +7,48 @@ IF EXIST %README_PATH% (
EXIT /b
)
:: Create essential folder
:: Create main binary directory
MKDIR bin
CD bin
:: Create build folder
MKDIR Win32
MKDIR x64
MKDIR documentation
:: Create install folder
MKDIR install
CD install
MKDIR Win32_Debug
MKDIR Win32_Release
MKDIR x64_Debug
MKDIR x64_Release
CD ..
:: Build for Win32
CD Win32
cmake -G "Visual Studio 16 2019" -A Win32 -DYYCC_BUILD_TESTBENCH=ON ../..
cmake --build . --config Debug
cmake --install . --prefix=../install --config Debug
cmake --install . --prefix=../install/Win32_Debug --config Debug
cmake --build . --config Release
cmake --install . --prefix=../install --config Release
cmake --install . --prefix=../install/Win32_Release --config Release
CD ..
:: Build for x64
CD x64
cmake -G "Visual Studio 16 2019" -A x64 -DYYCC_BUILD_TESTBENCH=ON ../..
cmake --build . --config Debug
cmake --install . --prefix=../install --config Debug
cmake --install . --prefix=../install/x64_Debug --config Debug
cmake --build . --config Release
cmake --install . --prefix=../install --config Release
cmake --install . --prefix=../install/x64_Release --config Release
CD ..
:: Build for documentation
CD documentation
cmake -DYYCC_BUILD_DOC=ON ../..
cmake -G "Visual Studio 16 2019" -A x64 -DYYCC_BUILD_DOC=ON ../..
cmake --build . --config Release
cmake --build . --target YYCCDocumentation
cmake --install . --prefix=../install
cmake --install . --prefix=../install/x64_Release --config Release
CD ..
ECHO DONE
:: Exit to original path
CD ..
ECHO Windows CMake Build Done

50
script/win_msvc_build.bat Normal file
View File

@ -0,0 +1,50 @@
@ECHO OFF
SET README_PATH=%CD%\README.md
IF EXIST %README_PATH% (
REM DO NOTHING
) ELSE (
ECHO Error: You must run this script at the root folder of this project!
EXIT /b
)
:: Enter main binary directory
CD bin
:: Create MSVC binary directory
MKDIR msvc_install
CD msvc_install
:: Create direcotries tree
MKDIR bin
MKDIR include
MKDIR lib
MKDIR share
CD bin
MKDIR Win32
MKDIR x64
CD ..
CD lib
MKDIR Win32\Debug
MKDIR Win32\Release
MKDIR x64\Debug
MKDIR x64\Release
CD ..
:: Exit MSVC binary directory
CD ..
:: Copy result
:: Copy include from x64_Release build
XCOPY install\x64_Release\include msvc_install\include\ /E /Y
:: Copy document from x64_Release build
XCOPY install\x64_Release\share msvc_install\share\ /E /Y
:: Copy binary testbench
COPY install\Win32_Release\bin\YYCCTestbench.exe msvc_install\bin\Win32\YYCCTestbench.exe /Y
COPY install\x64_Release\bin\YYCCTestbench.exe msvc_install\bin\x64\YYCCTestbench.exe /Y
:: Copy static library
COPY install\Win32_Debug\lib\YYCCommonplace.lib msvc_install\lib\Win32\Debug\YYCCommonplace.lib /Y
COPY install\Win32_Release\lib\YYCCommonplace.lib msvc_install\lib\Win32\Release\YYCCommonplace.lib /Y
COPY install\x64_Debug\lib\YYCCommonplace.lib msvc_install\lib\x64\Debug\YYCCommonplace.lib /Y
COPY install\x64_Release\lib\YYCCommonplace.lib msvc_install\lib\x64\Release\YYCCommonplace.lib /Y
:: Exit to original path
CD ..
ECHO Windows MSVC Build Done

View File

@ -74,8 +74,8 @@ PRIVATE
# Install binary and headers
install(TARGETS YYCCommonplace
EXPORT YYCCommonplaceTargets
LIBRARY DESTINATION ${YYCC_INSTALL_PATH_LIB}
ARCHIVE DESTINATION ${YYCC_INSTALL_PATH_LIB}
INCLUDES DESTINATION include
FILE_SET HEADERS DESTINATION include
LIBRARY DESTINATION ${YYCC_INSTALL_LIB_PATH}
ARCHIVE DESTINATION ${YYCC_INSTALL_LIB_PATH}
INCLUDES DESTINATION ${YYCC_INSTALL_INCLUDE_PATH}
FILE_SET HEADERS DESTINATION ${YYCC_INSTALL_INCLUDE_PATH}
)

View File

@ -35,7 +35,6 @@ PRIVATE
# Install testbench only on Release mode
install(TARGETS YYCCTestbench
EXPORT YYCCTestbenchTargets
CONFIGURATIONS Release
RUNTIME DESTINATION ${YYCC_INSTALL_PATH_BIN}
RUNTIME DESTINATION ${YYCC_INSTALL_BIN_PATH}
)