cpp-best-practices / gui_starter_template

A template CMake project to get you started with C++ and tooling

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Failure upon building project on Windows

gary-desroches opened this issue · comments

I'm attempting to build a new project using this template and Clang.

I followed the instructions to install the apps via choco, expect I already had Visual Studio Enterprise installed, so I skipped that bit. I added everything to the Path. I also added CC and CCX environment variables. I selected "Visual Studio 16 2019" as the generator, ClangCl as the Optional toolset, and checked "use default native compilers" Upon configuring in cmake-gui, I get the following output.

Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.18363.
The CXX compiler identification is Clang 10.0.0 with MSVC-like command-line
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/Llvm/x64/bin/clang-cl.exe - skipped
Detecting CXX compile features
Detecting CXX compile features - done
ccache found and enabled
Conan: checking conan executable
Conan: Found program C:/Program Files/Conan/conan/conan.exe
Conan: Version found Conan version 1.32.0

Conan: Adding bincrafters remote repository (https://api.bintray.com/conan/bincrafters/public-conan)
Conan: Using cmake-multi generator
Conan: Automatic detection of conan settings from cmake
clang-cl
: warning: unknown argument ignored in clang-cl: '-x' [-Wunknown-argument]

clang-cl
: warning: unknown argument ignored in clang-cl: '-dM' [-Wunknown-argument]

clang-cl
: error: no such file or directory: 'c++'

Conan: Settings= -s;build_type=Release;-s;compiler=clang;-s;compiler.version=10;-s;compiler.libcxx=libc++
Conan: checking conan executable
Conan: Found program C:/Program Files/Conan/conan/conan.exe
Conan: Version found Conan version 1.32.0

Conan executing: C:/Program Files/Conan/conan/conan.exe install . -s build_type=Release -s compiler=clang -s compiler.version=10 -s compiler.libcxx=libc++ -g=cmake_multi --build=missing
Configuration:

[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=clang
compiler.libcxx=libc++
compiler.version=10
os=Windows
os_build=Windows
[options]
[build_requires]
[env]


conanfile.txt: 
Installing package
Requirements
    catch2/2.11.0 from 'conan-center' - Cache
    docopt.cpp/0.6.2 from 'conan-center' - Cache
    fmt/6.2.0 from 'conan-center' - Cache
    spdlog/1.5.0 from 'conan-center' - Cache
Packages
    catch2/2.11.0:5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9 - Cache
    docopt.cpp/0.6.2:96ea241aa3076f4628e6ccc36aec6371370a7e39 - Build
    fmt/6.2.0:96ea241aa3076f4628e6ccc36aec6371370a7e39 - Build
    spdlog/1.5.0:3a5fa269c7789182033bca003043705da37ce3d1 - Build


Installing (downloading, building) binaries...

catch2/2.11.0: 
Already installed!

docopt.cpp/0.6.2: 
Copying sources to build folder

docopt.cpp/0.6.2: 
Building your package in C:\Users\gary\.conan\data\docopt.cpp\0.6.2\_\_\build\96ea241aa3076f4628e6ccc36aec6371370a7e39

docopt.cpp/0.6.2: 
Generator cmake created conanbuildinfo.cmake

docopt.cpp/0.6.2: 
Calling build()

CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.


CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.

CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage

-- Configuring incomplete, errors occurred!

docopt.cpp/0.6.2: 


WARN: spdlog/1.5.0: requirement fmt/6.2.1 overridden by your conanfile to fmt/6.2.0 
docopt.cpp/0.6.2: WARN: Package binary is corrupted, removing: 96ea241aa3076f4628e6ccc36aec6371370a7e39
docopt.cpp/0.6.2: WARN: Build folder is dirty, removing it: C:\Users\gary\.conan\data\docopt.cpp\0.6.2\_\_\build\96ea241aa3076f4628e6ccc36aec6371370a7e39
docopt.cpp/0.6.2: ERROR: Package '96ea241aa3076f4628e6ccc36aec6371370a7e39' build failed
docopt.cpp/0.6.2: WARN: Build folder C:\Users\gary\.conan\data\docopt.cpp\0.6.2\_\_\build\96ea241aa3076f4628e6ccc36aec6371370a7e39
ERROR: docopt.cpp/0.6.2: Error in build() method, line 58
	cmake = self._configure_cmake()
while calling '_configure_cmake', line 52
	self._cmake.configure(build_folder=self._build_subfolder)
	ConanException: Error 1 while executing cd C:\Users\gary\.conan\data\docopt.cpp\0.6.2\_\_\build\96ea241aa3076f4628e6ccc36aec6371370a7e39\build_subfolder && cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE="Release" -DCONAN_IN_LOCAL_CACHE="ON" -DCONAN_COMPILER="c
lang" -DCONAN_COMPILER_VERSION="10" -DCONAN_CXX_FLAGS="-m64" -DCONAN_SHARED_LINKER_FLAGS="-m64" -DCONAN_C_FLAGS="-m64" -DCONAN_LIBCXX="libc++" -DBUILD_SHARED_LIBS="OFF" -DCMAKE_INSTALL_PREFIX="C:\Users\gary\.conan\data\docopt.cpp\0.6.2\_\_\package\96ea241aa3076f4628e6ccc36aec6371370a7e39" -DCMAKE_INSTALL_BINDIR="bin" -DCMAKE_INSTALL_SBINDIR="bin" -DCMAKE_INSTALL_LIBEXECDIR="bin" -DCMAKE_INSTALL_LIBDIR="lib" -DCMAKE_INSTALL_INCLUDEDIR="include" -DCMAKE_INSTALL_OLDINCLUDEDIR="include" -DCMAKE_INSTALL_DATAROOTDIR="share" -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY="ON" -DCONAN_EXPORTED="1" -DUSE_BOOST_REGEX="False" -Wno-dev C:\Users\gary\.conan\data\docopt.cpp\0.6.2\_\_\build\96ea241aa3076f4628e6ccc36aec6371370a7e39

CMake Error at build/conan.cmake:402 (message):
  Conan install failed='1'
Call Stack (most recent call first):
  build/conan.cmake:492 (conan_cmake_install)
  cmake/Conan.cmake:16 (conan_cmake_run)
  CMakeLists.txt:76 (run_conan)


Configuring incomplete, errors occurred!
See also "C:/Dev/Code/TheCodeFiend/vulkan-cmake-clang-vs/build/CMakeFiles/CMakeOutput.log".

@gary-desroches this appears to be a bug specific to building docopt.cpp on MSVC/Clang configuration. Have you been able to resolve this problem since you reported it?

@lefticus I managed to get the build process working on my Windows setup using MSVC/Clang. Unfortunately I'm pretty new to C++ and CMAKE and I don't have a proper solution for this but maybe this info can help someone more knowledgeable address this.

From what I could tell it seems that CMAKE_COMPILER_ID, which is "Clang" under these conditions results in a misconfiguration in build/conan.cmake around lines 154 and 174 which looks to be expecting the CMAKE_COMPILER_ID to be MSVC. I don't know if this is Conan making an incorrect assumption or some issue in this setup.

I managed to get everything building fine by setting the CMAKE_CXX_COMPILER_ID to MSVC and CMAKE_CXX_GENERATOR_TOOLSET to ClangCL before Conan.cmake invokes conan.cmake/conan_cmake_run() and it results in conan generating a working batch of settings that look something like this:

[settings]
arch=x86_64
arch_build=x86_64
build_type=Debug
compiler=Visual Studio
compiler.runtime=MDd
compiler.toolset=ClangCL
compiler.version=16
os=Windows
os_build=Windows
[options]
[build_requires]
[env]

I do revert the CMAKE_COMPILER_ID and CMAKE_GENERATOR_TOOLSET after this call but because I'm pretty clueless about most of this I'm not sure what the repercussions would be. I'm don't know if any of this is useful but hopefully someone here has an idea how this should be fixed up correctly.

For my own purposes I have worked around this by checking against these variables and modifying the cmake/Conan.cmake file to look something like this:

set (PROJECT_IS_MSVC_CLANG (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" AND ${CMAKE_CXX_COMPILER_FRONTEND_VARIANT} STREQUAL "MSVC"))

if (PROJECT_IS_MSVC_CLANG)
  set(PREV_CMAKE_CXX_COMPILER_ID ${CMAKE_CXX_COMPILER_ID})
  set(PREV_CMAKE_CXX_GENERATOR_TOOLSET ${CMAKE_CXX_GENERATOR_TOOLSET})
  set(CMAKE_CXX_COMPILER_ID MSVC)
  set(CMAKE_CXX_GENERATOR_TOOLSET ClangCL)
endif ()  
  
conan_cmake_run(
  REQUIRES
  ${CONAN_EXTRA_REQUIRES}
  catch2/2.13.3
  docopt.cpp/0.6.2
  fmt/6.2.0
  spdlog/1.5.0
  OPTIONS
  ${CONAN_EXTRA_OPTIONS}
  BASIC_SETUP
  CMAKE_TARGETS # individual targets to link to
  BUILD
  missing)

if (PROJECT_IS_MSVC_CLANG)
  set(CMAKE_CXX_COMPILER_ID ${PREV_CMAKE_CXX_COMPILER_ID})
  set(CMAKE_CXX_GENERATOR_TOOLSET ${PREV_CMAKE_CXX_GENERATOR_TOOLSET})
endif ()  

Probably a horrendous hack but it works for me until the conan packages handle this correctly.

Has anyone tried the fix proposed in #122 for this problem? I don't know if it works, but it looks a little cleaner.

I'm not able to reproduce this problem myself, otherwise I would try the fix.

Has anyone tried the fix proposed in #122 for this problem? I don't know if it works, but it looks a little cleaner.

I'm not able to reproduce this problem myself, otherwise I would try the fix.

I tried it, and I got the following error upon configuring.

Conan executing: C:/Program Files/Conan/conan/conan.exe install . -s build_type=Release -s compiler=clang -s compiler.version=11 -s compiler.libcxx=libc++ -e=CC= -e=CXX=C:/Program Files/LLVM/bin/clang-cl.exe -e=catch2/2.13.3 -e=docopt.cpp/0.6.2 -e=fmt/6.2.0 -e=spdlog/1.5.0 -g=cmake_multi --build=missing
ERROR: Invalid input 'catch2/2.13.3', use 'name=value'

Also, is this just setting environment variables to Clang? Setting them is a part of the instructions, so I already have them.

Edit: Actually, I had CC and CXX not the CMAKE_ versions. I set them as environment variables and tried again. I get the same errors, even the ones saying I'm missing those.

@gary-desroches this appears to be a bug specific to building docopt.cpp on MSVC/Clang configuration. Have you been able to resolve this problem since you reported it?

Not yet.

Has anyone tried using Conan profiles (https://docs.conan.io/en/latest/reference/profiles.html)? This is one of the approaches frequently suggested by people in the Conan community who are having trouble building with a specific toolchain. I think you can use a Conan profile to mimic what @BrendonSmuts was doing, without adding any compiler-specific code to Conan.cmake.

You would need to pass the path to your profile into cmake_conan_run:

conan_cmake_run(
    ...
    PROFILE ${PATH_TO_USER_CONAN_PROFILE}
    ...
)

I think you can use PROFILE default if the user doesn't have a Conan profile.

See https://github.com/conan-io/cmake-conan#profile and https://docs.conan.io/en/latest/using_packages/using_profiles.html for docs.

Edit: Whoops, seems like this is an ongoing issue with Conan and clang-cl, depending on the dependency you're building. According to this comment, (conan-io/conan#1839 (comment)), which includes a working clang-cl Conan profile, "some third-party Conan package recipes that we use haven't accounted for the possibility of compiler=clang when os=Windows".

I think we can close this issue now, as cpp-boilerplate-project has builds for windows/llvm