compiling googletest program on linux openSUSE with g++,make,cmakelists - c++

So I tried to use the googletest library ( https://github.com/google/googletest ). First I compiled it with cmake:
marton#linux-clwa:~/documents/github/googletest/googletest/cmake> cmake ..
-- The CXX compiler identification is GNU 4.8.5
-- The C compiler identification is GNU 4.8.5
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Found PythonInterp: /usr/local/bin/python (found version "3.4.5")
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/marton/documents/github/googletest/googletest/cmak
e
marton#linux-clwa:~/documents/github/googletest/googletest/cmake> make
Scanning dependencies of target gtest
[ 25%] Building CXX object CMakeFiles/gtest.dir/src/gtest-all.cc.o
[ 50%] Linking CXX static library libgtest.a
[ 50%] Built target gtest
Scanning dependencies of target gtest_main
[ 75%] Building CXX object CMakeFiles/gtest_main.dir/src/gtest_main.cc.o
[100%] Linking CXX static library libgtest_main.a
[100%] Built target gtest_main
and tried to compile it with g++, make:
Thu Mar 16; 22:45:19; marton;~/documents/github/fmi_summer_2017/chisleni_metodi ; $ g++ -isystem /home/marton/documents/github/googletest/googletest/include -L/home/marton/documents/github/googletest/googletest -pthread -lgthread 002.razd_razl.cpp -o test
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: cannot find -lgthread
collect2: error: ld returned 1 exit status
I am not sure if this error is due to my compiler/distro but I have installed these packages:
gcc-32bit gcc48-32bit glibc-devel-32bit libasan0-32bit libatomic1-32bit libgomp1-32bit
libitm1-32bit
So I thought that the lgtest is the problem and as poor-brained coder I decided to remove it and the result is a big list of undefined functions, namespaces and variables.
So I tried this repo: ( https://github.com/snikulov/google-test-examples ).
Everything was working correctly meaning that the problem is not with my compiler.but the repo was using cmakelists.
What am I doing wrong, what do I have to do to compile my program?
I know the fascist geeks will downvote but I searched google,youtube, the gtest repo and there is no explanation anywhere of how to compile your program your test via g++. So where can I find information about that ?
Which is it better to use make or CMakeLists ?

For compiling, if you want to use a CMakeLists.txt, added to a parent one via add_subdirectory, you can do something like this. (Taken from the Google Test Documentation)
In ProjectRoot/CMakeLists.txt
...
set(GTEST_OUTPUT_PATH ${CMAKE_BINARY_DIR}/googletest)
add_subdirectory(build_test)
...
In ProjectRoot/build_test/CMakeLists.txt
cmake_minimum_required(VERSION 2.8.11)
# Download and unpack googletest at configure time
configure_file(CMakeLists.txt.in ${GTEST_OUTPUT_PATH}/download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${GTEST_OUTPUT_PATH}/download )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${GTEST_OUTPUT_PATH}/download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()
# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${GTEST_OUTPUT_PATH}/src
${GTEST_OUTPUT_PATH}/build)
In ProjectRoot/build_test/CMakeLists.txt.in
cmake_minimum_required(VERSION 2.8.2)
project(googletest-download NONE)
include(ExternalProject)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG master
SOURCE_DIR "${GTEST_OUTPUT_PATH}/src"
BINARY_DIR "${GTEST_OUTPUT_PATH}/build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
What this allows us to do is clone a fresh copy of GoogleTest from their repo, and then builds it with the correct command arguments. (You can then after this is completed link to it as you normally would. ) I would recommend trying to set it up this to ensure that there aren't any issues in how you are building it. The only requirements for GTest is a c++98 compatible compiler, and make. You can see the complete (very minimal) requirements here: Linux Requirements

Related

emcmake doesn't locate installed packages

I'm trying to compile a simple C++ program which uses CGAL to WASM. The problem is that for some reason find_package(CGAL) fails when using emsmake cmake, though it works fine when using cmake for compiling regular executables. I'm pretty new to compiling C++ and working with Emscripten, so this is most likely a noob question.
Running emcmake (notice CGAL warning):
cgal % emcmake cmake .
configure: cmake . -DCMAKE_TOOLCHAIN_FILE=/Users/kitty/Downloads/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR=/Users/kitty/Downloads/emsdk/node/14.18.2_64bit/bin/node;--experimental-wasm-threads
-- This project requires the CGAL library, and will not be compiled.
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/kitty/Projects/cgal
Running regular cmake (no warning):
cgal % cmake .
-- The C compiler identification is AppleClang 13.1.6.13160021
-- The CXX compiler identification is AppleClang 13.1.6.13160021
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning at /usr/local/lib/cmake/CGAL/CGALConfig.cmake:92 (message):
CGAL_DATA_DIR cannot be deduced, set the variable CGAL_DATA_DIR to set the
default value of CGAL::data_file_path()
Call Stack (most recent call first):
CMakeLists.txt:10 (find_package)
-- Using header-only CGAL
-- Targetting Unix Makefiles
-- Using /Library/Developer/CommandLineTools/usr/bin/c++ compiler.
-- DARWIN_VERSION=21
-- Mac Leopard detected
-- Found GMP: /usr/local/lib/libgmp.dylib
-- Found MPFR: /usr/local/lib/libmpfr.dylib
-- Found Boost: /usr/local/lib/cmake/Boost-1.78.0/BoostConfig.cmake (found suitable version "1.78.0", minimum required is "1.48")
-- Boost include dirs: /usr/local/include
-- Boost libraries:
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found Boost: /usr/local/lib/cmake/Boost-1.78.0/BoostConfig.cmake (found version "1.78.0")
CMake Warning at /usr/local/lib/cmake/CGAL/CGAL_enable_end_of_configuration_hook.cmake:99 (message):
=======================================================================
CGAL performance notice:
The variable CMAKE_BUILD_TYPE is set to "". For performance reasons, you
should set CMAKE_BUILD_TYPE to "Release".
Set CGAL_DO_NOT_WARN_ABOUT_CMAKE_BUILD_TYPE to TRUE if you want to disable
this warning.
=======================================================================
Call Stack (most recent call first):
CMakeLists.txt:9223372036854775807 (CGAL_run_at_the_end_of_configuration)
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/kitty/Projects/cgal
Running make afterwards produces a working executable.
CMakeLists.txt (for the most part generated using cgal_create_CMakeLists utility):
# Created by the script cgal_create_CMakeLists
# This is the CMake script for compiling a set of CGAL applications.
cmake_minimum_required(VERSION 3.1...3.15)
project( executable )
# CGAL and its components
find_package( CGAL QUIET COMPONENTS )
if ( NOT CGAL_FOUND )
message(STATUS "This project requires the CGAL library, and will not be compiled.")
return()
endif()
# Boost and its components
find_package( Boost REQUIRED )
if ( NOT Boost_FOUND )
message(STATUS "This project requires the Boost library, and will not be compiled.")
return()
endif()
# include for local directory
# include for local package
# Creating entries for target: executable
# ############################
add_executable( executable test.cpp )
add_to_cached_list( CGAL_EXECUTABLE_TARGETS executable )
# Link the executable to CGAL and third-party libraries
target_link_libraries(executable PRIVATE CGAL::CGAL )
# Lines below are commented for now as they are not required for minimal repro
#set(CMAKE_EXECUTABLE_SUFFIX ".wasm")
#set_target_properties(executable PROPERTIES LINK_FLAGS "-s WASM=1 -s EXPORTED_FUNCTIONS='[_main]'")
test.cpp:
#include <iostream>
int main() {
std::cout << "Hello World!";
return 0;
}
In order for emcmake cmake .. to find the CGAL you would need to build that project for wasm and install it into the emscripten sysroot. (normally emscripten/cache/sysroot). Any libraries in /usr/lib or /usr/local/lib are most likely host libraries and therefore not compatible with wasm or emscripten.

Can't use vcpkg on linux

Here is my CMakelists.txt:
cmake_minimum_required(VERSION 3.0)
SET(CMAKE_TOOLCHAIN_FILE "/home/xxx/vcpkg/scripts/buildsystems/vcpkg.cmake")
project(test)
find_package(unofficial-sqlite3 CONFIG REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main PRIVATE unofficial::sqlite3::sqlite3)
I'm trying to use vcpkg through SET(CMAKE_TOOLCHAIN_FILE ${vcpkg_root}),but it seems that it doesn't work.Here is the error:
[cmake] CMake Error at CMakeLists.txt:5 (find_package):
[cmake] Could not find a package configuration file provided by
[cmake] "unofficial-sqlite3" with any of the following names:
[cmake]
[cmake] unofficial-sqlite3Config.cmake
[cmake] unofficial-sqlite3-config.cmake
I have verify that unofficial-sqlite3-config.cmake does exists in
/home/xxx/vcpkg/packages/sqlite3_x64-linux/share/unofficial-sqlite3/unofficial-sqlite3-config.cmake
I'm using WSL and vscode as IDE, Now I have no idea how to fix it.
I could not reproduce your issue using the following basic CMakeLists.txt
cmake_minimum_required(VERSION 3.21)
project(test)
find_package(unofficial-sqlite3 REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main PRIVATE unofficial::sqlite3::sqlite3)
I installed sqlite3 via vcpkg install sqlite3 and ran the build via
$ echo 'int main() { return 0; }' > main.cpp
$ cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /path/to/build
As you can see, this worked flawlessly. I'm not sure whether setting your CMake policy level to the downright ancient 3.0 is what matters, or if you're using an old vcpkg checkout (I used the most recent commit at time of writing).

SFML Cross-compilation for Windows on Linux

I'm trying to compile a simple program with SFML (basic helloworld but with a big green circle). I'm supposed to build the program on Linux for Linux and Windows. When I compile for Linux the program compile and run perfectly, however when I try to compile the Windows Executable, I get the following error:
/usr/bin/x86_64-w64-mingw32-ld: cannot find -lsfml-graphics
/usr/bin/x86_64-w64-mingw32-ld: cannot find -lsfml-window
/usr/bin/x86_64-w64-mingw32-ld: cannot find -lsfml-system
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/BrickShooter.dir/build.make:215: BrickShooter.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/BrickShooter.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I tried to change the setting in my Cmake without success (add_library, include_directories) but so far nothing worked.
Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.16)
project(BrickShooter)
set(CMAKE_CXX_STANDARD 14)
add_executable(BrickShooter main.cpp GameObjects/Block.cpp GameObjects/Block.h GameObjects/Player.cpp GameObjects/Player.h GameObjects/Shoot.cpp GameObjects/Shoot.h SysObjects/Game.cpp SysObjects/Game.h SysObjects/Store.cpp SysObjects/Store.h SysObjects/Menu.cpp SysObjects/Menu.h SysObjects/Backup.cpp SysObjects/Backup.h SysObjects/SysGame.cpp SysObjects/SysGame.h)
target_link_libraries (BrickShooter sfml-graphics sfml-window sfml-system)
And my toolchain for Windows:
# Sample toolchain file for building for Windows from an Ubuntu Linux system.
#
# Typical usage:
# *) install cross compiler: `sudo apt-get install mingw-w64`
# *) cd build
# *) cmake -DCMAKE_TOOLCHAIN_FILE=~/windows.cmake ..
set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
# cross compilers to use for C, C++ and Fortran
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
# target environment on the build host system
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
# modify default behavior of FIND_XXX() commands
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(SFML_INCLUDE_DIR "gitlab_ci/SFML-2.5.1-WIN/include")
include_directories(gitlab_ci/SFML-2.5.1-WIN/include)
set(SFML_LIBRARY_DIR "gitlab_ci/SFML-2.5.1-WIN/lib")
set(SFML_DIR "gitlab_ci/SFML-2.5.1-WIN/lib/cmake/SFML")
I'm using the following command to manually build the program:
cmake gitlab_ci/SFML-2.5.1-WIN/ -DCMAKE_TOOLCHAIN_FILE=gitlab_ci/windows.cmake CMakeLists.txt && make
Where gitlab_ci/SFML-2.5.1-WIN is where I stored the includes, libs, etc for Windows. I'm on Ubuntu 20.04 LTS and I have installed everything I needed with the following commands:
apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential libsfml-dev cmake doxygen mingw-w64 curl unzip
curl -O https://www.sfml-dev.org/files/SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit.zip
unzip SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit.zip
mv SFML-2.5.1 gitlab_ci/SFML-2.5.1-WIN
rm SFML-2.5.1-windows-gcc-7.3.0-mingw-64-bit.zip
Thanks to #tsyvarev here is the solution that worked for me:
I added this line to my toolchain for Windows
link_directories(gitlab_ci/SFML-2.5.1-WIN/lib)
The final result is:
# Sample toolchain file for building for Windows from an Ubuntu Linux system.
#
# Typical usage:
# *) install cross compiler: `sudo apt-get install mingw-w64`
# *) cd build
# *) cmake -DCMAKE_TOOLCHAIN_FILE=~/windows.cmake ..
set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
# cross compilers to use for C, C++ and Fortran
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
# target environment on the build host system
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
# modify default behavior of FIND_XXX() commands
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(SFML_INCLUDE_DIR "gitlab_ci/SFML-2.5.1-WIN/include")
include_directories(gitlab_ci/SFML-2.5.1-WIN/include)
set(SFML_LIBRARY_DIR "gitlab_ci/SFML-2.5.1-WIN/lib")
link_directories(gitlab_ci/SFML-2.5.1-WIN/lib)
set(SFML_DIR "gitlab_ci/SFML-2.5.1-WIN/lib/cmake/SFML")
and this give the following output:
cmake gitlab_ci/SFML-2.5.1-WIN/ -DCMAKE_TOOLCHAIN_FILE=gitlab_ci/windows.cmake CMakeLists.txt && make
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/x86_64-w64-mingw32-g++
-- Check for working CXX compiler: /usr/bin/x86_64-w64-mingw32-g++ -- 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: /mnt/shared/school/Ynov/Home_Work/uf_dev_log_13/repo_gitlab
Scanning dependencies of target BrickShooter
[ 10%] Building CXX object CMakeFiles/BrickShooter.dir/main.cpp.obj
[ 20%] Building CXX object CMakeFiles/BrickShooter.dir/GameObjects/Block.cpp.obj
[ 30%] Building CXX object CMakeFiles/BrickShooter.dir/GameObjects/Player.cpp.obj
[ 40%] Building CXX object CMakeFiles/BrickShooter.dir/GameObjects/Shoot.cpp.obj
[ 50%] Building CXX object CMakeFiles/BrickShooter.dir/SysObjects/Game.cpp.obj
[ 60%] Building CXX object CMakeFiles/BrickShooter.dir/SysObjects/Store.cpp.obj
[ 70%] Building CXX object CMakeFiles/BrickShooter.dir/SysObjects/Menu.cpp.obj
[ 80%] Building CXX object CMakeFiles/BrickShooter.dir/SysObjects/Backup.cpp.obj
[ 90%] Building CXX object CMakeFiles/BrickShooter.dir/SysObjects/SysGame.cpp.obj
[100%] Linking CXX executable BrickShooter.exe
[100%] Built target BrickShooter
Here is the link to the CMake docs about link_directories()

How do I get CMake to find my test in my C library project?

I have a project here:
https://github.com/edhartnett/ncglm
It is a small C library for reading netCDF data files from the Geostationary Lightning Mapper. I have an autotools build which works fine, and I'm trying to add a CMake build.
The directory structure is simple, there is a main directory, a src directory, and a test directory.
In the main directory I have:
# This is the main cmake file for ncglm, a library to help read the
# netCDF data files from the Global Lightning Mapper (GLM) instrument
# on GOES-16 and GOES-17.
#
# Ed Hartnett 11/10/19
# This will use any cmake between 3.1 and 3.15, preferint later
# versions with updated policies.
cmake_minimum_required(VERSION 3.1...3.15)
if (${CMAKE_VERSION} VERSION_LESS 3.12)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
endif()
# set the project name
project(ncglm VERSION 1.0)
#Add custom CMake Module
SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/"
CACHE INTERNAL "Location of our custom CMake modules.")
# Find netCDF.
include(FindNetCDF)
include_directories("${NETCDF_INCLUDES}")
# Create a config.h.
configure_file(config.h.cmake.in config.h)
# Turn on testing.
enable_testing()
include(CTest)
# Build in this subdirectory.
add_subdirectory(src test)
In the src subdirectory I have:
# This is the cmake file for the src directory of the ncglm library.
# Ed Hartnett 11/10/19
# Build the ncglm library.
add_library(ncglm glm_read.c goes_glm.h glm_data.h)
In the test directory I have:
# This is the cmake build file for the test directory of the ncglm library.
#
# Ed Hartnett 11/10/19
enable_testing()
add_test(NAME tst_glm_read COMMAND tst_glm_read)
build_test(tst_glm_read)
add_sh_test(nc_test4 run_glm_tests)
When I build, I get:
ed#mikado:~/ncglm/build$ cmake -DNETCDF_INCLUDES=/usr/local/netcdf-c-4.7.2_hdf5-1.10.5/include -DNETCDF_LIBRARIES=/usr/local/netcdf-c-4.7.2_hdf5-1.10.5/lib .. && make test
-- The C compiler identification is GNU 7.4.0
-- The CXX compiler identification is GNU 7.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found NetCDF: /usr/local/netcdf-c-4.7.2_hdf5-1.10.5/lib
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ed/ncglm/build
Running tests...
Test project /home/ed/ncglm/build
No tests were found!!!
How come cmake is not trying to build or run my test?
add_subdirectory(src test)
This is invalid / it doesn't do what you think it does. What you want to do is:
add_subdirectory(src)
add_subdirectory(test)
The cmake website is down right now, I can't link to it. From memory the add_subdirectory(src test) reads CMakeLists.txt in the src source directory, but builds the sources in the test build directory, the test is created inside the build directory inside CMAKE_CURRENT_BUILD_DIR. To add two source directories, you have to use two add_subdirectory().

Running cmake in a different build directory on Windows

I run CMake using cmake .. in order to make it output all the generated files in a different directory. This runs fine on Ubuntu, but breaks on Windows 10 when I try to run it. Running cmake . from the root project directory seems to work fine on both platforms. The output of cmake .. on Windows is:
PS D:\Development\cpp\hello-vulkan\build> cmake ..
-- Building for: Visual Studio 15 2017
-- Selecting Windows SDK version 10.0.16299.0 to target Windows 10.0.17134.
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:3 (project):
No CMAKE_C_COMPILER could be found.
CMake Error at CMakeLists.txt:3 (project):
No CMAKE_CXX_COMPILER could be found.
-- Configuring incomplete, errors occurred!
The CMakeLists.txt is specified here:
include(${CMAKE_ROOT}/Modules/ExternalProject.cmake)
cmake_minimum_required(VERSION 3.10)
project(hello_vulkan)
# Download and setup GLFW
set(GLFW_DIR ${PROJECT_SOURCE_DIR}/lib/glfw)
set(GLFW_BINARY_DIR ${GLFW_DIR}/bin)
ExternalProject_Add(
glfw
PREFIX ${GLFW_DIR}
GIT_REPOSITORY https://github.com/glfw/glfw.git
GIT_TAG 3.2.1
INSTALL_DIR ${GLFW_BINARY_DIR}
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${GLFW_BINARY_DIR}
)
# Link Vulkan and GLFW
set(VULKAN_DIR ${PROJECT_SOURCE_DIR}/lib/vulkan)
include_directories(${VULKAN_DIR}/include)
link_directories(
${VULKAN_DIR}/lib
${GLFW_BINARY_DIR}
)
# Setup project
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/build/)
set(SOURCES source/main.cpp)
add_executable(hello_vulkan ${SOURCES})
add_dependencies(hello_vulkan glfw)
Any ideas what to do for it to work when running from a different directory on Windows?
Edit:
Here is the output from cmake .. on Ubuntu:
cmake ..
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- 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: /mnt/d/Development/cpp/hello-vulkan/build