jeudi 19 mars 2020

CMake ignores gcc (CMAKE_CC_COMPILER) and then does not compile with c++11

I have a mixed c++ and c project I have set up to build on my Mac with cmake. However when I try to go on my box (it is a shared linux machine) I am unable to get it to build. Here is the CMakeLists folder

cmake_minimum_required(VERSION 3.1.3)
project(terminalTest)

set(MainSource "../../Backend")
set(TerminalSource "../../Terminal")
set(CollisionSource "../../Collision")
set(TouchSource "../../Multitouch")

# Debugging
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

include_directories("../../")

file(GLOB_RECURSE SOURCES
    ${MainSource}/*.cpp
    ${CollisionSource}/*.cpp
    ${TouchSource}/*.cpp
)
file(GLOB SOURCES2
    ${TerminalSource}/*.cpp 
)

add_executable(terminalTest ${SOURCES} ${SOURCES2})

Now part of this could be that on Mac I used the cmake GUI and here I dont have such luxuries. If I try and run cmake . from the build folder that also has the list file I get this

-- The C compiler identification is GNU 7.3.1
-- The CXX compiler identification is GNU 7.3.1
-- Check for working C compiler: /opt/rh/devtoolset-7/root/usr/bin/cc
-- Check for working C compiler: /opt/rh/devtoolset-7/root/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: /opt/rh/devtoolset-7/root/usr/bin/c++
-- Check for working CXX compiler: /opt/rh/devtoolset-7/root/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: /homes/iws/username/Coding/projectname/Terminal/Build

It picks up this cc and c++ program that I dont know what they are for and tries to build with it. If I call make it has a bunch of errors that would be resolved if it was compiled with c++11.

So instead I tried the following command

cmake -DCMAKE_CC_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/gcc -DCMAKE_CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/g++ .

And instead of doing gcc it has the following output

-- The C compiler identification is GNU 7.3.1
-- The CXX compiler identification is GNU 7.3.1
-- Check for working C compiler: /opt/rh/devtoolset-7/root/usr/bin/cc
-- Check for working C compiler: /opt/rh/devtoolset-7/root/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: /opt/rh/devtoolset-7/root/usr/bin/g++
-- Check for working CXX compiler: /opt/rh/devtoolset-7/root/usr/bin/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
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_CC_COMPILER


-- Build files have been written to: /homes/iws/username/Coding/projectname/Terminal/Build

You can see how it ignores my gcc CMAKE_CC_COMPILER variable in favor of whatever this cc program is. And when I run make I still get the errors that wouldn't be there if it compiled with c++11.

What is going on here?

If I run make -n I get the following output

/usr/bin/cmake3 -S/homes/iws/username/Coding/projectname/Terminal/Build -B/homes/iws/username/Coding/projectname/Terminal/Build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake3 -E cmake_progress_start /homes/iws/username/Coding/projectname/Terminal/Build/CMakeFiles /homes/iws/username/Coding/projectname/Terminal/Build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make -f CMakeFiles/terminalTest.dir/build.make CMakeFiles/terminalTest.dir/depend
cd /homes/iws/username/Coding/projectname/Terminal/Build && /usr/bin/cmake3 -E cmake_depends "Unix Makefiles" /homes/iws/username/Coding/projectname/Terminal/Build /homes/iws/username/Coding/projectname/Terminal/Build /homes/iws/username/Coding/projectname/Terminal/Build /homes/iws/username/Coding/projectname/Terminal/Build /homes/iws/username/Coding/projectname/Terminal/Build/CMakeFiles/terminalTest.dir/DependInfo.cmake --color=
make -f CMakeFiles/terminalTest.dir/build.make CMakeFiles/terminalTest.dir/build
/usr/bin/cmake3 -E cmake_echo_color --switch= --green --progress-dir=/homes/iws/username/Coding/projectname/Terminal/Build/CMakeFiles --progress-num=1 "Building CXX object CMakeFiles/terminalTest.dir/homes/iws/username/Coding/projectname/Backend/Engine/Engine.cpp.o"
/opt/rh/devtoolset-7/root/usr/bin/g++   -I/homes/iws/username/Coding/projectname/Terminal/Build/../..  -g   -std=c++11 -o CMakeFiles/terminalTest.dir/homes/iws/username/Coding/projectname/Backend/Engine/Engine.cpp.o -c /homes/iws/username/Coding/projectname/Backend/Engine/Engine.cpp
/usr/bin/cmake3 -E cmake_echo_color --switch= --green --progress-dir=/homes/iws/username/Coding/projectname/Terminal/Build/CMakeFiles --progress-num=2 "Building CXX object CMakeFiles/terminalTest.dir/homes/iws/username/Coding/projectname/Backend/Engine/Memory.cpp.o"
/opt/rh/devtoolset-7/root/usr/bin/g++   -I/homes/iws/username/Coding/projectname/Terminal/Build/../..  -g   -std=c++11 -o 
... 

You can see it is using g++ and the -std=c++11 argument.

Here is the Makefile generated in the build folder

# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.14

# Default target executed when no arguments are given to make.
default_target: all

.PHONY : default_target

# Allow only one "make -f Makefile2" at a time, but pass parallelism.
.NOTPARALLEL:


#=============================================================================
# Special targets provided by cmake.

# Disable implicit rules so canonical targets will work.
.SUFFIXES:


# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =

.SUFFIXES: .hpux_make_needs_suffix_list


# Suppress display of executed commands.
$(VERBOSE).SILENT:


# A target that is always out of date.
cmake_force:

.PHONY : cmake_force

#=============================================================================
# Set environment variables for the build.

# The shell in which to execute make rules.
SHELL = /bin/sh

# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake3

# The command to remove a file.
RM = /usr/bin/cmake3 -E remove -f

# Escaping for special characters.
EQUALS = =

# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /homes/iws/username/Coding/projectname/Terminal/Build

# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /homes/iws/username/Coding/projectname/Terminal/Build

#=============================================================================
# Targets provided globally by CMake.

# Special rule for the target rebuild_cache
rebuild_cache:
    @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
    /usr/bin/cmake3 -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache

# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache

.PHONY : rebuild_cache/fast

# Special rule for the target edit_cache
edit_cache:
    @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
    /usr/bin/ccmake3 -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : edit_cache

# Special rule for the target edit_cache
edit_cache/fast: edit_cache

.PHONY : edit_cache/fast

# The main all target
all: cmake_check_build_system
    $(CMAKE_COMMAND) -E cmake_progress_start /homes/iws/username/Coding/projectname/Terminal/Build/CMakeFiles /homes/iws/username/Coding/projectname/Terminal/Build/CMakeFiles/progress.marks
    $(MAKE) -f CMakeFiles/Makefile2 all
    $(CMAKE_COMMAND) -E cmake_progress_start /homes/iws/username/Coding/projectname/Terminal/Build/CMakeFiles 0
.PHONY : all

# The main clean target
clean:
    $(MAKE) -f CMakeFiles/Makefile2 clean
.PHONY : clean

# The main clean target
clean/fast: clean

.PHONY : clean/fast

# Prepare targets for installation.
preinstall: all
    $(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall

# Prepare targets for installation.
preinstall/fast:
    $(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall/fast

# clear depends
depend:
    $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend

#=============================================================================
# Target rules for targets named terminalTest

# Build rule for target.
terminalTest: cmake_check_build_system
    $(MAKE) -f CMakeFiles/Makefile2 terminalTest
.PHONY : terminalTest

# fast build rule for target.
terminalTest/fast:
    $(MAKE) -f CMakeFiles/terminalTest.dir/build.make CMakeFiles/terminalTest.dir/build
.PHONY : terminalTest/fast

homes/iws/username/Coding/projectname/Backend/Engine/Engine.o: homes/iws/username/Coding/projectname/Backend/Engine/Engine.cpp.o

.PHONY : homes/iws/username/Coding/projectname/Backend/Engine/Engine.o

# target to build an object file
homes/iws/username/Coding/projectname/Backend/Engine/Engine.cpp.o:
    $(MAKE) -f CMakeFiles/terminalTest.dir/build.make CMakeFiles/terminalTest.dir/homes/iws/username/Coding/projectname/Backend/Engine/Engine.cpp.o
.PHONY : homes/iws/username/Coding/projectname/Backend/Engine/Engine.cpp.o

homes/iws/username/Coding/projectname/Backend/Engine/Engine.i: homes/iws/username/Coding/projectname/Backend/Engine/Engine.cpp.i

.PHONY : homes/iws/username/Coding/projectname/Backend/Engine/Engine.i

# target to preprocess a source file
homes/iws/username/Coding/projectname/Backend/Engine/Engine.cpp.i:
    $(MAKE) -f CMakeFiles/terminalTest.dir/build.make CMakeFiles/terminalTest.dir/homes/iws/username/Coding/projectname/Backend/Engine/Engine.cpp.i
.PHONY : homes/iws/username/Coding/projectname/Backend/Engine/Engine.cpp.i

homes/iws/username/Coding/projectname/Backend/Engine/Engine.s: homes/iws/username/Coding/projectname/Backend/Engine/Engine.cpp.s

.PHONY : homes/iws/username/Coding/projectname/Backend/Engine/Engine.s

# target to generate assembly for a file
homes/iws/username/Coding/projectname/Backend/Engine/Engine.cpp.s:
    $(MAKE) -f CMakeFiles/terminalTest.dir/build.make CMakeFiles/terminalTest.dir/homes/iws/username/Coding/projectname/Backend/Engine/Engine.cpp.s
.PHONY : homes/iws/username/Coding/projectname/Backend/Engine/Engine.cpp.s

homes/iws/username/Coding/projectname/Backend/Engine/Memory.o: homes/iws/username/Coding/projectname/Backend/Engine/Memory.cpp.o

.PHONY : homes/iws/username/Coding/projectname/Backend/Engine/Memory.o

# target to build an object file
homes/iws/username/Coding/projectname/Backend/Engine/Memory.cpp.o:
    $(MAKE) -f CMakeFiles/terminalTest.dir/build.make CMakeFiles/terminalTest.dir/homes/iws/username/Coding/projectname/Backend/Engine/Memory.cpp.o
.PHONY : homes/iws/username/Coding/projectname/Backend/Engine/Memory.cpp.o

homes/iws/username/Coding/projectname/Backend/Engine/Memory.i: homes/iws/username/Coding/projectname/Backend/Engine/Memory.cpp.i

.PHONY : homes/iws/username/Coding/projectname/Backend/Engine/Memory.i

# target to preprocess a source file
homes/iws/username/Coding/projectname/Backend/Engine/Memory.cpp.i:
    $(MAKE) -f CMakeFiles/terminalTest.dir/build.make CMakeFiles/terminalTest.dir/homes/iws/username/Coding/projectname/Backend/Engine/Memory.cpp.i
.PHONY : homes/iws/username/Coding/projectname/Backend/Engine/Memory.cpp.i

homes/iws/username/Coding/projectname/Backend/Engine/Memory.s: homes/iws/username/Coding/projectname/Backend/Engine/Memory.cpp.s

.PHONY : homes/iws/username/Coding/projectname/Backend/Engine/Memory.s

# target to generate assembly for a file
homes/iws/username/Coding/projectname/Backend/Engine/Memory.cpp.s:
    $(MAKE) -f CMakeFiles/terminalTest.dir/build.make CMakeFiles/terminalTest.dir/homes/iws/username/Coding/projectname/Backend/Engine/Memory.cpp.s
.PHONY : homes/iws/username/Coding/projectname/Backend/Engine/Memory.cpp.s

homes/iws/username/Coding/projectname/Backend/Geometry/Geometry.o: homes/iws/username/Coding/projectname/Backend/Geometry/Geometry.cpp.o

.PHONY : homes/iws/username/Coding/projectname/Backend/Geometry/Geometry.o

... A bunch more of these

homes/iws/username/Coding/projectname/Terminal/EngineTester.o: homes/iws/username/Coding/projectname/Terminal/EngineTester.cpp.o

.PHONY : homes/iws/username/Coding/projectname/Terminal/EngineTester.o

# target to build an object file
homes/iws/username/Coding/projectname/Terminal/EngineTester.cpp.o:
    $(MAKE) -f CMakeFiles/terminalTest.dir/build.make CMakeFiles/terminalTest.dir/homes/iws/username/Coding/projectname/Terminal/EngineTester.cpp.o
.PHONY : homes/iws/username/Coding/projectname/Terminal/EngineTester.cpp.o

homes/iws/username/Coding/projectname/Terminal/EngineTester.i: homes/iws/username/Coding/projectname/Terminal/EngineTester.cpp.i

.PHONY : homes/iws/username/Coding/projectname/Terminal/EngineTester.i

# target to preprocess a source file
homes/iws/username/Coding/projectname/Terminal/EngineTester.cpp.i:
    $(MAKE) -f CMakeFiles/terminalTest.dir/build.make CMakeFiles/terminalTest.dir/homes/iws/username/Coding/projectname/Terminal/EngineTester.cpp.i
.PHONY : homes/iws/username/Coding/projectname/Terminal/EngineTester.cpp.i

homes/iws/username/Coding/projectname/Terminal/EngineTester.s: homes/iws/username/Coding/projectname/Terminal/EngineTester.cpp.s

.PHONY : homes/iws/username/Coding/projectname/Terminal/EngineTester.s

# target to generate assembly for a file
homes/iws/username/Coding/projectname/Terminal/EngineTester.cpp.s:
    $(MAKE) -f CMakeFiles/terminalTest.dir/build.make CMakeFiles/terminalTest.dir/homes/iws/username/Coding/projectname/Terminal/EngineTester.cpp.s
.PHONY : homes/iws/username/Coding/projectname/Terminal/EngineTester.cpp.s

# Help Target
help:
    @echo "The following are some of the valid targets for this Makefile:"
    @echo "... all (the default if no target is provided)"
    @echo "... clean"
    @echo "... depend"
    @echo "... rebuild_cache"
    @echo "... edit_cache"
    @echo "... terminalTest"
    @echo "... homes/iws/username/Coding/projectname/Backend/Engine/Engine.o"
    @echo "... homes/iws/username/Coding/projectname/Backend/Engine/Engine.i"
    @echo "... homes/iws/username/Coding/projectname/Backend/Engine/Engine.s"
    ... (This gets repeated for every source)
.PHONY : help



#=============================================================================
# Special targets to cleanup operation of make.

# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
    $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system

I honestly cant get much value out of reading that because it does not mention my compliers anywhere. Ive written makefiles by hand before and they have not looked quite like this.

Aucun commentaire:

Enregistrer un commentaire