CMake环境搭建
安装CMake
- 通过https://cmake.org/download/进入cmake下载网站,找到以
msi
为拓展名的软件包镜像并下载。如图所示: - 下载完成后,双击软件包安装。在安装过程中,添加CMake到所有用户的PATH环境变量中,如图所示:
- 安装路径最好自定义,方便后面查找。所有选择完成之后,一直点 NEXT ,直到安装完成。
配置CMake
安装CMake后,还需要对CMake进行配置,以便CMake可支持SylixOS。
注意:
添加文件之前,需要先打开文件的拓展名显示,因为添加的文件会涉及修改文件拓展名。
- 以win 11为例,打开任意文件管理器,按照 查看 > 显示 > 文件拓展名 的顺序,勾选文件拓展名。
- 找到cmake安装目录下的
/share/cmake-3.27/Modules/Platform
文件夹。在该文件夹下创建SylixOS.cmake、SylixOS-GNU.cmake、SylixOS-GNU-C.cmake、SylixOS-GNU-CXX.cmake、SylixOS-GNU-Fortran.cmake总共5个文件。
注意:
Windows下可以先创建记事本文件,通过重命名的方式得到所需文件,注意拓展名的修改。也可以通过 MSYS2 终端通过命令的方式创建文件。创建文件的命令为touch
。
- 将下列代码块内容,分别复制到对应文件中,并保存。
- SylixOS.cmake
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
# support for SylixOS https://www.sylixos.com/
# Guard against multiple inclusion, which e.g. leads to multiple calls to add_definition()
if(__SYLIXOS_CMAKE_INCLUDED)
return()
endif()
set(__SYLIXOS_CMAKE_INCLUDED TRUE)
set(CMAKE_SHARED_LIBRARY_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "")
set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP "")
set(CMAKE_LINK_LIBRARY_SUFFIX "")
set(CMAKE_STATIC_LIBRARY_PREFIX lib)
set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
set(CMAKE_SHARED_LIBRARY_PREFIX lib) # lib
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so") # .so
set(CMAKE_EXECUTABLE_SUFFIX "") #
set(CMAKE_DL_LIBS "" )
set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_BUILD_TYPE})
set(CMAKE_FIND_LIBRARY_SUFFIXES ".so")
include(Platform/UnixPaths)
- SylixOS-GNU.cmake
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
# support for SylixOS https://www.sylixos.com/
# This module is shared by multiple languages; use include blocker.
if(__SYLIXOS_COMPILER_GNU)
return()
endif()
set(__SYLIXOS_COMPILER_GNU 1)
macro(__SylixOS_compiler_gnu lang)
# We pass this for historical reasons. Projects may have
# executables that use dlopen but do not set ENABLE_EXPORTS.
set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS " ")
endmacro()
- SylixOS-GNU-C.cmake
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
# support for SylixOS https://www.sylixos.com/
include(Platform/SylixOS-GNU)
__SylixOS_compiler_gnu(C)
- SylixOS-GNU-CXX.cmake
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
# support for SylixOS https://www.sylixos.com/
include(Platform/SylixOS-GNU)
__SylixOS_compiler_gnu(CXX)
- SylixOS-GNU-Fortran.cmake
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
# support for SylixOS https://www.sylixos.com/
include(Platform/SylixOS-GNU)
__SylixOS_compiler_gnu(Fortran)
set(CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS "")