why does cmake also adds compile options for imported packages? - c++

I have a project where I need some dependencies and and I use vcpkg to manage them. Now I want to set compile options with add_compile_options( /W4 /WX /std:c++17 ) for my executable and subdirectories but I don't want them to be applied on packages which were loaded with find_package.
This is the code inside my CMakeLists.txt from my test repository:
cmake_minimum_required(VERSION 3.15)
project(test)
set(VCPKG_DEPENDENCIES glm)
# set the build triplet for windows because default is x86-windows
if(WIN32)
set(VCPKG_TARGET_TRIPLET "x64-windows")
add_compile_options( /W4 /WX /std:c++17 )
endif()
get_filename_component(ABS_PATH_VCPKG "./vcpkg" REALPATH)
set(VCPKG_ROOT ${ABS_PATH_VCPKG})
set(CMAKE_TOOLCHAIN_FILE "${ABS_PATH_VCPKG}/scripts/buildsystems/vcpkg.cmake")
# additional folder where find_XXXX functions are searching for packages
set(CMAKE_PREFIX_PATH "${VCPKG_ROOT}/installed/${VCPKG_TARGET_TRIPLET}/share")
foreach(DEPENDENCY ${VCPKG_DEPENDENCIES})
message(STATUS "installing vcpkg dependency: <${DEPENDENCY}>")
execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/vcpkg.exe install ${DEPENDENCY}:${VCPKG_TARGET_TRIPLET} OUTPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg_install_log.txt)
endforeach()
add_executable(test main.cpp)
find_package(glm CONFIG REQUIRED)
target_link_libraries(test PRIVATE glm)
Ans this is my main:
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
int main()
{
glm::vec3 vec(1.0);
std::cout << ("Hello World!");
return 0;
}
The glm package however is calling add_library with the IMPORTED key which should inform about that this package is a system package and should not get the options applied to.
This is the error code:
[build] Starting build
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --build <path>/cpp_test_Isystem/build --config Debug --target all -- -j 18
[build] [1/2 50% :: 0.752] Building CXX object CMakeFiles\test.dir\main.cpp.obj
[build] FAILED: CMakeFiles/test.dir/main.cpp.obj
[build] <path>\VC\Tools\MSVC\1423~1.281\bin\Hostx64\x64\cl.exe /nologo /TP -I..\vcpkg\installed\x64-windows\include /DWIN32 /D_WINDOWS /GR /EHsc /Zi /Ob0 /Od /RTC1 -MDd /W4 /WX /std:c++17 /showIncludes /FoCMakeFiles\test.dir\main.cpp.obj /FdCMakeFiles\test.dir\ /FS -c ..\main.cpp
[build] <path>\cpp_test_Isystem\vcpkg\installed\x64-windows\include\glm\ext\../detail/type_quat.hpp(58): error C2220: the following warning is treated as an error
[build] <path>\cpp_test_Isystem\vcpkg\installed\x64-windows\include\glm\ext\../detail/type_quat.hpp(137): note: see reference to class template instantiation 'glm::qua<T,Q>' being compiled
[build] <path>\cpp_test_Isystem\vcpkg\installed\x64-windows\include\glm\ext\../detail/type_quat.hpp(58): warning C4201: nonstandard extension used: nameless struct/union
[build] ninja: build stopped: subcommand failed.
[build] Build finished with exit code 1

Your main.cpp file includes this header, so any options that apply to it also apply to the header.
Your options:
Disable the C4201 warning with a #pragma around the #include of GLM headers:
#pragma warning( push )
#pragma warning( disable : 4201 )
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#pragma warning( pop )
Disable the warning from CMake:
target_add_compile_options(test /wd4201)
EDIT: Use a GLM-specific define to silence these warnings (source):
#define GLM_FORCE_SILENT_WARNINGS
(or equivalent with target_add_definitions)

Related

How to fix : LINK Error when using Try_Run command in CMake

I am working on setting up a project folder architecture for a game and want to compile and link dependencies while keeping a clean project structure using CMake.
This imply that external libraries are built separately from my application binary. The application binary should however be able to access includes & sources files when building.
Here is a link to the git project : https://github.com/guyllaumedemers/SDL2-Tetris.
Here's my project folder architecture :
cmake
doc
extern
- libImGUI
- CMakeLists.txt
- #git.submodule - imgui
- libImGUI.cpp
- libSDL2
- CMakeLists.txt
- #git.submodule - sdl2
- libSDL2.cpp
- CMakeLists.txt
src
- appTetris
- CMakeLists.txt
- Main.cpp
- CMakeLists.txt
test
CMakeLists.txt
Before integrating the libraries I have added in my project, I want to run a test using ONLY my dummy source files with CMake Try_Run command.
// test script
#include <cstdio>
void libImGUITest(){ std::printf("libImGUI, Hello World!");}
I have created a src file under extern/libSDL2 with a simple function definition & did the same for the second library under extern/libImGUI. You can ignore the target_include_directories atm since I do not require the headers of the actual library.
project(
libImGUI
)
# add directory for lib
add_library(
${PROJECT_NAME}
OBJECT
"${PROJECT_SOURCE_DIR}/libImGUI.cpp"
)
add_library(
lib::imgui
ALIAS
${PROJECT_NAME}
)
target_include_directories(
${PROJECT_NAME}
PUBLIC
"${PROJECT_SOURCE_DIR}/pkg/backends"
)
# temp solution for try_run in appTetris CMakeLists.txt
add_library(
tryRunlibImGUI
STATIC
$<TARGET_OBJECTS:${PROJECT_NAME}>
)
Under my application folder : src/appTetris, I have my application entry point which is a Main.cpp with 2 forward declarations.
I am expecting the LINKER to resolve the definition of the forward declaration and print both library output message in the console log.
void libImGUITest();
void libSDL2Test();
int main(int argv, char** argc)
{
libImGUITest();
libSDL2Test();
return 0;
}
src/AppTetris CMakeLists.txt
set(
MYLANGUAGES
CXX
)
project(
Demo
VERSION 0.0.0.0
DESCRIPTION "Demo"
LANGUAGES ${MYLANGUAGES}
)
add_executable(
${PROJECT_NAME}
Main.cpp
)
add_dependencies(
${PROJECT_NAME}
lib::imgui
lib::sdl2
)
target_link_libraries(
${PROJECT_NAME}
PUBLIC
lib::imgui
lib::sdl2
)
# set project specifics
set(
MYCXX_VERSION_STANDARD
20
)
set_property(
TARGET
${PROJECT_NAME}
PROPERTY
CMAKE_CXX_STANDARD
${MYCXX_VERSION_STANDARD}
)
if(NOT ${CMAKE_CXX_STANDARD} EQUAL ${MYCXX_VERSION_STANDARD})
message(WARNING "WARNING! CXX_STANDARD SHOULD BE CXX_${MYCXX_VERSION_STANDARD}, CURRENTLY : ${CMAKE_CXX_STANDARD}")
else()
message(WARNING "WARNING! CXX_STANDARD IS CXX_${CMAKE_CXX_STANDARD}") # why this doesnt print?
endif()
set(
CMAKE_CXX_STANDARD_REQUIRED
ON
)
if(${CMAKE_CXX_STANDARD_REQUIRED})
message(WARNING "WARNING! CXX_STANDARD_REQUIRED IS ${CMAKE_CXX_STANDARD_REQUIRED}. MAKE SURE YOU HAVE THE LATEST COMPILER VERSION SUPPORTING THE CURRENT REQUIREMENTS FOR CXX_${CMAKE_CXX_STANDARD}")
endif()
set(
CMAKE_CXX_EXTENSIONS
OFF
)
if(NOT ${CMAKE_CXX_EXTENSIONS})
message(WARNING "WARNING! CXX_EXTENSIONS IS ${CMAKE_CXX_EXTENSIONS}!")
endif()
# check support for LINK Time Optimization between translation units
include(CheckIPOSupported)
check_ipo_supported(
RESULT
IS_IPO_SUPPORTED
OUTPUT
IPO_SUPPORT_LOG_OUTPUT
LANGUAGES
${MYLANGUAGES}
)
if(NOT ${IS_IPO_SUPPORTED})
message(WARNING "IPO ADD ON SUPPORTED : ${IS_IPO_SUPPORTED}. ${IPO_SUPPORT_LOG_OUTPUT}")
else()
set(
CMAKE_INTERPROCEDURAL_OPTIMIZATION
TRUE
)
endif()
# check compiler features supported
set(
PRINT_UNSUPPORTED_COMPILE_FEATURES
FALSE
)
if(${PRINT_UNSUPPORTED_COMPILE_FEATURES})
foreach(VAR IN LISTS CMAKE_CXX_COMPILE_FEATURES)
list(FIND CMAKE_CXX_COMPILE_FEATURES ${VAR} RESULT COMPILE_FEATURE_SUPPORT_RESULT)
if(NOT ${COMPILE_FEATURE_SUPPORT_RESULT})
message(WARNING "WARNING! FEATURE NOT SUPPORTED : ${VAR}")
endif()
endforeach()
endif()
# run try catch on dependencies
set(
APP_TETRIS_TEST_BINARY_DIR
"${PROJECT_BINARY_DIR}/test"
)
set(
TARGET_TRY_RUN
"${PROJECT_SOURCE_DIR}/Main.cpp"
)
# try_run cannot use ALIAS for some reason. target_link_libraries however allow such setup
# try_run doesn't allow OBJECTlib which means I can only create another lib that capture the TARGET_OBJECTS thru transitive property
try_run(
MAIN_CPP_RUN_RESULT
MAIN_CPP_COMPILE_RESULT
"${APP_TETRIS_TEST_BINARY_DIR}"
"${TARGET_TRY_RUN}"
LINK_LIBRARIES
tryRunlibImGUI
tryRunlibSDL2
COMPILE_OUTPUT_VARIABLE
TRY_COMPILE_LOG_OUTPUT
RUN_OUTPUT_VARIABLE
TRY_RUN_LOG_OUTPUT
)
if(NOT ${MAIN_CPP_COMPILE_RESULT})
message(SEND_ERROR "SEND_ERROR! TARGET TRY COMPILATION FAILED : ${TARGET_TRY_RUN}, COMPILE OUTPUT : ${TRY_COMPILE_LOG_OUTPUT}, RUN OUTPUT : ${TRY_RUN_LOG_OUTPUT}")
elseif(NOT ${MAIN_CPP_RUN_RESULT})
message(SEND_ERROR "SEND_ERROR! TARGET TRY RUN FAILED : ${TARGET_TRY_RUN}, COMPILE OUTPUT : ${TRY_COMPILE_LOG_OUTPUT}, RUN OUTPUT : ${TRY_RUN_LOG_OUTPUT}")
endif()
However, when running Try_Run command in CMake, I get the following linking error.
CMake Error at src/appTetris/CMakeLists.txt:138 (message):
SEND_ERROR! TARGET TRY COMPILATION FAILED :
D:/VisualStudio/SDL2/SDL2-GameDevCMake/SDL2-Tetris/src/appTetris/Main.cpp,
COMPILE OUTPUT : Change Dir:
D:/VisualStudio/SDL2/SDL2-GameDevCMake/SDL2-Tetris/out/build/bin/SDL2-TetrisApp/test/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Program Files/Microsoft Visual
Studio/2022/Enterprise/MSBuild/Current/Bin/amd64/MSBuild.exe
cmTC_4786f.vcxproj /p:Configuration=Debug /p:Platform=x64
/p:VisualStudioVersion=17.0 /v:m && MSBuild version 17.3.1+2badb37d1 for
.NET Framework
Microsoft (R) C/C++ Optimizing Compiler Version 19.33.31629 for x64
Main.cpp
Copyright (C) Microsoft Corporation. All rights reserved.
cl /c /Zi /W1 /WX- /diagnostics:column /Od /Ob0 /D _MBCS /D WIN32 /D _WINDOWS /D "CMAKE_INTDIR=\"Debug\"" /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_4786f.dir\Debug\\" /Fd"cmTC_4786f.dir\Debug\vc143.pdb" /external:W1 /Gd /TP /errorReport:queue "D:\VisualStudio\SDL2\SDL2-GameDevCMake\SDL2-Tetris\src\appTetris\Main.cpp"
LINK : fatal error LNK1104: cannot open file 'tryRunlibImGUI.lib'
[D:\VisualStudio\SDL2\SDL2-GameDevCMake\SDL2-Tetris\out\build\bin\SDL2-TetrisApp\test\CMakeFiles\CMakeTmp\cmTC_4786f.vcxproj]
Can anyone point me in the right direction to compile and run the Try_Run command?

Can't build OR-Tools (fetched with FetchContent) with MSVC in Qt Creator

I'm trying to build a project that integrates OR-Tools, with MSCV 2019 in Qt Creator, but there are strange build errors (hundred of them, in Abseil source code at the moment, but probably only because it's built first):
C:\MyProject\build_deps\absl-src\absl\time\time.h:110: erreur : C2039: 'ratio': is not a member of 'std'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\algorithm(40): note: see declaration of 'std'
C:\MyProject\build_deps\absl-src\absl\time\time.h:110: erreur : C2061: syntax error: identifier 'ratio'
C:\MyProject\build_deps\absl-src\absl\time\time.h:408: erreur : C2760: syntax error: unexpected token '{', expected ')'
I'm fetching OR-Tools with FetchContent, with the following CMakeLists.txt (I've removed most of the default Qt boilerplate):
cmake_minimum_required(VERSION 3.15)
project(MyProject VERSION 0.1 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets LinguistTools)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets LinguistTools)
set(PROJECT_SOURCES main.cpp)
qt_add_executable(${PROJECT_NAME}
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
include(FetchContent)
set(BUILD_DEPS ON)
set(BUILD_SAMPLES OFF)
set(BUILD_EXAMPLES OFF)
FetchContent_Declare(
or-tools
GIT_REPOSITORY https://github.com/google/or-tools.git
GIT_TAG v9.3
)
FetchContent_MakeAvailable(or-tools)
target_link_libraries(${PROJECT_NAME} PRIVATE or-tools)
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX)
target_compile_options(${PROJECT_NAME} PRIVATE /experimental:external /external:anglebrackets /external:W0)
qt_finalize_executable(${PROJECT_NAME})
For information, Qt Creator successively calls:
C:\Qt\Tools\CMake_64\bin\cmake.exe -S "C:/MyProject" -B "C:/MyProject/build" "-DCMAKE_GENERATOR:STRING=Ninja" "-DCMAKE_BUILD_TYPE:STRING=Debug" "-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=C:/Qt/Tools/QtCreator/share/qtcreator/package-manager/auto-setup.cmake" "-DQT_QMAKE_EXECUTABLE:FILEPATH=C:/Qt/6.3.0/msvc2019_64/bin/qmake.exe" "-DCMAKE_PREFIX_PATH:PATH=C:/Qt/6.3.0/msvc2019_64" "-DCMAKE_C_COMPILER:FILEPATH=C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe" "-DCMAKE_CXX_COMPILER:FILEPATH=C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe"
C:\Qt\Tools\CMake_64\bin\cmake.exe --build "C:/MyProject/build" --target all
The first failed compile command is:
C:\MSVC\x64\cl.exe /nologo /TP
-I"C:\MyProject\build\_deps\absl-build\absl\time"
-I"C:\MyProject\build\_deps\absl-src\absl\time"
-I"C:\MyProject\build\_deps\absl-build\absl\time\time_zone_autogen\include"
-I"C:\MyProject\build\_deps\absl-src"
/DWIN32 /D_WINDOWS /GR /EHsc /Zi /Ob0 /Od /RTC1 -MDd /W3 /DNOMINMAX
/DWIN32_LEAN_AND_MEAN /D_CRT_SECURE_NO_WARNINGS /D_SCL_SECURE_NO_WARNINGS /D_ENABLE_EXTENDED_ALIGNED_STORAGE
/bigobj /wd4005 /wd4068 /wd4180 /wd4244 /wd4267 /wd4503 /wd4800 -std:c++20 /showIncludes
/Fo_deps\absl-build\absl\time\CMakeFiles\time_zone.dir\internal\cctz\src\time_zone_lookup.cc.obj
/Fd_deps\absl-build\absl\time\CMakeFiles\time_zone.dir\time_zone.pdb
/FS -c "C:\MyProject\build\_deps\absl-src\absl\time\internal\cctz\src\time_zone_lookup.cc
Am I missing something?
Can you try with c++17 instead of c++20?
This happens when a project (such as https://github.com/abseil/abseil-cpp, used by or-tools) has a file called time.h.
The project builds fine when built standalone, but when used with FetchContent in a toplevel project that defines set(CMAKE_INCLUDE_CURRENT_DIR ON), <ctime> ends up including the time.h file from the project instead of the time.h file from the system.
I fixed this with
set(CMAKE_INCLUDE_CURRENT_DIR OFF)
FetchContent_MakeAvailable(absl)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

Can't compile static library with cmake cause compilation `cannot open include file: ...` for any standard header

Note: I've only tested this problem on windows but that's what I want to solve right now.
I'm trying to create a static library and I'm using CMake to generate the build files. However, building leads to no standard libraries being found. The simplest form I reproduce this issue is with these 3 files:
Test.hpp
#pragma once
class A
{
public:
int DoSomething();
};
Test.cpp
#include "Test.hpp"
#include <assert.h>
int A::DoSomething()
{
assert(true);
return 5;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.10.2)
project(MyLib VERSION 1.0.0 DESCRIPTION "My Lib")
set(SOURCE "src/Test.cpp")
if(WIN32)
set(CMAKE_CXX_FLAGS "/std:c++17 /EHsc")
else()
...
endif()
include_directories(${CMAKE_CURRENT_LIST_DIR}/include)
add_library(MyLib STATIC ${SOURCE})
Running cmake is fine but then running cmake --build . I get the following output:
C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1425~1.286\bin\HostX64\x64\cl.exe /nologo /TP -I..\..\..\include /std:c++17 /EHsc /MDd /Zi /Ob0 /Od /RTC1 /showIncludes /FoCMakeFiles\MyLib.dir\src\Test.cpp.obj /FdCMakeFiles\MyLib.dir\MyLib.pdb /FS -c ..\..\..\src\Test.cpp ..\..\..\src\Test.cpp(3): fatal error C1083: Cannot open include file: 'assert.h': No such file or directory
I'm not sure why it can't find assert.h. I'm only using this as an example but this happens with all STL headers. I've also tried using /MD /MT /MTd but it doesn't change anything. Feels like I need to do something special because it's a STATIC library but I couldn't identify what looking around.

Using CMAKE with visual studio buildtools 2017 ; unable to access UWP libs

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.

Why NMake generator puts the .obj file for C files in a directory other than those of C ++

I've a mysterious problem with the "NMake Makefiles" generator.
When I used my CMakeLists for generate a Solution Visual and I build after, he puts all my .obj in the same folder "sql_lite.dir/Debug/". The build success.
But when I use the Nmake generator, he put my .obj in 2 diferent folder :
sql_sqlite.dir/C_/Users/mea/Documents/repos/corealpi/external/sqlite
and
sql_sqlite.dir/C_/Users/mea/Documents/repos/corealpi/external/sqlite/sqlite3.c.obj
I thought the fact I have file.cpp and file.c is the problem of my issue, because I have the following output :
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Configuring done
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILE_OBJECT
And this at the end of Nmake :
[100%] Building C object CMakeFiles/sql_sqlite.dir/C_/Users/mea/Documents/repos/
corealpi/external/sqlite/sqlite3.c.obj
Linking CXX shared library C:\Users\mea\Documents\repos\corealpi\build\cmake_x86
d\bin\sql_sqlite.dll
LINK : fatal error LNK1104: cannot open file 'CMakeFiles/sql_sqlite.dir/C_/Users
/mea/Documents/repos/corealpi/external/sqlite/sqlite3.c.obj'
LINK failed. with 1104
It seems, he not build in the same directory and not build the .obj for the C file's.
Here is my CMakeLists.txt (who's running well under Visual Studio) :
############################### SQLITE ###############################
project(sql_sqlite CXX)
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /MANIFEST:NO")
# Path of Release
SET(BIN_RELEASE_PATH "../../build/cmake_x86")
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${BIN_RELEASE_PATH}/bin/" )
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${BIN_RELEASE_PATH}/bin/" )
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${BIN_RELEASE_PATH}/bin/" )
# Path of Debug
SET(BIN_DEBUG_PATH "../../build/cmake_x86d")
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${BIN_DEBUG_PATH}/bin/" )
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${BIN_DEBUG_PATH}/bin/" )
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${BIN_DEBUG_PATH}/bin/" )
# Flags
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /Ycstdafx.h /Yustdafx.h /D_USRDLL /DSQL_SQLITE_EXPORTS /D_UNICODE /DUNICODE")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi /GL /Oi /Gy /O2 /GR- /Gm- /OPT /Fosql_sqlite.dir/src/sql_sqlite")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX- /ZI /Oy- /Gm /EHsc /MDd /GS /Gd")
set_source_files_properties(../datasec/src/sql_sqlite/stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h")
set_source_files_properties(../datasec/src/sql_sqlite/main.cpp PROPERTIES COMPILE_FLAGS "/Yustdafx.h")
set_source_files_properties(../external/sqlite/sqlite3.c PROPERTIES COMPILE_FLAGS "/Y-")
# Files of library
add_library(
sql_sqlite
SHARED
../datasec/src/sql_sqlite/stdafx.h
../external/sqlite/sqlite3.h
../datasec/src/sql_sqlite/sql_sqlite.cpp
../datasec/src/sql_sqlite/stdafx.cpp
../datasec/src/sql_sqlite/main.cpp
../external/sqlite/sqlite3.c
)
target_link_libraries(sql_sqlite datasec core)
Please I need help because, I've search on many website, try different solution during many days but anyway, it stand failing linking.
I've trying to put something like that : /Fosql_sqlite.dir/src/sql_sqlite but nothing change.
Do I have to make a special rule for sqlite3.c ? Or have I make something wrong on my CMakeLists.txt ?
Why CMake tells me : Missing variable is: CMAKE_C_COMPILE_OBJECT ?
Thanks for help.
Your PROJECT lines specifes C++ only via the CXX. Maybe removing the CXX will fix the problem so that both C and C++ compilers will be setup. The documentation is here, http://www.cmake.org/cmake/help/v3.2/command/project.html