How to solve the problem that clion keeps processing? - cmake

when i try to modify my CMakeLists or compile a project, it gives the warning: processing ( Code analysis has been suspended. Heavy operation is running. ) Then I cannot compile my project.
The version of clion is 2021.3.2. And the cmake_minimum_required is version 3.21
cmake_minimum_required(VERSION 3.21)
The clion project occupy huge part of the CPU.
The project I want to compile is simple just like this:
#include <stdio.h>
int main(){
printf("hello2!");
return 0;}
The Cmakelists is properly written:
cmake_minimum_required(VERSION 3.21)
project(test C)
add_executable(test
hello2.c)
I try to compile the project in Linux and it success. (Ubuntu 20.04 VMware Workstation) . But it always fail in Windows.
enter image description here
Also, the project can be compiled successfully when I open it at first without doing any changes. After I do some simple changes, it shows processing and fails to compile. But I can save these changes and open it as a clion project to enable it to compile.

This question was solved. I changed my regedit by mistake for some reasons. After I reinstall the system(windows10). This problem disappear.

Related

Cmake cannot find wxWidgets on Windows

I have searched for this topic and found this and this, but it only seems to either pertain to building wxWidgets or do not contain an answer to my question.
I have built the static libs für wxWidgets on Windows successfully, but I am now struggling to correctly include the libraries to my project using Cmake. This is my CMakeLists.txt:
set(PROJECT_NAME wxapp)
project(${PROJECT_NAME})
cmake_minimum_required(VERSION 2.8)
set(SRC_LIST main.cpp app.cpp app.h frame.cpp frame.h)
add_executable(${PROJECT_NAME} WIN32 ${SRC_LIST})
find_package(wxWidgets REQUIRED net gl core base)
include(${wxWidgets_USE_FILE})
target_link_libraries(${PROJECT_NAME} ${wxWidgets_LIBRARIES})
set(wxWidgets_USE_LIBS ON)
set(wxWidgets_CONFIGURATION msw)
I have set the WXWIN path variable correctly. Yet, CMake throws an error with this configuration:
Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES
wxWidgets_INCLUDE_DIRS net gl core base)
I have tried multiple suggestions, like using downloading prebuild dynamic libraries and adding them manually as suggested here, e.g.
set(wxWidgets_ROOT_DIR $ENV{WXWIN})
set(wxWidgets_LIBRARIES $ENV{WXWIN}/include)
set(wxWidgets_INCLUDE_DIR $ENV{WXWIN}/lib/vc14x_x64_dll)
include_directories(includes $ENV{WXWIN} $ENV{WXWIN}/include $ENV{WXWIN}/lib/vc14x_x64_dll)
link_directories($ENV{WXWIN} $ENV{WXWIN}/include $ENV{WXWIN}/lib/vc14x_x64_dll) # this seems to be a discouraged/deprecated method
but all to no avail.
WORKAROUND (at least it works for me):
I changed the find_package command from the suggested statement:
find_package(wxWidgets COMPONENTS gl core base OPTIONAL_COMPONENTS net)
to
find_package(wxWidgets 3.1 REQUIRED)
A user in this post had this included in his/her CMake file and out of deperation, I tried this and it actually worked. Seems like the configuration of CMake under certain unknown circumstances won't function correctly with the statement provided in the instructions. If I change the command to the new statement my static build as well as self- and precompiled dlls are flawlessly identifed by CMake.
I also cleared the CMake cache, inspired by this post. According to this post, there seems to be an issue with Windows and the CMake cache in some situations, but the reasons escape me. I could replicate the behaviour observed by the user there:
Under Windows, you have to point to the installation directory, e.g.
set(wxWidgets_ROOT_DIR "C:/wxWidgets-3.1.3") set(wxWidgets_LIB_DIR
"C:/wxWidgets-3.1.3/lib/vc14x_x64_dll")
But then the behavior is still strange. When i use CMake GUI (3.16,
latest), behavior is like this
delete cache (just to be consistent)
press 'configure' button
--> fail: CMake Error at C:/Program Files/CMake/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146
(message): Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES
wxWidgets_INCLUDE_DIRS core base qa adv net html gl propgrid richtext)
press 'configure' button again
--> success
I also have observed some inconsistent behaviour of CMake within the IDEs CLion and CodeBlocks when clearing the cache and reloading the project.
So, exactly how the cache clearing plays into the resolution of my issue, I don't know. But if I merely clear the cache, reload my project and leave the CMake instruction at find_package(wxWidgets COMPONENTS gl core base OPTIONAL_COMPONENTS net), CMake won't find my installation despite the WXWIN path being set correctly.
If you know more about this, I am happy to be corrected.

