Cmake does not evaluate -D CMAKE_CXX_COMPILER = g ++

I am trying to get cmake to build cpp code with g ++ since clang is used instead by default. So I use: cmake -D CMAKE_CXX_COMPILER=g++ ../src/CMakeLists.txt , after which cmake checks gcc and g ++ (with success), but nonetheless make VERBOSE=1 gives

 /usr/bin/c++ -o CMakeFiles/trial_cpp.dir/trial.cpp.o -c "/Users/Kuba/Code/Sketchpad/Trial project/src/trial.cpp" Linking CXX executable trial_cpp /opt/etlocal/bin/cmake -E cmake_link_script CMakeFiles/trial_cpp.dir/link.txt --verbose=1 /usr/bin/c++ -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/trial_cpp.dir/trial.cpp.o -o trial_cpp 

As it calls / usr / bin / C ++ not / usr / bin / g ++, I agree that it still uses clang. Any idea what the problem is? I know that I have g ++ and this is in / usr / bin /. I am running Mac OS X 10.8.2

+11
c ++ g ++ cmake
Dec 13
source share
2 answers

CMAKE_CXX_COMPILER can only be set when cmake is first run in the specified assembly directory. On subsequent launches, it is ignored. To change CMAKE_CXX_COMPILER, you first need to delete the contents of the assembly directory and then run cmake again with this option.

Source: http://www.cmake.org/Wiki/CMake_Useful_Variables

I believe that the argument for only using this variable in the first run is that a change later could potentially invalidate everything already built, including configuration checks, so cmake should still start from scratch anyway.

+12
Dec 13 '12 at 13:00
source share

I do it like this:

 CXX=/usr/bin/g++ cmake ../src/CMakeLists.txt 
+1
Dec 13
source share



All Articles