-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
I was surprised to discover that adding add_subdirectory(cpp-httplib) to our project CMakeLists.txt has broken the build because some libraries that were supposed to be built as shared have suddenly started being built as static. The reason for this is that this library defines BUILD_SHARED_LIBS as OFF and, as CMake documentation says:
Note that if bringing external dependencies directly into the build, such as with FetchContent or a direct call to add_subdirectory(), and one of those dependencies has such a call to option(BUILD_SHARED_LIBS ...), the top level project must also call option(BUILD_SHARED_LIBS ...) before bringing in its dependencies.
and our project doesn't define this option. We probably could define it, but I think it would be better if cpp-httplib didn't define it instead, especially when HTTPLIB_COMPILE is OFF, i.e. when it's not even used by this library itself. I believe the best approach would be to use this option as default value for some new HTTPLIB_SHARED option and only use this option to decide which kind of library to build. This would have the following desirable consequences:
BUILD_SHARED_LIBSwill still be respected if it's defined (by the superproject or directly on the command line when configuring).- It will become possible to specify whether static or shared cpp-httplib library should be built by setting
HTTPLIB_SHAREDwithout affecting anything else. - Adding this project to the existing build won't break anything else any more.
Please let me know if you'd like me to submit a PR implementing this proposal.