Korchkidu
Korchkidu

Reputation: 4946

Jenkins + CMake for multiple OS and library versions

My C++ program is compiled for multiple OS (Win7, MacOS & Linux) using CMake.

For OS dependent stuff, I am doing things like:

if (${APPLE})
    // Do MacOS dependent things here
elseif(${WIN32})
    // Do Win dependent things here
elseif(${UNIX})
    // Do Linux dependent things here
endif (${APPLE})

Now, I need to link my program against different versions of a library. Continuing the same way will quickly become unpractical.

How could I compile my program for multiple OS against multiple versions of a library while keeping everything practical so that it is easy to add new OS and/or new versions of the library?

Eventually, everything will be integrated with Jenkins so I don't know if it is better to work at CMake or Jenkins level (or both).

Upvotes: 0

Views: 622

Answers (1)

Fraser
Fraser

Reputation: 78408

There's probably no "correct" answer here. The purpose of CMake is to provide a Cross-Platform Make (hence the name) and as such, it provides many ways to reduce or eliminate platform-specific code.

I tend to find that the majority of cases where I need platform-specific blocks are either during dependency lookups (find_library, find_file, etc) or to set compiler/linker flags. (Of course, my experience may not be typical or even applicable in your case). This generally means that there aren't too many places in a given CMakeLists file where I need platform- or compiler-specific code.

One possible way to clean up would be to have all the platform-specific code in separate files and just include each in a single if elseif else block.

Upvotes: 1

Related Questions