Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLion and CMake: only building a library without an executable?

How to only build a static library with clion without having an executable? How does the CMakeLists.txt look like? (without add_executable)

Update: If I don't add executable to Clion, I have an error, that an executable is required.

Here my CMakeLists.txt.

like image 302
ilw Avatar asked Mar 30 '15 20:03

ilw


2 Answers

This is an old question. But I'll add the answer to your question as a help for other people. You need to replace your add_executable with add_library

add_library(target_name source_files)
like image 149
Praminda Avatar answered Oct 24 '22 00:10

Praminda


Short answer: compile the library target and run any custom command as a placeholder to avoid the warning.

Long answer:

CLion lets you either build the whole project and run executables/configurations.

When running executables, you can choose a target to compile and the executable to run after compiling the target. For executable targets, they are usually the same thing. You compile the executable target and then run it.

It seems like this is not really designed for libraries, but there is a workaround. You usually set the target to be the library and the executable to be any executable that depends on this library. However, this is usually not very useful because if you wanted to run this executable you could just set this executable to be the target and the library would be built anyway.

So people probably want to just build the library (to check if everything is OK, etc) without compiling or running any extra executable targets. In this case, the workaround is to choose a custom executable to run after building the library, and the error message is gone.

You have nothing useful you need to run after building the library, just choose any cheap command as a placeholder. Something like "pwd" or "ls".

Setting up a configuration

like image 39
user2983585 Avatar answered Oct 23 '22 22:10

user2983585