Taylor Liss
Taylor Liss

Reputation: 593

What is the CMake equivalent of the GCC -c option?

For example, if I had a makefile that contains this:

dynArray.o: dynArray.c dynArray.h type.h 
    gcc -Wall -ansi -c dynArray.c

How would I translate that into a CMakeLists.txt file?

Upvotes: 0

Views: 447

Answers (2)

legalize
legalize

Reputation: 2252

Since an object file alone is not the end result of what you are building, I suspect there is more context to the question that is missing. You are probably building an executable from the objects. Just use add_executable to specify your target and the source files that make up the target. Then use target_compile_definitions to specify the compile options you want while compiling source files for that target. For example:

add_executable(dynArray dynArray.c dynArray.h type.h)
target_compile_definitions(dynArray PRIVATE -Wall -ansi)

You can verify that the resulting compile commands are what you expect by using the Unix Makefiles generator and passing VERBOSE=1 to the make command:

mkdir build; cd build
cmake -G "Unix Makefiles" ..
make VERBOSE=1

This will cause the generated Makefile to display the full command lines used on every step of the build.

Upvotes: 1

orhtej2
orhtej2

Reputation: 2165

Probably CMake's object libraries would do that, that mean compile objects but not archive them like normal library would.

add_library(<name> OBJECT <src>...)

Upvotes: 1

Related Questions