1

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 git@github.com:catchorg/Catch2.git
cd Catch2
cmake -Bbuild . -DBUILD_TESTING=OFF
cmake --build build/ --config release --target install
Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70
Gorun
  • 134
  • 6

1 Answers1

1

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 .).

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • You are right. I found my compile toolchain ar set to be `x86` all the time. When I switch the architecture from `x86` to `amd64`, this Catch2 is accepted and everything works fine. – Gorun May 26 '23 at 10:17
  • The installation guide is copied from Internet and now I found it doesn't match cmake CLI. Later I tried some regular solution: `mkdir build`->`cd build`->`cmake .. -DBUILD_TESTING=OFF`->`cmake --build . --config release --target install`, and Catch2 is still installed in `C:/Program Files (x86)`. Maybe wrong options doesn't matters at all. – Gorun May 26 '23 at 10:22
  • The location of Catch2 seems to be unimportant. I tried to move Catch2 to `C:/Program Files` and cmake also find that package. – Gorun May 26 '23 at 10:24