I\'m trying to build an object file using CMake, but I can\'t seem to get CMake to build something other than a complete executable. I\'m basically looking for the result of the
Since CMake 3.1, CMake has had the ability to create Object libraries:
The
OBJECT
library type defines a non-archival collection of object files resulting from compiling the given source files.
To only create the object file (no library or executable), use this OBJECT
keyword with the add_library() command:
# This will create object.c.o (or object.c.obj on Windows) when built.
add_library(MyObj OBJECT ${CMAKE_CURRENT_SOURCE_DIR}/src/object.c)
You can later reference the object file(s) to be compiled into other libraries or executables:
add_library(MyLibrary STATIC $ MyClass1.cpp Helpers.cpp)