Search code examples
c++cmakecatch2find-package

Catch2 found by cmake but not accepted due to version mismatch


I installed Catch2 on Windows, located in C:/Program Files (x86)/Catch2/, but something went wrong when I use find_package to use Catch2.

In detail, using this cmake file:

project(UnitTest)
cmake_minimum_required(VERSION 3.20)
set(CMAKE_CXX_STANDARD 17)
find_package(Catch2)

And cmake failed with

CMake Warning at CMakeLists.txt:7 (find_package):
  Could not find a configuration file for package "Catch2" that is compatible
  with requested version "".

  The following configuration files were considered but not accepted:

    C:/Program Files (x86)/Catch2/lib/cmake/Catch2/Catch2Config.cmake, version: 3.3.2 (64bit)

I tried to use find_package(Catch2 3) and find_package(Catch2 3.3.2) but they all failed due to version dismatch.

I also tried find_package(Catch2 "3.3.2 (64bit)"), but it failed due to invalid call to find_package.

I wonder what's happening and how to fix this?


Catch2 is installed using something like this:

git clone [email protected]:catchorg/Catch2.git
cd Catch2
cmake -Bbuild . -DBUILD_TESTING=OFF
cmake --build build/ --config release --target install

Solution

  • The reason of not accepting the package is in the parenthesis: (64bit).

    CMake treats your package as 64-bit one, so that package cannot be used in the project targeting 32-bit platform.


    Not sure why CMake installs 64-bit Catch project into C:/Program Files (x86). Probably, this is caused by incorrect environment you had when configure Catch (cmake -Bbuild .).