I’m wondering how i can make a portable build system (step-by-step), i currently use cmake because it was easy to set up in the first place, with only one arch target, but now that i have to package the library I’m developing I’m wondering how is the best way to make it portable for arch I’m testing.
I know I need a config.h to define things depending on the arch but I don’t know how automatic this can be.
Any other way to have a build system are warmly welcome!
You can just use CMake, it’s pretty straightforward.
You need these things:
First, means to find out the configuration specifics. For example, if you know that some function is named differently on some platform, you can use
TRY_COMPILEto discover that:where
alternative_function_test.cppis a file in your source directory that compiles only with the alternative definition.This will define variable
HAVE_ALTERNATIVE_FUNCif the compile succeeds.Second, you need to make this definition affect your sources. Either you can add it to compile flags
or you can make a
config.hfile. Createconfig.h.inwith the following lineand create a
config.hfile by this line inCMakeLists.txt(seeCONFIGURE_FILE)the
#cmakedefinewill be translated to#defineor#undefdepending on the CMake variable.BTW, for testing edianness, see this mail