Blender in CLion: MSVC_REDIST_DIR-NOTFOUND, LIBDIR cmake variable - cmake

I am trying to build the Blender project in CLion, and failing with just configuring the IDE.
First, but not so crucial IMO, I am not sure which Architecture should I select in the Settings. By default CLion decided to go with x86, but that sounds like 32bit Windows to me... in 2022?
(But as long as I can build the project I guess win32 should not bother me.)
This seems like a bigger problem:
CMake Warning at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.21/Modules/InstallRequiredSystemLibraries.cmake:601 (message):
system runtime library file does not exist:
'MSVC_REDIST_DIR-NOTFOUND/x86/Microsoft.VC142.CRT/msvcp140.dll'
...
'MSVC_REDIST_DIR-NOTFOUND/x86/Microsoft.VC142.CRT/vcruntime140.dll'
...
'MSVC_REDIST_DIR-NOTFOUND/x86/Microsoft.VC142.CRT/concrt140.dll'
...
'MSVC_REDIST_DIR-NOTFOUND/x86/Microsoft.VC142.OPENMP/vcomp140.dll'
...
CMake Error at build_files/cmake/platform/platform_win32.cmake:264 (message):
32 bit compiler detected, blender no longer provides pre-build libraries
for 32 bit windows, please set the `LIBDIR cmake variable` to your own
library folder
All those "missing" files are scattered in the Visual Studio subdirectory "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Redist\MSVC\14.30.30704\x86\Microsoft.VC143*" directories, but for some reason CMake "decided" to go with VC142.
1) How does one convince CMake to go with VC143?
2) How does one set the LIBDIR cmake variable?
I suppose this one could go away once the Nr.1 problem gets resolved, but if not... Where should the variable point to, and what would its full name be? Just LIBDIR? (I am seeing CMAKE_INSTALL_ and CMAKE_INSTALL_FULL_ prefixes mentioned in GNUInstallDirs.cmake.)
Anyways, I suspect it should be set here?

So apparently there's a bug in VS2022. This version comes with CRT143 (whatever it is) yet the bundled scripts identify the VS as 2019 which only knows/recognizes CRT up to version 142.
https://developercommunity.visualstudio.com/t/1616850

Related

Compiling project that depend on LLVM using CMake on Windows

I'm a *nix user, installing LLVM is easy for me, just download the precompiled file, set LLVM_DIR, and you're done. But I'm having a lot of problems with Windows ...
I downloaded LLVM-<version>-win64.exe from the GitHub release, but I can't find LLVMConfig.cmake file. Then I tried to compile LLVM from the source following this documentation.
When I started compiling my own project, I got this error:
'C:/<...>/Debug/libLLVMSupport.lib', needed by '<...>.exe', missing and no known rule to make it
I guess maybe I'm missing some compile options. but I can't find the documentation for LLVM_ENABLE_PROJECTS or BUILD_SHARED_LIBS, not even a list of component names.
I tried to add -DBUILD_SHARED_LIBS=ON but CMake told me BUILD_SHARED_LIBS option is not supported on Windows.

CMake find_library can't find an existing library on MSVC

I made a project and tried to build it under GCC (Linux) and MinGW (Windows) using CMake. Now I'm trying to do the same under Visual Studio 2019 (for reasons) and it seems that CMake that is shipped with VS can't find libraries installed with MSVC.
I'm using a script which unfortunately I can't find again on the Net, so I can't give you a link to it. But I tried to isolate what is causing the problem. So, here is the code:
if(MY_LIB_PATH)
set(MYLIB_NO_DEFAULT_PATH_CMD NO_DEFAULT_PATH)
endif()
find_library(MY_LIBRARY
NAMES myLibrary
HINTS
ENV MY_ENV
${MYLIB_NO_DEFAULT_PATH_CMD}
PATH_SUFFIXES lib lib/x64
PATHS ${MY_LIB_PATH}
DOC ""
)
(the code is much complicated than that, but that is what it looks after all variable substitutions)
If I don't set the MY_LIB_PATH variable it can't find the library (which is located in the lib/x64 folder in the MSVC installation folder). But when I call CMake like this:
cmake "-DMY_LIB_PATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\lib\x64"
it "miraculously" finds it.
Yes it works but...wasn't CMake made to avoid writing all that path in the first place? Besides, there is yet another problem: there are many such libraries in my project, all of which use the same above code for finding, and I have to write all that path multiple times, so CMake can find them.
Either the authors of my CMake script did something wrong or I installed my libraries not where CMake is expecting them.

Missing libcrypto.lib in CMake build of Poco project

