Skip to content

Commit 87dd0de

Browse files
committed
use CPM.cmake for testing
1 parent df8a343 commit 87dd0de

File tree

8 files changed

+67
-42
lines changed

8 files changed

+67
-42
lines changed

CMakeLists.txt

+2-19
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,6 @@
44
#
55
# ---------------------------------------------------------------------------- #
66

7-
# ---------------------------------------------------------------------------- #
8-
# CppMF projects are designed to apply modern CMake practice.
9-
# As such, a decent CMake version is used to benefit from all new features.
10-
#
11-
# Check CMake Release Notes:
12-
# https://cmake.org/cmake/help/latest/release/3.21.html
13-
# ---------------------------------------------------------------------------- #
14-
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
15-
16-
# ---------------------------------------------------------------------------- #
17-
# Project configuration
18-
# ---------------------------------------------------------------------------- #
19-
project(
20-
GitInfo.cmake
21-
LANGUAGES C CXX
22-
)
23-
247
# ---------------------------------------------------------------------------- #
258
#
269
# Following variables will be set when calling GitInfo
@@ -182,8 +165,8 @@ function(GitInfo source)
182165
endfunction()
183166

184167

185-
# Display info
186-
function(GitInfoInfo)
168+
# Report git information
169+
function(GitInfoReport)
187170
message(STATUS "")
188171
message(STATUS "----------------------------------------------------")
189172
message(STATUS " GitInfo.cmake")

test/CMakeLists.txt

+8-7
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
# ---------------------------------------------------------------------------- #
88
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
99

10+
# Make use of GetCPM.cmake
11+
include(${CMAKE_CURRENT_LIST_DIR}/cmake/GetCPM.cmake)
1012

11-
# Add the directory containing the main CMakeLists file
12-
# and declare the output directory
13-
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/.. ${CMAKE_CURRENT_BINARY_DIR}/GitInfoCmake)
13+
# Add Version.cmake package
14+
CPMAddPackage(NAME GitInfo.cmake SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
1415

1516

1617
# ---------------------------------------------------------------------------- #
@@ -23,7 +24,7 @@ GitInfo(${CMAKE_CURRENT_SOURCE_DIR}/..)
2324
# Project configuration
2425
# ---------------------------------------------------------------------------- #
2526
project(
26-
test_app
27+
TestApp
2728
VERSION 1.0.0
2829
LANGUAGES CXX
2930
)
@@ -33,18 +34,18 @@ project(
3334
# Display git info
3435
# ---------------------------------------------------------------------------- #
3536
if(GIT_INFO_CMAKE_INFO)
36-
GitInfoInfo()
37+
GitInfoReport()
3738
endif()
3839

3940

4041
# ---------------------------------------------------------------------------- #
4142
# Pass definition to compiler
4243
# ---------------------------------------------------------------------------- #
4344
if(GIT_REVISION)
44-
add_definitions(-DGIT_REVISION="${GIT_REVISION}")
45+
add_definitions(-DGIT_REVISION="${GIT_REVISION}")
4546
endif()
4647
if(GIT_REVISION_NAME)
47-
add_definitions(-DGIT_REVISION_NAME="${GIT_REVISION_NAME}")
48+
add_definitions(-DGIT_REVISION_NAME="${GIT_REVISION_NAME}")
4849
endif()
4950

5051

test/cmake/GetCPM.cmake

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# This script is part of CPM.cmake under the following license
2+
#
3+
# MIT License
4+
# Copyright (c) 2019 Lars Melchior
5+
#
6+
7+
# define CPM version if not set
8+
if(NOT CPM_CMAKE_VERSION)
9+
set(CPM_CMAKE_VERSION 0.34.0)
10+
endif()
11+
12+
# Set the cpm.cmake version to use
13+
# Check for the latest version at : https://github.com/TheLartians/CPM.cmake/releases
14+
set(CPM_DOWNLOAD_VERSION ${CPM_CMAKE_VERSION})
15+
16+
# Define where to store the downloaded version of cpm.cmake
17+
# You can define where to store by source packages by defining CPM_SOURCE_CACHE
18+
# If not, it will be stored in the default location
19+
if(CPM_SOURCE_CACHE)
20+
# Expand relative path. This is important if the provided path contains a tilde (~)
21+
get_filename_component(CPM_SOURCE_CACHE ${CPM_SOURCE_CACHE} ABSOLUTE)
22+
# Define download location
23+
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
24+
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
25+
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
26+
else()
27+
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
28+
endif()
29+
30+
# If cpm.cmake is not found in the cache location, it is then downloaded from github release
31+
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
32+
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
33+
file(DOWNLOAD
34+
https://github.com/TheLartians/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
35+
${CPM_DOWNLOAD_LOCATION}
36+
)
37+
endif()
38+
39+
# It is finally be added to CMake module search path
40+
include(${CPM_DOWNLOAD_LOCATION})

test/scripts/build.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
# Build the test project
4+
cmake -S ".." -B "../build" -DGIT_INFO_CMAKE_INFO=ON
5+
cmake --build "../build"
6+
cmake --build "../build" --target test

test/scripts/clean.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
# Clear all files
4+
rm -rf ../build

test/scripts/setup.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
# Create cmake directory
4+
mkdir -p ../cmake
5+
6+
# Download GetCPM.cmake
7+
wget -O ../cmake/GetCPM.cmake https://raw.githubusercontent.com/cppmf/GetCPM.cmake/master/GetCPM.cmake

tools/build.sh

-9
This file was deleted.

tools/clean.sh

-7
This file was deleted.

0 commit comments

Comments
 (0)