Cmake - creating of a new class and deletion of class, method are not handled properly

Answered

Please see the included Cmake file below, when non standard source root is used the Clion is not handling addition and deletion of the classes, methods, etc. It works more or less after Cmake refresh, but not as good as default config. Tested on Clion EAP-2018-3.

 

 

#https://github.com/krux02/minimal_cmake_example/blob/master/CMakeLists.txt
cmake_minimum_required(VERSION 3.12)
project(CppTest)

set(CMAKE_CXX_STANDARD 14)


file(GLOB_RECURSE sources src/main/cpp/*.cpp src/main/cpp/*.h)
file(GLOB_RECURSE data src/main/resources/*)
file(COPY ${data} DESTINATION resources)

add_executable(CppTest-1 ${sources} ${data})

#find_package(Boost)
#IF (Boost_FOUND)
# include_directories(${Boost_INCLUDE_DIR})
#endif ()

#set(Boost_USE_STATIC_LIBS OFF) # enable dynamic linking
#set(Boost_USE_MULTITHREAD ON) # enable multithreading

set(INSTALL_DIR "$ENV{HOME}/Documents/workspace/CLion/CppTest/install/cpp-test-1")
install(TARGETS CppTest-1 DESTINATION ${INSTALL_DIR})
install(DIRECTORY src/main/resources DESTINATION ${INSTALL_DIR}
PATTERN "resources/*"
PERMISSIONS GROUP_EXECUTE)
#
## now comes everything we need, to create a package
## there are a lot more variables you can set, and some
## you need to set for some package types, but we want to
## be minimal here
set(CPACK_PACKAGE_NAME "CppTest")
set(CPACK_PACKAGE_VERSION "1.0.0")
#
## we don't want to split our program up into several things
#set(CPACK_MONOLITHIC_INSTALL 1)
#
include(CPack)

7 comments

Hi, Vladimir! Not sure that I got the issue correctly.

So there are two directories with project sources - src/main/cpp and src/main/resources. Which directory is your project root in CLion (i.e. in which directory the .idea folder is located)? And where and how do you try to create a class? What happens when you do?

0

Anna, 

Here is the git link to the sample project including .idea folder https://github.com/vladgon/clion-CppTest/tree/clionSupport

I'm Creating  a new cpp file using CMD+N or CTRL+Insert shortcut and selecting "C++ Class", I'm not adding classes to the target since all .cpp and .h files files are part of the target already, I try to select the checkbox "Add To Target" but then files a literally added and this not what we want.

 

Thanks,

--Vladimir 

 

0

> I'm not adding classes to the target since all .cpp and .h files files are part of the target already

The New > C++ class option is intended for creation of two (or only one, it depends on the Create header only checkbox) new files from templates - the source and header files for the new class. Please see https://www.jetbrains.com/help/clion/creating-files-from-templates.html for more details.

Are you saying that you don't want a ".cpp, .h" pair of files to be created? You want to create a new class in an already existing file, don't you?

0

I'm fine with the creation of the file/files. The problem is that newly created file (let's say abc.h) is not recognizable by the Clion IDE until Cmake refresh is performed by clicking the refresh button or menu item.

The default project that Clion creates works properly and automatically traces the newly created files, classes and methods. But in my sample Cmake need to be explicitly refreshed in order for changes to be synced with the Clion.

 

 

0

I think I finally got this (that by "since all .cpp and .h files files are part of the target already" you mean that GLOB_RECURSE using in the file() commands), thank you for the details. 

Yes, for now CLion doesn't reload a CMake project automatically if you don't select the "Add To Target" option (and therefore the CMakeLists.txt is not changed).

Feel free to comment or upvote https://youtrack.jetbrains.com/issue/CPP-1369.

0

May Clion should check that if add to target checkbook is checked and if the file is already part of the target based on some other rule then it should not add it again, but at least refresh the project to be in sync. Added my few cents to the youtrack

 

Thank for your help.

 

--Vladimir

0

Vladimir, thanks for the comment!

0

Please sign in to leave a comment.