Getting Started
The SoCMake source code is available on the following link.
Dependencies
Only mandatory SoCMake dependencies are CMake>=3.25.0
and make
.
- PIP
- WGET
- APT
pip install cmake==3.26.3
wget https://github.com/Kitware/CMake/releases/download/v3.26.3/cmake-3.26.3-linux-x86_64.sh
chmod +x cmake-3.26.3-linux-x86_64.sh
./cmake-3.26.3-linux-x86_64.sh --skip-license --prefix=$(pwd)/cmake
export PATH=$(pwd)/cmake/bin:$PATH
apt-get install cmake
Usage
Since SoCMake
runs on CMake scripting language, no installation is required.
It is recommended to fetch the SoCMake locally within your CMake
project.
There are multiple ways to add SoCMake within project, 2 of them are with CPM
or inbuilt FetchContent
.
In both cases SoCMake will be downloaded during configuration phase of the project, only the first time.
It is recommended to create a file deps/deps.cmake
with the content from one of the 2 options:
deps/deps.cmake
- FetchContent
- CPM.cmake
include(FetchContent)
FetchContent_Declare(SoCMake
GIT_REPOSITORY "ssh://git@gitlab.cern.ch:7999/socrates/SoCMake.git"
GIT_TAG master # You can define GIT_TAG or GIT_COMMIT for specific versions
)
FetchContent_MakeAvailable(SoCMake)
FetchContent is a built in CMake function for handling dependencies.
set(CPM_DOWNLOAD_VERSION 0.38.1) # Define CPM version to be downloaded
include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake) # Include the CPM.cmake downloader
CPMAddPackage( # Add SoCMake as a package
NAME SoCMake
GIT_TAG master # You can define GIT_TAG or VERSION for versioning
GIT_REPOSITORY "ssh://git@gitlab.cern.ch:7999/socrates/SoCMake.git" # GIT_REPOSITORY or URL
)
This is the recomended way of adding SoCMake.
In the line 2 we are including deps/CPM.cmake
installation script, which needs to be placed in the repository.
if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()
# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
function(download_cpm)
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION}
)
endfunction()
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
download_cpm()
else()
# resume download if it previously failed
file(READ ${CPM_DOWNLOAD_LOCATION} check)
if("${check}" STREQUAL "")
download_cpm()
endif()
unset(check)
endif()
include(${CPM_DOWNLOAD_LOCATION})
CMakeLists.txt
In the main CMakeLists.txt
include deps/deps.cmake
.
It should look like this:
cmake_minimum_required(VERSION 3.25)
project(example NONE)
include("deps/deps.cmake")
After the previous code block, all of the SoCMake functions are available.
Directory structure
The directory tree of the project should look like this
├── CMakeLists.txt
└── deps
├── CPM.cmake
└── deps.cmake
Running CMake
Since CMake is endorsing out-of-source builds, meaning that the source files and build artifacts are in separate directories.
We are creating a build
directory.
mkdir build
cd build
cmake ../
After executing CMake we should ge the following messages:
-- Downloading CPM.cmake to .../build/cmake/CPM_0.38.1.cmake
-- CPM: Adding package SoCMake@ (master)
-- Configuring done
-- Generating done
-- Build files have been written to: .../build
By default the packages will be downloaded in ${CMAKE_BINARY_DIR}/_deps/
.
This is possible to change by setting FETCHCONTENT_BASE_DIR
before the first CPMAddPackage
command.
For larger projects it is recommended to set set(FETCHCONTENT_BASE_DIR ${CMAKE_CURRENT_LIST_DIR}/_deps)
in deps/deps.cmake
, this will download all the dependencies git repository wide, so they will be available from different subdirectories like verification
, documentation
etc...
The previous example only set up the project, but we didnt add any design files or added any targets. Jump to the Examples page next.