使用CMake构建boundscheck库

15,165 views

libboundscheck库,提供了众多安全C方法的实现,在gitee开源。
当前项目维护者只提供了传统的Makefile形式的构建方式,比较简单,但在Windows平台使用时多有不便。
CMake是当前比较热门的跨平台构建系统工具,平时在工作中应用比较多,因此基于业余时间,开发了CMake构建脚本。
当前已归档至个人仓库,欢迎各位朋友试用。

配置项目的输出,如下:

$ cmake -B build -S .
-- The C compiler identification is GNU 11.2.0
-- The CXX compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- SYSTEM                  :MSYS
-- CXX Compiler            :GNU
-- C Compiler              :GNU
-- CMAKE_SYSTEM_VERSION    :3.3.3-341.x86_64
-- CMAKE_SYSTEM_NAME       :MSYS
-- CMAKE_SYSTEM            :MSYS-3.3.3-341.x86_64
-- CMAKE_HOST_SYSTEM_NAME  :MSYS
-- CMAKE_HOST_SYSTEM       :MSYS-3.3.3-341.x86_64
-- LINUX                   :
-- UNIX                    :1
-- MINGW                   :
-- MSVC                    :
-- WIN32                   :
-- Looking for errno.h
-- Looking for errno.h - found
-- Looking for memory.h
-- Looking for memory.h - found
-- Looking for stdarg.h
-- Looking for stdarg.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Looking for stdio.h
-- Looking for stdio.h - found
-- Looking for stdlib.h
-- Looking for stdlib.h - found
-- Looking for string.h
-- Looking for string.h - found
-- Looking for wchar.h
-- Looking for wchar.h - found
-- Looking for ctype.h
-- Looking for ctype.h - found
-- Looking for wctype.h
-- Looking for wctype.h - found
-- Looking for memset_s
-- Looking for memset_s - not found
-- Looking for memmove_s
-- Looking for memmove_s - not found
-- Looking for memcpy_s
-- Looking for memcpy_s - not found
-- Looking for strcpy_s
-- Looking for strcpy_s - not found
-- Looking for strncpy_s
-- Looking for strncpy_s - not found
-- Looking for strcat_s
-- Looking for strcat_s - not found
-- Looking for strncat_s
-- Looking for strncat_s - not found
-- Looking for sprintf_s
-- Looking for sprintf_s - not found
-- Looking for snprintf_s
-- Looking for snprintf_s - not found
-- Looking for strtok_s
-- Looking for strtok_s - not found
-- Looking for gets_s
-- Looking for gets_s - not found
-- Looking for wmemmove_s
-- Looking for wmemmove_s - not found
-- Looking for wmemcpy_s
-- Looking for wmemcpy_s - not found
-- Looking for wcscpy_s
-- Looking for wcscpy_s - not found
-- Looking for wcsncpy_s
-- Looking for wcsncpy_s - not found
-- Looking for wcscat_s
-- Looking for wcscat_s - not found
-- Looking for wcsncat_s
-- Looking for wcsncat_s - not found
-- Looking for wcstok_s
-- Looking for wcstok_s - not found
-- Looking for scanf_s
-- Looking for scanf_s - not found
-- Looking for vscanf_s
-- Looking for vscanf_s - not found
-- Looking for vsprintf_s
-- Looking for vsprintf_s - not found
-- Looking for vsnprintf_s
-- Looking for vsnprintf_s - not found
-- Looking for sscanf_s
-- Looking for sscanf_s - not found
-- Looking for vsscanf_s
-- Looking for vsscanf_s - not found
-- Looking for fscanf_s
-- Looking for fscanf_s - not found
-- Looking for vfscanf_s
-- Looking for vfscanf_s - not found
-- Looking for vswprintf_s
-- Looking for vswprintf_s - not found
-- Looking for swprintf_s
-- Looking for swprintf_s - not found
-- Looking for wscanf_s
-- Looking for wscanf_s - not found
-- Looking for vwscanf_s
-- Looking for vwscanf_s - not found
-- Looking for swscanf_s
-- Looking for swscanf_s - not found
-- Looking for vswscanf_s
-- Looking for vswscanf_s - not found
-- Looking for fwscanf_s
-- Looking for fwscanf_s - not found
-- Looking for vfwscanf_s
-- Looking for vfwscanf_s - not found
-- Performing Test SECUREC_HAVE_WCHAR_T_RUN
-- Performing Test SECUREC_HAVE_WCHAR_T_RUN - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /d/workspace/gitee/libboundscheck/build

构建项目的输出,如下:

$ cmake --build build -j8
Consolidate compiler generated dependencies of target boundscheck
[  1%] Building C object CMakeFiles/boundscheck_static.dir/src/securecutil.c.o
[  2%] Building C object CMakeFiles/boundscheck_static.dir/src/secureinput_a.c.o
[  3%] Building C object CMakeFiles/boundscheck_static.dir/src/secureinput_w.c.o
[  5%] Building C object CMakeFiles/boundscheck_static.dir/src/secureprintoutput_a.c.o
[  6%] Building C object CMakeFiles/boundscheck_static.dir/src/secureprintoutput_w.c.o
[  7%] Building C object CMakeFiles/boundscheck_static.dir/src/snprintf_s.c.o
[  8%] Building C object CMakeFiles/boundscheck.dir/src/secureprintoutput_a.c.o
[ 10%] Building C object CMakeFiles/boundscheck_static.dir/src/vsnprintf_s.c.o
[ 11%] Building C object CMakeFiles/boundscheck.dir/src/secureprintoutput_w.c.o
[ 12%] Building C object CMakeFiles/boundscheck_static.dir/src/fscanf_s.c.o
[ 13%] Building C object CMakeFiles/boundscheck_static.dir/src/fwscanf_s.c.o
[ 15%] Building C object CMakeFiles/boundscheck.dir/src/snprintf_s.c.o
[ 16%] Building C object CMakeFiles/boundscheck_static.dir/src/gets_s.c.o
[ 18%] Building C object CMakeFiles/boundscheck.dir/src/vsnprintf_s.c.o
[ 18%] Building C object CMakeFiles/boundscheck_static.dir/src/memcpy_s.c.o
[ 20%] Building C object CMakeFiles/boundscheck.dir/src/fscanf_s.c.o
[ 21%] Building C object CMakeFiles/boundscheck_static.dir/src/memmove_s.c.o
[ 22%] Building C object CMakeFiles/boundscheck_static.dir/src/memset_s.c.o
[ 23%] Building C object CMakeFiles/boundscheck_static.dir/src/scanf_s.c.o
[ 25%] Building C object CMakeFiles/boundscheck_static.dir/src/sprintf_s.c.o
[ 26%] Building C object CMakeFiles/boundscheck.dir/src/fwscanf_s.c.o
[ 27%] Building C object CMakeFiles/boundscheck_static.dir/src/sscanf_s.c.o
[ 28%] Building C object CMakeFiles/boundscheck_static.dir/src/strcat_s.c.o
[ 30%] Building C object CMakeFiles/boundscheck.dir/src/gets_s.c.o
[ 31%] Building C object CMakeFiles/boundscheck.dir/src/memcpy_s.c.o
[ 32%] Building C object CMakeFiles/boundscheck.dir/src/memmove_s.c.o
[ 33%] Building C object CMakeFiles/boundscheck.dir/src/memset_s.c.o
[ 35%] Building C object CMakeFiles/boundscheck.dir/src/scanf_s.c.o
[ 36%] Building C object CMakeFiles/boundscheck_static.dir/src/strcpy_s.c.o
[ 37%] Building C object CMakeFiles/boundscheck.dir/src/sprintf_s.c.o
[ 38%] Building C object CMakeFiles/boundscheck_static.dir/src/strncat_s.c.o
[ 40%] Building C object CMakeFiles/boundscheck_static.dir/src/strncpy_s.c.o
[ 41%] Building C object CMakeFiles/boundscheck_static.dir/src/strtok_s.c.o
[ 42%] Building C object CMakeFiles/boundscheck.dir/src/sscanf_s.c.o
[ 43%] Building C object CMakeFiles/boundscheck.dir/src/strcat_s.c.o
[ 46%] Building C object CMakeFiles/boundscheck_static.dir/src/swprintf_s.c.o
[ 46%] Building C object CMakeFiles/boundscheck.dir/src/strcpy_s.c.o
[ 47%] Building C object CMakeFiles/boundscheck.dir/src/strncat_s.c.o
[ 48%] Building C object CMakeFiles/boundscheck.dir/src/strncpy_s.c.o
[ 50%] Building C object CMakeFiles/boundscheck.dir/src/strtok_s.c.o
[ 51%] Building C object CMakeFiles/boundscheck.dir/src/swprintf_s.c.o
[ 52%] Building C object CMakeFiles/boundscheck_static.dir/src/swscanf_s.c.o
[ 53%] Building C object CMakeFiles/boundscheck_static.dir/src/vfwscanf_s.c.o
[ 55%] Building C object CMakeFiles/boundscheck.dir/src/swscanf_s.c.o
[ 56%] Building C object CMakeFiles/boundscheck_static.dir/src/vsprintf_s.c.o
[ 57%] Building C object CMakeFiles/boundscheck_static.dir/src/vsscanf_s.c.o
[ 58%] Building C object CMakeFiles/boundscheck_static.dir/src/vswprintf_s.c.o
[ 60%] Building C object CMakeFiles/boundscheck_static.dir/src/vswscanf_s.c.o
[ 61%] Building C object CMakeFiles/boundscheck_static.dir/src/vwscanf_s.c.o
[ 62%] Building C object CMakeFiles/boundscheck.dir/src/vfwscanf_s.c.o
[ 63%] Building C object CMakeFiles/boundscheck_static.dir/src/wcscat_s.c.o
[ 65%] Building C object CMakeFiles/boundscheck.dir/src/vsprintf_s.c.o
[ 67%] Building C object CMakeFiles/boundscheck.dir/src/vsscanf_s.c.o
[ 67%] Building C object CMakeFiles/boundscheck.dir/src/vswprintf_s.c.o
[ 68%] Building C object CMakeFiles/boundscheck.dir/src/vswscanf_s.c.o
[ 70%] Building C object CMakeFiles/boundscheck.dir/src/vwscanf_s.c.o
[ 71%] Building C object CMakeFiles/boundscheck.dir/src/wcscat_s.c.o
[ 72%] Building C object CMakeFiles/boundscheck_static.dir/src/wcscpy_s.c.o
[ 73%] Building C object CMakeFiles/boundscheck.dir/src/wcscpy_s.c.o
[ 75%] Building C object CMakeFiles/boundscheck_static.dir/src/wcsncat_s.c.o
[ 76%] Building C object CMakeFiles/boundscheck.dir/src/wcsncat_s.c.o
[ 77%] Building C object CMakeFiles/boundscheck_static.dir/src/wcsncpy_s.c.o
[ 78%] Building C object CMakeFiles/boundscheck_static.dir/src/wcstok_s.c.o
[ 80%] Building C object CMakeFiles/boundscheck_static.dir/src/wscanf_s.c.o
[ 81%] Building C object CMakeFiles/boundscheck_static.dir/src/wmemcpy_s.c.o
[ 82%] Building C object CMakeFiles/boundscheck_static.dir/src/wmemmove_s.c.o
[ 83%] Building C object CMakeFiles/boundscheck_static.dir/src/vfscanf_s.c.o
[ 85%] Building C object CMakeFiles/boundscheck.dir/src/wcsncpy_s.c.o
[ 86%] Building C object CMakeFiles/boundscheck_static.dir/src/vscanf_s.c.o
[ 87%] Building C object CMakeFiles/boundscheck.dir/src/wcstok_s.c.o
[ 88%] Building C object CMakeFiles/boundscheck.dir/src/wscanf_s.c.o
[ 90%] Building C object CMakeFiles/boundscheck.dir/src/wmemcpy_s.c.o
[ 91%] Building C object CMakeFiles/boundscheck.dir/src/wmemmove_s.c.o
[ 92%] Building C object CMakeFiles/boundscheck.dir/src/vfscanf_s.c.o
[ 93%] Building C object CMakeFiles/boundscheck.dir/src/vscanf_s.c.o
[ 95%] Linking C static library libboundscheck_d.a
[ 96%] Linking C shared library msys-boundscheck-1.dll
[ 96%] Built target boundscheck_static
[100%] Built target boundscheck

执行安装操作的输出,如下:

$ cmake --build build --target install -j8
[ 90%] Built target boundscheck
[100%] Built target boundscheck_static
Install the project...
-- Install configuration: ""
-- Installing: /usr/local/lib/libboundscheck.dll.a
-- Installing: /usr/local/lib/libboundscheck_d.a
-- Installing: /usr/local/include/boundscheck/securec.h
-- Installing: /usr/local/include/boundscheck/securectype.h
-- Installing: /usr/local/include/boundscheck/boundscheck_config.h


若非注明,均为原创,欢迎转载,转载请注明来源:使用CMake构建boundscheck库

关于 JackieAtHome

基层程序员,八年之后重新启航

此条目发表在 工作总结, 笔记 分类目录,贴了 , , 标签。将固定链接加入收藏夹。