Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build System and portability

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!

like image 504
claf Avatar asked Feb 12 '09 10:02

claf


People also ask

What is a build system in programming?

Put simply, a build system is a set of programs and companion text files that collectively build a software code base. Nowadays, every programming language has its own set of build systems. For instance, in Java, you have Ant, Maven, Gradle, and so on.

What is a build system in C++?

Build systems were developed to simplify and automate running the compiler and linker and are an essential part of modern software development. This blog post is a precursor to future posts discussing our experiences refactoring the training projects to use the CMake build generator. Contents. Using Build Systems.

What is build system in Linux?

An Embedded Linux Build System refers. to the the tools and the environment for building the software. packages for a particular board/machine.


1 Answers

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_COMPILE to discover that:

TRY_COMPILE(HAVE_ALTERNATIVE_FUNC 
    ${CMAKE_BINARY_DIR}
    ${CMAKE_SOURCE_DIR}/alternative_function_test.cpp
    CMAKE_FLAGS -DINCLUDE_DIRECTORIES=xxx
)

where alternative_function_test.cpp is a file in your source directory that compiles only with the alternative definition.

This will define variable HAVE_ALTERNATIVE_FUNC if the compile succeeds.

Second, you need to make this definition affect your sources. Either you can add it to compile flags

IF(HAVE_TR1_RANDOM)
    ADD_DEFINITIONS(-DHAVE_TR1_RANDOM)
ENDIF(HAVE_TR1_RANDOM)

or you can make a config.h file. Create config.h.in with the following line

#cmakedefine HAVE_ALTERNATIVE_FUNCS

and create a config.h file by this line in CMakeLists.txt (see CONFIGURE_FILE)

CONFIGURE_FILE(config.h.in config.h @ONLY)

the #cmakedefine will be translated to #define or #undef depending on the CMake variable.

BTW, for testing edianness, see this mail

like image 80
jpalecek Avatar answered Nov 30 '22 08:11

jpalecek