Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
850 views
in Technique[技术] by (71.8m points)

cmake - How do I get CLion to run an install target

I'm evaluating CLion 1.2.1 on an existing project which is already using CMake. The project is made up of a few library modules and a single executable.

I have an install target which I use to collect the executable and a configuration file together in a bin folder for debugging:

...
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_BINARY_DIR}/bin/)
install(FILES config.xml DESTINATION ${CMAKE_BINARY_DIR}/bin/)

When building on the command line I'd just run:

make install

which as expected builds the binaries and if successful then runs the above install commands.

My problem is that I can't get CLion to run the 'install' target. I expected to be able to create a new Run/Debug configuration but the Target: dropdown only contains those targets added using add_executable() and add_library().

I also tried adding 'install' to the Build options in the Settings dialog. That however runs install for every target now including 'clean' which is not right.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

UPDATE: As of 2018.1 EAP, build 181.3741.16, CLion supports running cmake install if your project defines install targets:


Original Answer:

I don't think that CLion implements this feature yet. However, you can work around this limitation by adding a CMake "custom target" (using add_custom_target()) that will execute the make install command:

add_custom_target(install_${PROJECT_NAME}
                  $(MAKE) install
                  DEPENDS ${PROJECT_NAME}
                  COMMENT "Installing ${PROJECT_NAME}")

Now, all you have to do is "build" the install_YOUR_PROJECT_NAME target from the "targets" menu in CLion.

Update:

A more cross-platform technique might be the following:

add_custom_target(install_${PROJECT_NAME}
                  "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target install
                  DEPENDS ${PROJECT_NAME}
                  COMMENT "Installing ${PROJECT_NAME}")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...