CMake and c++ libraries
Hi everyone,
At work, I stumbled upon something that seems completely absurd to me, but perhaps someone here will have a different perspective.
We have a software architect who defines the data model using .idl files (a kind of simplified struct, if you're not familiar with it). These .idl files generate C++ code.
Historically, it was C++ 98 code. And now it also includes "modern" C++ code, meaning that arrays are no longer T[] but rather vector<T>, for example. Originally, these IDL files are used within our kind-of micro services. They update the data model within the distributed monolith, and we develop related features.
Under the pretext that these are the same source IDL files, our software architect imposes and provides us with the same CMake target name for both. This means we have to generate one install folder in 98 and another in "modern" C++.
And for the software where we'd like to start mixing the two within the same CMake project, we're stuck because we're limited to a single CMake target for two final .so files.
Do any of you see the point of his approach?
Would you recommend having a unique target name for each .so/.a ?
21
u/d3matt Jun 19 '26
Vector is very much part of C++98
7
u/blipman17 Jun 19 '26
What is your question? Why writing .idl's makes sense? where it doesn't? How to get out of your situation with the conflicting idl's?
2
u/Sniffy4 Jun 19 '26
what about writing your own code-generator that parses the .idl and generates whatever kind of class names and modern c++ you want? This is not hard to do anymore, esp. with AI assistance.
2
u/thegreatunclean Jun 20 '26
You aren't going to be able to use both in the same project without extreme trouble; you'll be fighting CMake all the way.
This is very similar to requiring two different version of the same library in the same build. If you can't patch the CMake file then the best solution I've seen is to use
ExternalProjectto build the library "outside" the main build and declare IMPORT targets that point to the different static libraries.It may be the same IDL files but it creates code with completely different usage and linkage requirements. If the SA isn't willing to use best practices then it's on them to provide an alternative solution.
Yes, and the fact this is even a question draws the software architect's understanding of CMake into question.
12
u/TheRealSmolt Jun 19 '26
There just isn't enough information we're going to be able to get to say much. There's way too many unknowns, we don't know the rationals behind anything being done, or what the goal is. This is why architects exist, to answer these questions with knowledge, expertise, and context. I can't say with certainty that they know better than you do, but I'd be pretty comfortable hedging that bet. The only opinion that I can give is that mixing two IDL implementations in the same context sounds like a bad idea.
4
u/kisielk Jun 19 '26
Yes I would recommend just having two separate library targets. If there are different compile options make sure you use target_compile_options etc. as opposed to the global versions of those functions.
1
u/saf_e Jun 19 '26
What's your question? Can you combine old and new interface in one lib? Diffinitely. And can be just a wrapper over the other.