Skip to content

Do NOT build tests if Fastor is a dependency #178

Description

@Bbllaaddee

I would like to use Fastor as a dependency in a cmake project. To do that, one would probably go for FetchContent module or use a CPM.cmake package.

Obviously, while doing this, I do not want to build Fastor's tests. However, at the moment, Fastor's tests are being built anyways.

Another issue is that currently Fastor exposes BUILD_TESTING option at the top-level CMakeLists.txt file, which might interfere with other projects' own variables.

cmake3.21 introduces PROJECT_IS_TOP_LEVEL option, that allows to check if project is a dependency for other project. There are also presets, but they are far more complex and require more attention.

I propose a simple fix by bumping cmake version to 3.21 from 3.20, adding a condition on Fastor being a top-level project in order to build tests.

My test project for this consists only of two files: main.cpp and CMakeLists.txt.

// main.cpp
#include <iostream>
#include "Fastor/Fastor.h"

int main()
{
	Fastor::Tensor<int,3> a { 1,2,3 };
	Fastor::Tensor<int,3> b { 4,5,6 };
	std::cout << a+b  << std::endl; // so it doesn't compile out
}
# CMakeLists.txt
cmake_minimum_required(VERSION 3.21)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

project(
    qwe
	LANGUAGES CXX
)

add_executable(main main.cpp)

# ---- Download Fastor ----
include(FetchContent)
FetchContent_Declare(
	fastor
	GIT_REPOSITORY https://github.com/Bbllaaddee/Fastor.git
	GIT_TAG master
)
FetchContent_MakeAvailable(fastor)


target_include_directories(main PUBLIC ${FASTOR_INCLUDE_DIR})
target_link_libraries(main Fastor)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions