Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake: how to define target without linking (compilation only)

Tags:

cmake

Is there any simple way to create a target where object files aren't linked? I need additional target only for tests if everything compiles for ARM. I don't want to create any executable (it would not link anyway), because my project will be finally a part of something much bigger, which has its own old stable make-based build system.

So I just need to compile sources. All tests are done with other, PC target compiled with gcc.

like image 240
ardabro Avatar asked Apr 14 '15 17:04

ardabro


People also ask

What does target mean in CMake?

Introduction. A CMake-based buildsystem is organized as a set of high-level logical targets. Each target corresponds to an executable or library, or is a custom target containing custom commands.

How does CMake know which compiler to use?

As the linker is invoked by the compiler driver, CMake needs a way to determine which compiler to use to invoke the linker. This is calculated by the LANGUAGE of source files in the target, and in the case of static libraries, the language of the dependent libraries.

What is Cmakelist?

CMake is a meta build system that uses scripts called CMakeLists to generate build files for a specific environment (for example, makefiles on Unix machines). When you create a new CMake project in CLion, a CMakeLists. txt file is automatically generated under the project root.


1 Answers

You can use an object library:

add_library(dummy OBJECT <source files>)

See also:

  • add_library => object-libraries
  • Official tutorial.
like image 131
Antonio Avatar answered Dec 07 '22 16:12

Antonio