fpagliughi / sockpp

Modern C++ socket library.
BSD 3-Clause "New" or "Revised" License
769 stars 126 forks source link

CMake error with old CMake version #89

Closed HerrNamenlos123 closed 7 months ago

HerrNamenlos123 commented 9 months ago

I am using this library with CMake version 3.13.4 (And cannot update it). This library requires 3.12, hence it should work. However, when building I encounter following error:

-- Creating static library: sockpp-static
-- Configuring done
CMake Error at sockpp/src/CMakeLists.txt:84 (target_compile_options):
  Error evaluating generator expression:

    $<CXX_COMPILER_ID:MSVC,Clang>

  $<CXX_COMPILER_ID> expression requires one or zero parameters.

This points to here: https://github.com/fpagliughi/sockpp/blob/f3100f575b38e83a1f2464ca54228bebb1282679/src/CMakeLists.txt#L87

In CMake 3.27 it works fine, but in 3.13.4 it does not. And if I change $<CXX_COMPILER_ID:MSVC,Clang> to just $<CXX_COMPILER_ID:MSVC>, it also works in the old version. Maybe the generator syntax was changed and only works like that in newer CMake versions? It might be solved by using two separate generator expressions with an AND or by setting a policy.

Can someone please take a quick look at this? I am not in the position to file a PR...

Thank you for all your time!

fpagliughi commented 9 months ago

Hmmm. I think you’re right. Looking at the CMake docs, the support for a comma-separated list first appears in 3.15.

I’m not great with CMake, but I thought it would tell you if you used an unsupported feature with the version you declared! I guess not.

I suppose the same thing can be done with if/else statements instead of generator expressions. That would make it work with older versions.

For now, in your local copy, you can comment out those lines as they’re just turning on compiler warnings when building the library.

HerrNamenlos123 commented 9 months ago

Yep, I think using an if statement instead of a generator expression should work since only one of them will be true at configure time.

fpagliughi commented 7 months ago

Actually just rewrote the generator expression to work with the older CMake versions.

fpagliughi commented 7 months ago

Fixed in v0.8.2