CUDA compilation with relocatable code: "Could not find fatbin in ..."

As part of a larger CMake project, I am adding a CUDA library. The rest of the project is C++, compiled with clang.
To test that the library works correctly, I'm creating a small executable and linking the CUDA library to it:
add_library(kernels STATIC
kernels.cu
)
set_target_properties(kernels PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
# --- Test executable
add_executable(main
main.cpp
)
target_link_libraries(main PRIVATE kernels)
The library compiles fine, but I get the following error when nvcc is invoked to do the device linking part of the process on my executable (target main):
nvlink fatal : Could not find fatbin in '[some long path]/main.cpp.o'
nvlink fatal : elfLink internal error
What is preventing this step from working?
I couldn't reproduce this issue in a fresh, tiny CMake project, so I eventually figured out that some flag from my larger project wasn't playing along.
It turns out that Thin LTO, which was enabled in CMAKE_CXX_FLAGS is causing this issue.
I disabled it for this particular target with:
target_compile_options(main PRIVATE "-fno-lto")

Compiling latest release of CppUTest (3.7) with MinGw, pthreads missing

I'm trying to use CppUTest in Windows, first step is to get it to work and I already have problems. These are the things I've tried:
First Approach
With CMake, using the cmake GUI I can do the configure and generate command and I get something in the output directory, but no binaries and no libraries, just a bunch of cmakefiles. The CMake GUI says everything went OK during the configuration and generation steps, however the libraries (.lib files) are not generated in the output directory... is there something I am missing? I've never used CMake before.
Second approach
With MinGW and msys alone, running cmd in Windows and executing a MinGW shell by typing sh in the Windows terminal, afterwards I execute the following commands:
cd <CppUTest folder>
mount c:\mingw /mingw
./autogen.sh
./configure
make
The build process starts but it fails with a message indicating that pthread.h was not found in MinGW directory. If I install the pthread-win32 package with the MinGW package manager and repeat the same steps as above the build process starts but fails with a message indicating that the structure timespec is defined in time.h and pthread.h.
I've tried to follow this same procedure with CppUTest 3.6 and it works perfectly fine, I get the .lib files, so I guess I will have to continue with this for now.
Does anyone know how to build CppUTest 3.7 (latest release) with MinGW or CMake?
In the end I used Cygwin to compile it, I couldn't find a way to compile it with MinGW properly, I added a dirty trick to make it compile under MinGW (handled the timespec redifinition) but chances are that is going to cause issues.
Just make sure that you use Cygwin aswell to compile your tests, something that I found out after making this question (https://www.youtube.com/watch?v=oVmd0P85D8o).

Force cmake to re-run CHECK_CXX_SOURCE_COMPILES after external libraries have been set up

Using CMake I want to check if a particular function (cv::getGaborKernel) from OpenCV library is available (it is available only in quite recent version of the library). If it is, I will use it in my code, if it is not, I redefine it in my code, in btw #ifdefs.
Here is a snippet of my CMakeLists.txt:
FIND_PACKAGE(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
get_property(inc_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
set(CMAKE_REQUIRED_INCLUDES ${OpenCV_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${OpenCV_LIBS})
INCLUDE(CheckCXXSourceCompiles)
CHECK_CXX_SOURCE_COMPILES(
"
#include <opencv2/imgproc/imgproc.hpp>
int
main()
{
cv::Mat toto = cv::getGaborKernel(cv::Size(11,11), 1,0,3,1,0, CV_64F);
}
" HAVE_OPENCV_GABOR)
if(HAVE_OPENCV_GABOR)
message("Using OpenCV Gabor implementation")
else(HAVE_OPENCV_GABOR)
message("Using custom Gabor implementation")
endif(HAVE_OPENCV_GABOR)
When deploying on a computer with recent OpenCV version (which does have cv::getGaborKernel), the test fails, forcing the redefinition of the function and some compilation errors.
The problem reside in the fact that OpenCV not beeing installed in standard directory, it first fails to locate the library. So the sample program cannot be built. However, after I properly set up OpenCV dependencies, the test for HAVE_OPENCV_GABOR is not run again as the failure is registered in the cache.
How can I force CMake to rerun the test in that case?
Just wrap your CHECK_CXX_SOURCE_COMPILES() call with
if(NOT OpenCV_INCLUDE_DIRS OR NOT OpenCV_LIBS)
...
endif()
Another solution - add unset(HAVE_OPENCV_GABOR CACHE) before running CHECK_CXX_SOURCE_COMPILES().

LLVM based project lib dependencies for CMake on windows

This has been asked here before but I couldn't find a solution which works for me.
Sample CMakeLists.txt file for LLVM project - This was the original question.
However, there are a couple of issues I am facing when making a project with LLVM.
Platform: Windows 7
Compiler: MingW
1) Firstly, I am using the svn version of llvm which is currently at 3.1. Currently, Binaries for MingW are not present for llvm 3.0 too so I decided to go with the latest itself and build it with mingw. So although the build works fine, I cannot seem to find the llvm-config perl script in the bin folder. I tried searching the entire dir yet I can only find an llvm-config folder and a dependencies file.
2) I tried building llvm for Visual studio 2010 yet that didn't work with cmake so I had to use MingW.
3) Now, this is sequence in which I add libs to CMake -
LLVMXCoreInfo
LLVMMipsAsmPrinter
LLVMMipsCodeGen
LLVMMipsInfo
LLVMMBlazeAsmPrinter
LLVMMBlazeCodeGen
LLVMMBlazeInfo
LLVMLinker
LLVMipo
LLVMInterpreter
LLVMInstrumentation
LLVMJIT
LLVMExecutionEngine
LLVMMC
LLVMBitWriter
LLVMX86Disassembler
LLVMX86AsmParser
LLVMX86AsmPrinter
LLVMX86CodeGen
LLVMX86Info
LLVMAsmParser
LLVMARMAsmParser
LLVMMCParser
LLVMARMAsmPrinter
LLVMARMCodeGen
LLVMARMInfo
LLVMArchive
LLVMBitReader
LLVMSelectionDAG
LLVMAsmPrinter
LLVMCodeGen
LLVMScalarOpts
LLVMInstCombine
LLVMTransformUtils
LLVMipa
LLVMAnalysis
LLVMTarget
LLVMMC
LLVMCore
LLVMSupport
imagehlp
psapi
m
4) However, adding InitializeNativeTarget(), starts giving me linking errors which I think come because of the dependencies not being in right order.
5) I want to use the llvm_map_components_to_libraries(REQ_LLVM_LIBRARIES jit native) and hence I added this to my CMakeLists.txt
INCLUDE(cmake/LLVM-Config.cmake)
However, this doesn't work. CMake Error at cmake/LLVM-Config.cmake:141 (message):
Library `jit' not found in list of llvm libraries.
Now, the question is really too long but I basically wanted to ask what is the best way to do this in CMake. Could someone post the entire thing (for windows).
Also, is there a way to build it for VS 2010. I tried the instructions on CLang site but those gave me this error in CMake.
" string sub-command REGEX, mode MATCH needs at least 5 arguments total to command."
I really need some help figuring out how to get dependencies to work in llvm and for it to build with VS. I would really appreciate some help.