Both FetchContent and ExternalProject have trouble with stuff you want to build and link when you build your project. The problem is none of the things you need to find in the library will exist at configure time since you’ve not built the library yet.
I think the “cleanest” way may be to rewrite the build system of the project in cmake, and use that to build it.
You can use find_package with third party projects that don’t use cmake, someone just has to supply the module find_package calls (either Find.cmake or Config.cmake (with a few acceptable variations). The Find version is for when the “find module” is written, maintained, and provided by someone other than the upstream maintainers of the project, the config version is for when the maintainers of the upstream project provide the cmake configuration.
There are a few projects that don’t use cmake but provide cmake config files, Qt comes to mind (well, they use cmake to build as of Qt6, but they started providing config files in Qt5).
Another approach is to use pkg-config, cmake has a built in module called FindPkgConfig.cmake (you can call it with
find_package(PkgConfig) and it will run pkg-config with the right flags, parse the output, and create a target for you.
Neither of these approaches help if the library (and the pkg-config or cmake configuration files) don’t actually exist when you are configuring, as is the case when you’d like to build the library as part of your project’s
As a workaround you can do things like spawning a new cmake process as a custom command or with
execute_process (this is, in fact, how FetchContent works internally) but all such methods are pretty messy.
Also: most makefile based build systems don’t support all the stuff cmake does, and projects that ship Makefile.win32 files in many cases don’t actually do much CI on windows, and their windows makefiles are very frequently just broken.
tl;dr it’s probably easier to just rewrite the makefile in cmake (stuff like file(GLOB) that’s usually not recommended can be quite handy here). As a bonus it’ll build like 10x faster since nmake on windows can’t do multiple rules at once.