I am trying to set up vcpkg with a CMake project. Since I intend to have multiple people with different platforms working on this project, I wanted to use an Environment Variable to set CMAKE_TOOLCHAIN_FILE instead of a command line argument as recommended here for cmake: https://vcpkg.readthedocs.io/en/latest/users/integration/
However, It appears that CMake is unable to find the VCPKG_ROOT environment variable. I made a small example separate from my project to see if the problem still exists and it does. Here is my CMakeLists.txt file:
cmake_minimum_required (VERSION 3.8)
#vcpkg init
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
MESSAGE("vcpkg root found")
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "")
else()
MESSAGE("vcpkg not found")
endif()
project ("CmakeVcpkgTestF")
add_executable (CmakeVcpkgTestF "CmakeVcpkgTestF.cpp" "CmakeVcpkgTestF.h")
And here is the associated output when buliding, note that "vcpkg not found is output" instead of "vcpkg root found"
1> CMake generation started for default configuration: 'x64-Debug (default)'.
1> Command line: "cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="F:\VisualStudio2019\CmakeVcpkgTestF\out\install\x64-Debug (default)" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "F:\VisualStudio2019\CmakeVcpkgTestF" 2>&1"
1> Working directory: F:\VisualStudio2019\CmakeVcpkgTestF\out\build\x64-Debug (default)
1> [CMake] vcpkg not found
1> [CMake] -- Configuring done
1> [CMake] -- Generating done
1> [CMake] -- Build files have been written to: F:/VisualStudio2019/CmakeVcpkgTestF/out/build/x64-Debug (default)
1> Extracted CMake variables.
1> Extracted source files and headers.
1> Extracted code model.
1> Extracted includes paths.
1> CMake generation finished.
So far all I have done install vcpkg (running the required bootstrap as well), is there something else I need to do to get this to work? Also it is worth noting that vcpkg is installed at the root of my drive(specifically F:/vcpkg/vcpkg), not at root of the code, but I don't imagine that is causing the problem.
Thanks in advance for any assistance.
Based on your output, this is the second time your code has run. Your if condition asks whether CMAKE_TOOLCHAIN_FILE is defined at all, but it is! You defined it as a cache variable, which was then loaded into the global scope on the second run.
You probably want a test more like this:
set(vcpkg "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
if(NOT CMAKE_TOOLCHAIN_FILE AND EXISTS "${vcpkg}")
set(CMAKE_TOOLCHAIN_FILE "${vcpkg}"
CACHE FILEPATH "CMake toolchain file")
message(STATUS "vcpkg toolchain found: ${CMAKE_TOOLCHAIN_FILE}")
endif()
Related
I have the following cmake file:
cmake_minimum_required(VERSION 3.15)
add_subdirectory(googletest)
add_subdirectory(zlib)
# libpng setup
option(PNG_TESTS OFF)
set(PNG_TESTS OFF)
option(PNG_SHARED OFF)
set(PNG_SHARED OFF)
option(PNG_EXECUTABLES OFF)
set(PNG_EXECUTABLES OFF)
option(PNG_BUILD_ZLIB ON)
set(PNG_BUILD_ZLIB ON)
set(ZLIB_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/zlib" "${CMAKE_CURRENT_BINARY_DIR}/zlib")
set(ZLIB_LIBRARY "zlib")
add_subdirectory(libpng)
This generates the project correctly and zlib/googletest build is OK. pnglib on the other hand doesn't build:
1>Generating pnglibconf.out
1>Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29337 for x64
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>
1>pnglibconf.c
1>build/thirdparty/libpng/pnglibconf.c(34): fatal error C1083: Cannot open include file: 'zlib.h': No such file or directory
1>CMake Error at scripts/genout.cmake:78 (message):
1> Failed to generate build/thirdparty/libpng/pnglibconf.out.tf1
1>
1>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(238,5): error MSB8066: Custom build for 'build\CMakeFiles\4c907688e112b5b30b06f56662306981\pnglibconf.out.rule;build\CMakeFiles\4c907688e112b5b30b06f56662306981\pnglibconf.h.rule;build\CMakeFiles\5a2501006db4b4e75991d2f2c16bfadf\sym.out.rule;build\CMakeFiles\4c907688e112b5b30b06f56662306981\libpng.sym.rule;build\CMakeFiles\5a2501006db4b4e75991d2f2c16bfadf\vers.out.rule;build\CMakeFiles\4c907688e112b5b30b06f56662306981\libpng.vers.rule;build\CMakeFiles\5a2501006db4b4e75991d2f2c16bfadf\intprefix.out.rule;build\CMakeFiles\5a2501006db4b4e75991d2f2c16bfadf\prefix.out.rule;build\CMakeFiles\5a2501006db4b4e75991d2f2c16bfadf\symbols.chk.rule;build\CMakeFiles\e5199c38ed750451ee22eda432b56e2c\genfiles.rule' exited with code 1.
1>Done building project "genfiles.vcxproj" -- FAILED.
If I manually copy ${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt to ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h as genfiles target should do pnglib_static compiles fine.
...
if(NOT AWK OR ANDROID OR IOS)
# No awk available to generate sources; use pre-built pnglibconf.h
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt
${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h)
add_custom_target(genfiles) # Dummy
else()
...
Any idea on how to fix this? I would like to not alter the CMakeLists.txt from libpng to be easier to update to newer versions. I'm using the latest version from url = git://git.code.sf.net/p/libpng/code as documented on http://www.libpng.org/pub/png/libpng.html
After reading genout.cmake I've found this line:
set(AWK "C:/Program Files/Git/usr/bin/gawk.exe")
If I run CMake from cmd instead of git bash genout.cmake contains:
set(AWK "AWK-NOTFOUND")
Probably running CMake from git bash confuses the build system, but running CMake from cmd generates the project correctly.
I'm trying to compile a simple app to test a few libraries I might be using in the future. Because of some problems I had with msvc I tried Clang, which made a strange error I got disappear.
The problem I have now is that the libraries I want to test use OpenMP. They import it using the FindOpenMP module CMake privides. However the module doesn't find it with Clang.
cmake_minimum_required(VERSION 3.14.0)
project(blaze-test VERSION 0.1.0)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(OpenMP)
I got this output :
1> CMake generation started for configuration: 'x64-Debug'.
1> Environment settings:
1> CXXFLAGS=-m64 -fdiagnostics-absolute-paths
1> CFLAGS=-m64 -fdiagnostics-absolute-paths
1> Command line: "cmd.exe" /c ""C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe" -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="PATH\blaze-test\install\x64-Debug" -DCMAKE_CXX_COMPILER:FILEPATH="C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO/2019/COMMUNITY/VC/Tools/Llvm/8.0.0/bin/clang-cl.exe" -DCMAKE_C_COMPILER:FILEPATH="C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO/2019/COMMUNITY/VC/Tools/Llvm/8.0.0/bin/clang-cl.exe" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "PATH\blaze-test" 2>&1"
1> Working directory: PATH\blaze-test\build\x64-Debug
1> [CMake] -- The C compiler identification is Clang 8.0.0
1> [CMake] -- The CXX compiler identification is Clang 8.0.0
1> [CMake] -- Check for working C compiler: C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO/2019/COMMUNITY/VC/Tools/Llvm/8.0.0/bin/clang-cl.exe
1> [CMake] -- Check for working C compiler: C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO/2019/COMMUNITY/VC/Tools/Llvm/8.0.0/bin/clang-cl.exe -- works
1> [CMake] -- Detecting C compiler ABI info
1> [CMake] -- Detecting C compiler ABI info - done
1> [CMake] -- Detecting C compile features
1> [CMake] -- Detecting C compile features - done
1> [CMake] -- Check for working CXX compiler: C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO/2019/COMMUNITY/VC/Tools/Llvm/8.0.0/bin/clang-cl.exe
1> [CMake] -- Check for working CXX compiler: C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO/2019/COMMUNITY/VC/Tools/Llvm/8.0.0/bin/clang-cl.exe -- works
1> [CMake] -- Detecting CXX compiler ABI info
1> [CMake] -- Detecting CXX compiler ABI info - done
1> [CMake] -- Detecting CXX compile features
1> [CMake] -- Detecting CXX compile features - done
1> [CMake] -- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
1> [CMake] -- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
1> [CMake] -- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)
Based on this I added
set(OpenMP_CXX_FLAGS "-Xclang -fopenmp" CACHE STRING "" FORCE)
set(OpenMP_C_FLAGS "-Xclang -fopenmp" CACHE STRING "" FORCE)
right before the find_package call. It removed the part about the compiler flags from the error message. I added libomp.lib the same way. Then I get
1> [CMake] -- Could NOT find OpenMP_C (missing: OpenMP_C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/Llvm/8.0.0/lib/libomp.lib_LIBRARY)
1> [CMake] -- Could NOT find OpenMP_CXX (missing: OpenMP_C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/Llvm/8.0.0/lib/libomp.lib_LIBRARY)
1> [CMake] -- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)
I hope someone can tell me how to get CMake to find it. These unreliable Find Modules are really annoying.
ps: I'm using Clang 8 (clang-cl.exe) with CMake 3.14 and Visual Studio 2019.
When using find_package(OpenMP REQUIRED), I have also received similar errors when using clang-cl from Visual Studio. There are known limitations with CMake's FindOpenMP.cmake module, as well as some lack of support the clang-cl side. There are other answers on this site suggesting to populate the CMake OpenMP_ variables manually, but this seems backwards. When I tried it, CMake claimed that OpenMP was FOUND, but the paths to the libraries was still unknown and compilation was unsuccessful. I was able to successfully run CMake then compile my applications with MSVC+Clang by avoiding the use of find_package and (unfortunately) hard-coding the path to the OpenMP libraries for now:
cmake_minimum_required(VERSION 3.14.0)
project(blaze-test VERSION 0.1.0)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(OpenMP_LIBRARY_DIR "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/Llvm/lib")
set(OpenMP_CXX_FLAGS "-Xclang -fopenmp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
# Tell CMake where to find the OpenMP libraries.
link_directories(${OpenMP_LIBRARY_DIR})
# Library
add_library(MyLibrary SHARED MyExample.h MyExample.cpp)
# Link in the OpenMP libraries.
target_link_libraries(MyLibrary PUBLIC libomp libiomp5md)
# Executable
add_executable(MyOpenMpTest MyOpenMpTest .cpp)
target_link_libraries(MyOpenMpTest MyLibrary)
Hopefully, the folks at CMake and LLVM will get this issue worked out soon and FindOpenMP.cmake can be used more reliably.
I'm trying to setup a development environment for C++ to compile under Linux x64 using CMake integration with VS2017. To better manage dependencies I choose to use Conan but I'm pretty new to this software and I'm wondering what's the best way to have VS2017 to recognize the dependencies of the project.
For example, I've used Conan to install the POCO library for C++ but when I open the Main.cpp file it doesn't recognise the header files location and I'm not really sure where to add those paths.
Can anyone give some hints to solve this?
If needed all the source files are in my Github repo CppLinuxVS.
UPDATE
As per comments on this post, below you can find the contents of the files:
CMakeLists.txt
project(CppLinuxVS)
cmake_minimum_required(VERSION 2.8.12)
add_definitions("-std=c++11")
# Download automatically, you can also just copy the conan.cmake file
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/v0.8/conan.cmake"
"${CMAKE_BINARY_DIR}/conan.cmake")
endif()
include(${CMAKE_BINARY_DIR}/conan.cmake)
conan_cmake_run(CONANFILE conanfile.txt
BASIC_SETUP CMAKE_TARGETS
BUILD missing)
add_executable(CppLinuxVS Main.cpp)
target_link_libraries(CppLinuxVS ${CONAN_LIST})
conanfile.txt
[requires]
Poco/1.8.0#pocoproject/stable
[generators]
cmake
UPDATE 2
Output of CMake inside VS2017 after downloading the conan.cmake file into the project instead of having the download specified in CMakeLists.txt. Also updated the CMakeLists.txt to require CMake 3.1.2 as per suggestion in the comments.
1> 17:52:57: Copying files to remote machine...
1> 17:53:00: Finished copying files (elapsed time 00h:00m:02s:799ms).
1> /usr/local/bin/cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="Debug" "\var\tmp\src\03967bd6-44be-4e31-b449-a34a45d7109d\Linux-Debug"
1> -- Conan ** WARNING** : This detection of settings from cmake is experimental and incomplete. Please check 'conan.cmake' and contribute
1> -- Conan executing: conan install /var/tmp/src/03967bd6-44be-4e31-b449-a34a45d7109d/Linux-Debug/conanfile.txt -g cmake -s build_type=Debug -s os=Linux -s compiler=gcc -s compiler.version=5 -s compiler.libcxx=libstdc++11 --build=missing
1> PROJECT: Installing /var/tmp/src/03967bd6-44be-4e31-b449-a34a45d7109d/Linux-Debug/conanfile.txt
1> Requirements
1> OpenSSL/1.0.2l#conan/stable from 'conan-center'
1> Poco/1.8.0#pocoproject/stable from 'conan-center'
1> zlib/1.2.11#conan/stable from 'conan-center'
1> Packages
1> OpenSSL/1.0.2l#conan/stable:f68b4e006611addfaec53a2f3d5c0e6b0406266d
1> Poco/1.8.0#pocoproject/stable:e3d8f1070a587658375103e87fd35c8b5c372b6e
1> zlib/1.2.11#conan/stable:15c6f8a55cbf8b39b86ca055629a91be1b2d3cf5
1>
1> zlib/1.2.11#conan/stable: Already installed!
1> OpenSSL/1.0.2l#conan/stable: Already installed!
1> Poco/1.8.0#pocoproject/stable: Already installed!
1> PROJECT: Generator cmake created conanbuildinfo.cmake
1> PROJECT: Generator txt created conanbuildinfo.txt
1> PROJECT: Generated conaninfo.txt
1> -- Conan: Loading conanbuildinfo.cmake
1> -- Current conanbuildinfo.cmake directory: /var/tmp/build/03967bd6-44be-4e31-b449-a34a45d7109d/build/Linux-Debug
1> -- Conan: Compiler GCC>=5, checking major version 5
1> -- Conan: Checking correct version: 5
1> -- Conan: Using cmake targets configuration
1> -- Library PocoUtild found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoUtild.a
1> -- Library PocoMongoDBd found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoMongoDBd.a
1> -- Library PocoNetd found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoNetd.a
1> -- Library PocoNetSSLd found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoNetSSLd.a
1> -- Library PocoCryptod found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoCryptod.a
1> -- Library PocoDatad found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoDatad.a
1> -- Library PocoDataSQLited found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoDataSQLited.a
1> -- Library PocoZipd found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoZipd.a
1> -- Library PocoXMLd found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoXMLd.a
1> -- Library PocoJSONd found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoJSONd.a
1> -- Library PocoFoundationd found /root/.conan/data/Poco/1.8.0/pocoproject/stable/package/e3d8f1070a587658375103e87fd35c8b5c372b6e/lib/libPocoFoundationd.a
1> -- Library pthread not found in package, might be system one
1> -- Library dl not found in package, might be system one
1> -- Library rt not found in package, might be system one
1> -- Library ssl found /root/.conan/data/OpenSSL/1.0.2l/conan/stable/package/f68b4e006611addfaec53a2f3d5c0e6b0406266d/lib/libssl.a
1> -- Library crypto found /root/.conan/data/OpenSSL/1.0.2l/conan/stable/package/f68b4e006611addfaec53a2f3d5c0e6b0406266d/lib/libcrypto.a
1> -- Library dl not found in package, might be system one
1> -- Library z found /root/.conan/data/zlib/1.2.11/conan/stable/package/15c6f8a55cbf8b39b86ca055629a91be1b2d3cf5/lib/libz.a
1> -- Conan: Adjusting default RPATHs Conan policies
1> -- Conan: Adjusting language standard
1> -- Configuring done
1> -- Generating done
1> -- Build files have been written to: /var/tmp/build/03967bd6-44be-4e31-b449-a34a45d7109d/build/Linux-Debug
1> Starting CMake target info extraction ...
1> Extracted source files and headers.
1> Extracted global settings.
1> Extracted code model.
1> Collating data ...
1> Target info extraction done.
CMakeLists.txt updated
project(CppLinuxVS)
cmake_minimum_required(VERSION 3.1.2)
add_definitions("-std=c++11")
include(conan.cmake)
conan_cmake_run(CONANFILE conanfile.txt
BASIC_SETUP CMAKE_TARGETS
BUILD missing)
add_executable(CppLinuxVS Main.cpp)
target_link_libraries(CppLinuxVS ${CONAN_LIBS})
#lusocoding here is a project i setup to demonstrate a working combination of VS -> Cmake -> Conan.
https://github.com/solvingj/vs-cmake-conan-demo
One of the critical parts (as I recall) was CMakeSettings.json, which is supposed to be a machine-specific setting that you don't typically commit to git. However, at the time, there were customizations (i think it was the CLI flags passed to CMake) which i had to add to to make it work. So, i committed that file to git for the demonstration.
See if you can clone and use the project as is, and then slowly compare with your project to find differences.
Hope this helps.
When using CMake to generate a Visual Studio 15 Solution for the 64 bit architecture one has to first call vcvarsall.bat amd64 and then call cmake with the generator option cmake . -Bbuild -G"Visual Studio 14 2015 Win64". CMake will then determine the value of a couple of variables when executing the project() function.
CMAKE_GENERATOR: Visual Studio 14 2015 Win64
CMAKE_BUILD_TOOL: C:/Program Files (x86)/MSBuild/14.0/bin/MSBuild.exe
CMAKE_CXX_COMPILER: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
CMAKE_C_COMPILER: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
CMAKE_LINKER: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/link.exe
CMAKE_CXX_COMPILER_ID: MSVC
CMAKE_CXX_COMPILER_VERSION: 19.0.24215.1
CMAKE_VS_PLATFORM_NAME: x64
I would like to get rid of the call to vcvarsall.bat and the -G"generator" option by setting the values of the variables in a toolchain file like this:
# VisualStudio2015.cmake
set(CMAKE_GENERATOR "Visual Studio 14 2015 Win64" CACHE STRING "The CMake generator" FORCE )
set(CMAKE_BUILD_TOOL "C:/Program Files (x86)/MSBuild/14.0/bin/MSBuild.exe" CACHE FILEPATH "The visual studio build-system" FORCE)
set(CMAKE_CXX_COMPILER "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe" CACHE FILEPATH "Microsoft compiler" FORCE)
set(CMAKE_C_COMPILER "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe" CACHE FILEPATH "Microsoft compiler" FORCE)
set(CMAKE_LINKER "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/link.exe" CACHE FILEPATH "Microsoft linker" FORCE)
set(CMAKE_CXX_COMPILER_ID MSCV CACHE STRING "The Id string of the compiler" FORCE)
set(CMAKE_CXX_COMPILER_VERSION 19.0.24215.1 CACHE STRING "The version of the compiler" FORCE)
set(CMAKE_VS_PLATFORM_NAME x64 CACHE STRING "Target processor architecture" FORCE)
and then call cmake with the CMAKE_TOOLCHAIN_FILE option:
cmake . -Bbuild -DCMAKE_TOOLCHAIN_FILE=VisualStudio2015.cmake
The problem is that this does not seem to work. When cmake executes the project() function it overrides the values for the compiler that I have set. So do I just forget to set some variables that are required or is this simply not possible?
Thank you for your time.
Turning my comment into an answer
I think what your are looking for is not a toolchain file (since you can't change the CMAKE_GENERATOR there), but the -C <initial-cache> option to "Pre-load a script to populate the cache".
And you shouldn't put too many of the values CMake normally detects/evaluates into the script.
So I've successfully tested the following:
VS2015InitialCache.cmake
set(CMAKE_GENERATOR "Visual Studio 14 2015 Win64" CACHE STRING "The CMake generator" FORCE)
set(CMAKE_CACHE_INIT_FILE "${CMAKE_CURRENT_LIST_FILE}" CACHE STRING "The CMake cache init file used" FORCE)
set(CMAKE_MAKE_PROGRAM "C:/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/devenv.com" CACHE FILEPATH "Microsoft compiler" FORCE)
set(CMAKE_CXX_COMPILER "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe" CACHE FILEPATH "Microsoft CXX compiler" FORCE)
set(CMAKE_C_COMPILER "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe" CACHE FILEPATH "Microsoft C compiler" FORCE)
And then you call:
> cmake -CVS2015InitialCache.cmake -H. -Bbuild
loading initial cache file VS2015InitialCache.cmake
-- The C compiler identification is MSVC 19.0.24215.1
-- The CXX compiler identification is MSVC 19.0.24215.1
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
...
References
CMake preload script for cache
CMake: Generating batch file calling cl.exe
I'm trying to to use CMAKE with Visual Studio Buildtools 2017; and no matter what combination of flags or otherwise I am unable to get a working compilation. (I tried buildtools 2015 as well) I'm unable to access UWP libs, specifically platform.winmd
I always end with
fatal error C1107: could not find assembly 'platform.winmd': please specify the assembly search path using /AI or by setting the LIBPATH environment variable [C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test\build\winsearch.vcxproj]
My CMAKELISTS.txt looks like:
cmake_minimum_required(VERSION 3.7)
set(lib "winsearch")
file(GLOB SOURCE_FILES "src/module/winSearch/*.cpp" "src/module/winSearch/*.h")
add_library( ${lib} SHARED ${SOURCE_FILES})
set( MSVS15_COMPILE_FLAGS "/ZW" )
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MSVS15_COMPILE_FLAGS}" )
set_target_properties(${lib} PROPERTIES PREFIX "" SUFFIX ".node")
target_include_directories(${lib} PRIVATE ${CMAKE_JS_INC})
target_link_libraries(${lib} ${CMAKE_JS_LIB})
And I have removed all the source except for a blank function and a call to include #include <collection.h>
CMAKE itself is being called like:
cmake.exe "C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test" --no-warn-unused-cli -G"Visual Studio 15 2017 Win64" -DCMAKE_JS_VERSION="3.4.0" -DCMAKE_BUILD_TYPE="Release" -DCMAKE_RUNTIME_OUTPUT_DIRECTORY="C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test\build" -DCMAKE_JS_INC="C:\Users\ehiller\.cmake-js\electron-x64\v1.4.5\src;C:\Users\ehiller\.cmake-js\electron-x64\v1.4.5\deps\v8\include;C:\Users\ehiller\.cmake-js\electron-x64\v1.4.5\deps\uv\include;C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test\node_modules\nan" -DNODE_RUNTIME="electron" -DNODE_RUNTIMEVERSION="1.4.5" -DNODE_ARCH="x64" -DCMAKE_JS_LIB="C:\Users\ehiller\.cmake-js\electron-x64\v1.4.5\x64\node.lib"
The full output upon execution is:
info TOOL Using Visual Studio 15 2017 Win64 generator, as specified from commandline.
info CMD CLEAN
info RUN C:\Users\ehiller\AppData\Local\omega\system\cmake\bin\cmake.exe -E remove_directory "C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test\build"
> uwp-js-test#0.0.1 compile C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test
> cmake-js build -c "C:\Users\ehiller\AppData\Local\omega\system\cmake\bin\cmake.exe" -G "Visual Studio 15 2017 Win64"
info TOOL Using Visual Studio 15 2017 Win64 generator, as specified from commandline.
info CMD CONFIGURE
info RUN C:\Users\ehiller\AppData\Local\omega\system\cmake\bin\cmake.exe "C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test" --no-warn-unused-cli -G"Visual Studio 15 2017 Win64" -DCMAKE_JS_VERSION="3.4.0" -DCMAKE_BUILD_TYPE="Release" -DCMAKE_RUNTIME_OUTPUT_DIRECTORY="C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test\build" -DCMAKE_JS_INC="C:\Users\ehiller\.cmake-js\electron-x64\v1.4.5\src;C:\Users\ehiller\.cmake-js\electron-x64\v1.4.5\deps\v8\include;C:\Users\ehiller\.cmake-js\electron-x64\v1.4.5\deps\uv\include;C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test\node_modules\nan" -DNODE_RUNTIME="electron" -DNODE_RUNTIMEVERSION="1.4.5" -DNODE_ARCH="x64" -DCMAKE_JS_LIB="C:\Users\ehiller\.cmake-js\electron-x64\v1.4.5\x64\node.lib"
Not searching for unused variables given on the command line.
-- The C compiler identification is MSVC 19.10.24930.0
-- The CXX compiler identification is MSVC 19.10.24930.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.10.24930/bin/HostX86/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.10.24930/bin/HostX86/x64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.10.24930/bin/HostX86/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.10.24930/bin/HostX86/x64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/ehiller/Dev/src/github.com/erichiller/uwp-js-test/build
info CMD BUILD
info RUN C:\Users\ehiller\AppData\Local\omega\system\cmake\bin\cmake.exe --build "C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test\build" --config Release
Microsoft (R) Build Engine version 15.1.545.13942
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 2/18/2017 9:27:58 PM.
Project "C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test\build\ALL_BUILD.vcxproj" on node 1 (default targets).
Project "C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test\build\ALL_BUILD.vcxproj" (1) is building "C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-te st\build\ZERO_CHECK.vcxproj" (2) on node 1 (default targets).
PrepareForBuild:
Creating directory "x64\Release\ZERO_CHECK\".
Creating directory "x64\Release\ZERO_CHECK\ZERO_CHECK.tlog\".
InitializeBuildStatus:
Creating "x64\Release\ZERO_CHECK\ZERO_CHECK.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
CustomBuild:
Checking Build System
CMake does not need to re-run because C:/Users/ehiller/Dev/src/github.com/erichiller/uwp-js-test/build/CMakeFiles/generate.stamp is up-to-date.
FinalizeBuildStatus:
Deleting file "x64\Release\ZERO_CHECK\ZERO_CHECK.tlog\unsuccessfulbuild".
Touching "x64\Release\ZERO_CHECK\ZERO_CHECK.tlog\ZERO_CHECK.lastbuildstate".
Done Building Project "C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test\build\ZERO_CHECK.vcxproj" (default targets).
Project "C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test\build\ALL_BUILD.vcxproj" (1) is building "C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-te st\build\winsearch.vcxproj" (3) on node 1 (default targets).
PrepareForBuild:
Creating directory "winsearch.dir\Release\".
Creating directory "C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test\build\Release\".
Creating directory "winsearch.dir\Release\winsearch.tlog\".
InitializeBuildStatus:
Creating "winsearch.dir\Release\winsearch.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
CustomBuild:
Building Custom Rule C:/Users/ehiller/Dev/src/github.com/erichiller/uwp-js-test/CMakeLists.txt
CMake does not need to re-run because C:/Users/ehiller/Dev/src/github.com/erichiller/uwp-js-test/build/CMakeFiles/generate.stamp is up-to-date.
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.10.24930\bin\HostX86\x64\CL.exe /c /I"C:\Users\ehiller\.cmake-js\electron-x64\v1.4.5
\src" /I"C:\Users\ehiller\.cmake-js\electron-x64\v1.4.5\deps\v8\include" /I"C:\Users\ehiller\.cmake-js\electron-x64\v1.4.5\deps\uv\include" /I"C:\Users\ehiller\Dev\
src\github.com\erichiller\uwp-js-test\node_modules\nan" /ZW /nologo /W3 /WX- /diagnostics:classic /O2 /Ob2 /D WIN32 /D _WINDOWS /D NDEBUG /D "CMAKE_INTDIR=\"Release
\"" /D winsearch_EXPORTS /D _WINDLL /D _MBCS /Gm- /EHsc /MD /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR /Fo"winsearch.dir\Release\\" /Fd"winsearch.dir\R
elease\vc141.pdb" /Gd /TP /errorReport:queue "C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test\src\module\winSearch\winSearch.cpp"
winSearch.cpp
C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test\src\module\winSearch\winSearch.cpp : fatal error C1107: could not find assembly 'platform.winmd': please sp ecify the assembly search path using /AI or by setting the LIBPATH environment variable [C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test\build\winsearch.vc xproj]
Done Building Project "C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test\build\winsearch.vcxproj" (default targets) -- FAILED.
Done Building Project "C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test\build\ALL_BUILD.vcxproj" (default targets) -- FAILED.
Build FAILED.
"C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test\build\ALL_BUILD.vcxproj" (default target) (1) ->
"C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test\build\winsearch.vcxproj" (default target) (3) ->
(ClCompile target) ->
C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test\src\module\winSearch\winSearch.cpp : fatal error C1107: could not find assembly 'platform.winmd': please
specify the assembly search path using /AI or by setting the LIBPATH environment variable [C:\Users\ehiller\Dev\src\github.com\erichiller\uwp-js-test\build\winsearch. vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.49
I have
C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd
C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.10.24930/lib/x86/store/references/platform.winmd
And I tried including them as libraries with
target_link_libraries( ${lib} "C:/Program Files (x86)/Windows Kits/10/UnionMetadata/Windows.winmd" )
TARGET_LINK_LIBRARIES(${lib} "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.10.24930/lib/x86/store/references/platform.winmd")
But none of that does anything either.
Nor does setting the CMAKE_SYSTEM_NAME
set( CMAKE_SYSTEM_NAME WindowsStore )
or the CMAKE_SYSTEM_VERSION
set( CMAKE_SYSTEM_VERSION 10.0 )
I even tried setting the library to every directory I could find in the sdk.bat file:
set( sd "C:/Program Files (x86)/Windows Kits/10/" )
set( WindowsSDKVersion "10.0.14393.0" )
target_link_libraries( ${lib} "${sd}bin")
target_link_libraries( ${lib} "${sd}UnionMetadata")
target_link_libraries( ${lib} "${sd}References")
target_link_libraries( ${lib} "${sd}bin")
target_link_libraries( ${lib} "{sd}bin" )
target_link_libraries( ${lib} "${sd}UnionMetadata" )
target_link_libraries( ${lib} "${sd}References" )
target_link_libraries( ${lib} "${sd}lib/${WindowsSDKLibVersion}/um/${NODE_ARCH}" )
target_link_libraries( ${lib} "${sd}include/${WindowsSDKVersion}/shared/" )
target_link_libraries( ${lib} "${sd}include/${WindowsSDKVersion}/um/" )
target_link_libraries( ${lib} "${sd}include/${WindowsSDKVersion}/winrt/" )
target_link_libraries( ${lib} "${sd}References/CommonConfiguration/Neutral" )
But that wasn't it either.
So I am at the point now that I am sure I missing something obvious. So I am hoping somebody can help me out here! Thanks!
(by the way, the cmake-js is a frontend for cmake, it just passes the flags right along to cmake and should not affect the system, but just to make sure, I tried running cmake directly, with the same results)
According to Microsoft's documentation to specify metadata directories, you have to pass the compiler option -AI"directory-path" for the winmd libraries. For the case of Visual C++ 2017, try augmenting the C++ options in your CMakeLists.txt file like this:
# windows.winmd search path:
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -AI\"C:/Program Files (x86)/Windows Kits/10/UnionMetadata\"" )
# platform.winmd search path for MSVC 2017:
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -AI\"C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/VC/vcpackages\"" )
I have tested these two search paths only on Visual Studio 2017 and Windows 10. You will have to modify one or possibly both paths should you have different versions.