The Poco Libraries can be really powerful and useful... but also stubbornly hard to build :-( I am now several days into a process of trying to upgrade from:
Poco 1.9.0, win32 build, including NetSSL_OpenSSL and Data/MySQL, on Windows 7, using MS Visual Studio 2015 successfully built via buildwin.cmd script from Windows Explorer since April 2018
to:
Poco 1.10.1, win32 and x64 builds, including NetSSL_OpenSSL and Data/MySQL (32-bit) or Data/PostgreSQL (64-bit), on Windows 10, using MS Visual Studio 2019, built via any means at all.
So far I cannot make the build process budge in any significant direction from my old build to my new target via any means... except possibly via CMake.
Since CMake appears to be the preferred way to build Poco, and nothing else (e.g. buildwin.cmd) works as expected, I am trying to rebuild the 32-bit DLLs so I can test with older proven components in my application. It looks promising. But the crypto build complains:
LINK : fatal error LNK1104: cannot open file 'libcrypto.lib' [S:\3rdparty\Poco-build32\Crypto\Crypto.vcxproj]
That's strange: in the entire Crypto.vcxproj file, there is no mention of libcrypto.lib at all, only libcrypto32MD.lib and libcrypto32MDd.lib. Why is it even looking for libcrypto.lib? Even so, if it is supposed to be finding libcrypto.lib, why doesn't it succeed when it is freshly installed in C:\Program Files (x86)\OpenSSL-Win32\lib and OPENSSL_ROOT_DIR is set to C:\Program Files (x86)\OpenSSL-Win32? What am I missing? I got to this point via:
cmake -HS:\3rdparty\Poco -B S:\3rdparty\Poco-build32 -G "Visual Studio 16 2019" -A win32
cmake --build s:\3rdparty\Poco-build32 --config RelWithDebInfo
UPDATE: in case I modified anything while trying to make it build in other ways (buildwin.cmd, Batch Build in Visual Studio), I set the entire Poco file structure aside, and unzipped a fresh copy. The OpenSSL install is also fresh and untouched. The x64 build produces the identical error...
There is a hidden readme file https://github.com/pocoproject/poco/blob/master/README. I'm quoting:
Through the Poco/Crypto/Crypto.h and Poco/Net/NetSSL.h header files,
Visual C++ will automatically link the libcrypto.lib and libssl.lib
libraries. If your OpenSSL libraries are named differently, compile
with the macro POCO_EXTERNAL_OPENSSL defined and edit the project
files accordingly.
You can try to re-compile with the POCO_EXTERNAL_OPENSSL macro set accordingly (see Foundation/include/Poco/Config.h). (source)
Or what I did. Edit the file Crypto/include/Poco/Crypto/Crypto.h, remove all if-else logic around pragmas and leave only libraries that use have:
#pragma comment(lib, "libcrypto64md.lib")
#pragma comment(lib, "libssl64md.lib")
This is not a direct answer - it is an alternative build path that has been confirmed to produce viable DLLs. Try:
Start command line tool from Visual Studio
Invoke vcvars32.bat or vcvars64.bat to ensure environment is correct for Win32 or x64 build.
I found these scripts in C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build
Ensure the Poco buildwin.cmd script is configured to specify location of OpenSSL include and lib sub-folders
you will likely have to modify the script between builds if building both 32- and 64-bit builds since openSSL-Win32 and openSSL-Win64 are separate installations
specify include and lib paths for other components the same way (e.g. MySQL and/or PostgreSQL, etc)
Edit the Poco "components" file to eliminate any components not required that will stop build
Invoke buildwin, e.g.:
buildwin 160 shared both Win32 samples notests
buildwin 160 shared both x64 samples notests

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.

making conditions for linux and windows when linking libraries

Windows VC++ 2008
linux gcc 4.4.3
I have the following problem. When I compile on windows I need the ws2_32 library. However, when I compile on linux, I don't need to link this.
My CMakeLists.txt
INCLUDE_DIRECTORIES($CLIENT_SERVER_SOURCE_DIR/client)
INCLUDE_DIRECTORIES($CLIENT_SERVER_SOURCE_DIR/cltsvr_ults)
# Link the library
LINK_DIRECTORIES($CLIENT_SERVER_DIR/client)
# Add the executable
ADD_EXECUTABLE(clt test_clt)
# Link the executable to the client library
IF(WIN32)
TARGET_LINK_LIBRARIES(clt client ws2_32)
ENDIF(WIN32)
IF(CMAKE_COMPILER_IS_GNUCXXX)
TARGET_LINK_LIBRARIES(clt client)
ENDIF(CMAKE_COMPILER_IS_GNUCXXX)
I have tried unsuccessfully to compile under linux. Using the above conditions. However, It always tries to link the ws2_32 and I get a compile error. I think that the conditions aren't working, as it always falls through the WIN32 condition.
many thanks for any suggestions,
Since the WIN32 thing is such a fundamental part of CMake, I'd guess that there is more to this than what you mention.
Are you doing a clean check out of your code, or just copying up a whole directory on Linux? If you have all your CMake build files cached from the Windows build, maybe (just maybe!) something has snuck in there and "detects" itself as WIN32 on Linux?
Are you sure it is that line and not something else that causes the link to the stray Win-library? Maybe try a MESSAGE(STATUS "I am here")line within the IF(WIN32) just to make sure.
Are you sure the error is caused by linking that library? I can see a typo in your script, it should be IF(CMAKE_COMPILER_IS_GNUCXX) - you have an extra X on there. Perhaps you are not linking in what you thing you are, and that is why it fails.