I am building unit test software for my library. I am using Catch2 Testing Framework Version 3.1.0
When I am trying to include the catch_all
file in my aml_vector3_test.cpp but it is giving file not found error.
#include <catch2/catch_all.hpp> //Error in this line
#include "aml.h"
I had referred the link for integration of vcpkg with my cmake prokect
I have tried both set (CMAKE_TOOLCHAIN_FILE "D:/vcpkg/scripts/buildsystems/vcpkg.cmake")
and include ("D:/vcpkg/scripts/buildsystems/vcpkg.cmake")
in both my global CMake file and test project cmake file but it still didn't help. I tried all permutation and combination with this.
Kindly note I have zero exposure to cmake and have no idea what I am doing.
Project Structure
aml
|--CMakeLists.txt (CMake File 1)
|--CMakeSettings.json
|--aml
| |--CMakeLists.txt (CMake File 2)
| |--aml.h
| |--aml_vector3.cpp
| |--aml_vector3.h
|--example
| |--CMakeLists.txt (CMake File 3)
| |--main.cpp
|--test
| |--CMakeLists.txt (CMake File 4)
| |--main.cpp
| |--aml_vector3_test.cpp
CMake1 (Global CMake)
# CMakeList.txt : Top-level CMake project file, do global configuration
# and include sub-projects here.
#
cmake_minimum_required (VERSION 3.8)
set (CMAKE_C_STANDARD 17)
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_TOOLCHAIN_FILE "D:/vcpkg/scripts/buildsystems/vcpkg.cmake")
project ("AttitudeMathLibrary")
# Include sub-projects.
add_subdirectory ("aml")
add_subdirectory ("test")
add_subdirectory ("example")
#enable_testing()
#add_test(test_all aml_vector3_test/aml_test)
Cmake2 (Main Library CMake)
# CMakeList.txt : CMake project for aml_vector3, include source and define
# project specific logic here.
#
cmake_minimum_required (VERSION 3.8)
project(aml)
# Add source to this project's executable.
# add_executable (aml_vector3 "aml_vector3.cpp" "aml_vector3.h" "aml.h")
# target_sources ("aml_vector3.cpp" "aml_vector3.h" "aml.h")
set (SRC_CPP_AML "aml_vector3.cpp" "aml_vector3.h" "aml.h")
# TODO: Add tests and install targets if needed.
add_library (${PROJECT_NAME} STATIC ${SRC_CPP_AML})
target_include_directories (${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR})
CMake3 (Example Project CMake)
# CMakeList.txt : CMake project for aml_vector3, include source and define
# project specific logic here.
#
cmake_minimum_required (VERSION 3.8)
project (aml_example)
# Add source to this project's executable.
add_executable (${PROJECT_NAME} "main.cpp")
# TODO: Add tests and install targets if needed.
target_link_libraries(${PROJECT_NAME} aml)
install (TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_BINARY_DIR}/bin)
CMake 4 (Unit Test Camke)
# CMakeList.txt : CMake project for aml_vector3, include source and define
# project specific logic here.
#
cmake_minimum_required (VERSION 3.8)
#set (CMAKE_TOOLCHAIN_FILE "D:/vcpkg/scripts/buildsystems/vcpkg.cmake")
include ("D:/vcpkg/scripts/buildsystems/vcpkg.cmake")
project (aml_test)
find_package(catch2 CONFIG REQUIRED)
# Add source to this project's executable.
add_executable (${PROJECT_NAME} "main.cpp" "aml_vector3_test.cpp")
include_directories(${CATCH2_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} aml)
target_link_libraries(${PROJECT_NAME} catch2)
# TODO: Add tests and install targets if needed.
CMakeSettings.json
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"variables": [
{
"name": "CMAKE_BUILD_TYPE",
"value": "Debug",
"type": "STRING"
},
{
"name": "CMAKE_INSTALL_PREFIX",
"value": "C:/Users/darksorrow/source/repos/aml_vector3/out/install/x64-Debug",
"type": "PATH"
},
{
"name": "CMAKE_MAKE_PROGRAM",
"value": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe",
"type": "FILEPATH"
},
{
"name": "CMAKE_TOOLCHAIN_FILE",
"value": "D:/vcpkg/scripts/buildsystems/vcpkg.cmake"
}
]
}
]
}
message ("CATCH2_INCLUDE_DIRS : ${CATCH2_INCLUDE_DIRS}")
prints
[CMake] CATCH2_INCLUDE_DIRS : D:/vcpkg/installed/x64-windows/include
Other Codes:
aml.h
#pragma once
// Helper file - Imports all Attitude Math Library Files in a single file.
// This is a convenience file for the user
#include "aml_vector3.h"
aml_vector.h
#include <iostream>
namespace aml
{
class Vector3
{
public:
union
{
double data[3];
struct
{
double x, y, z;
};
};
//Constructors
Vector3();
Vector3(double value);
Vector3(double x, double y, double z);
Vector3(double data[3]);
//Operator Assignment (Vector)
Vector3& operator+=(const Vector3& rhs);
Vector3& operator-=(const Vector3& rhs);
Vector3& operator*=(const Vector3& rhs);
Vector3& operator/=(const Vector3& rhs);
//Operator Assignment (Scalar)
Vector3& operator+=(double s);
Vector3& operator-=(double s);
Vector3& operator*=(double s);
Vector3& operator/=(double s);
};
}
aml_vector.cpp
#include <cmath>
#include "aml_vector3.h"
namespace aml
{
Vector3::Vector3() : x(0.0), y(0.0), z(0.0)
{
}
Vector3::Vector3(double value) : x(value), y(value), z(value)
{
}
Vector3::Vector3(double x, double y, double z) : x(x), y(y), z(z)
{
}
Vector3::Vector3(double data[3]) : x(data[0]), y(data[1]), z(data[2])
{
}
Vector3& Vector3::operator+=(const Vector3& rhs)
{
this->x += rhs.x;
this->y += rhs.y;
this->z += rhs.z;
return *this;
}
Vector3& Vector3::operator-=(const Vector3& rhs)
{
this->x -= rhs.x;
this->y -= rhs.y;
this->z -= rhs.z;
return *this;
}
Vector3& Vector3::operator*=(const Vector3& rhs)
{
this->x *= rhs.x;
this->y *= rhs.y;
this->z *= rhs.z;
return *this;
}
Vector3& Vector3::operator/=(const Vector3& rhs)
{
this->x /= rhs.x;
this->y /= rhs.y;
this->z /= rhs.z;
return *this;
}
Vector3& Vector3::operator+=(double s)
{
this->x += s;
this->y += s;
this->z += s;
return *this;
}
Vector3& Vector3::operator-=(double s)
{
this->x -= s;
this->y -= s;
this->z -= s;
return *this;
}
Vector3& Vector3::operator*=(double s)
{
this->x *= s;
this->y *= s;
this->z *= s;
return *this;
}
Vector3& Vector3::operator/=(double s)
{
this->x /= s;
this->y /= s;
this->z /= s;
return *this;
}
}
example - main.cpp
#include "aml.h"
int main(int argc, char** argv)
{
aml::Vector3 v1(1.0, 2.0, 3.0);
aml::Vector3 v2(4.0, 5.0, 6.0);
aml::Vector3 v3 = v1 + v2;
aml::Vector3 v4 = v1 * v2;
std::cout << "v1 : " << v1 << std::endl;
std::cout << "v2 : " << v2 << std::endl;
std::cout << "v3 : " << v3 << std::endl;
std::cout << "v4 : " << v4 << std::endl;
}
test - main.cpp
//File is empty
aml_vector3_test.cpp
#include <catch2/catch_all.hpp>
#include "aml.h"
Final Update (Solution)
I solved the problem by reinstalling vcpkg package manager and cmake tool.