The NAMES of find_path cause cannot open file

Continuing the discussion from window env variable and cmake path:

Arguments following NAMES cannot include a directory, they must be file names only.
And I follow this. I will happen cannot open file error.

The below is the problem:
D:\libpqxx\include\pqxx\pqxx.h

find_path(_PQXX_INCLUDE
	NAMES pqxx
	PATHS "D:/libpqxx/include"
        PATH_SUFFIXES pqxx)

The error
image

#include "pqxx/internal/compiler-internal-pre.hxx"
#include "pqxx/internal/compiler-public.hxx"

Please check first the content of your _PQXX_INCLUDE variable (e.g. inside the cache file) to see if the find was correct.
I assume that you need to specify the correct file name for the find, which is: pqxx.h and not just pqxx

I can search the library(cache file is correct). But I can’t include the library.

So I rewrite the find_path. It work and can find library.

find_path(_PQXX_INCLUDE
	NAMES pqxx/pqxx
	PATHS "D:/libpqxx/include" )

_PQXX_INCLUDE=D:/libpqxx/include/pqxx/pqxx.h

Please delete your build directory (or at least the cache file).
The variable needs to be a directory, not a file, and this is not the result of this find_path command. It probably was already set by earlier experiments or you have another find with the same variable.

I have delete build folder for the two method.
Sorry I cannot understand what do you mean. Do you have the example?
Thanks you.

find_path(_PQXX_INCLUDE
  NAMES "pqxx/pqxx.h"
  PATHS "D:/libpqxx/include"
)

This will find the path, which you need to add to your include directory. Which is in fact D:/libpqxx/include

I assume this is just an example to understand the find command. If you know the path already and hardcode it, then you don’t need to search for it in the first place.