Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do NOT build tests if Fastor is a dependency #178

Open
Bbllaaddee opened this issue Aug 28, 2024 · 0 comments
Open

Do NOT build tests if Fastor is a dependency #178

Bbllaaddee opened this issue Aug 28, 2024 · 0 comments

Comments

@Bbllaaddee
Copy link

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant