Also, a better solution for enabling C++11 on gcc under CMake is the following:
if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif(CMAKE_COMPILER_IS_GNUCC)
if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif(CMAKE_COMPILER_IS_GNUCC)
To copy to clipboard, switch view to plain text mode
On a fun note, I also tend to add the following to all my CMake projects:
option(enable_maintainer "Enables the maintainer CFLAGS (-Wall -Werror)" OFF)
if(enable_maintainer)
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
endif(CMAKE_COMPILER_IS_GNUCXX)
endif(enable_maintainer)
option(enable_maintainer "Enables the maintainer CFLAGS (-Wall -Werror)" OFF)
if(enable_maintainer)
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
endif(CMAKE_COMPILER_IS_GNUCXX)
endif(enable_maintainer)
To copy to clipboard, switch view to plain text mode
... which essentially means that any compiler warnings will show up as errors and demand to be fixed before things will actually compile... but it's turned off by default, so people don't accidentally turn it on.
Fully concur with ChrisW67's advice on target_link_libraries command for including the pthread library. He's right, though - if your project is using Qt at all (not clear from your post), then the pthread library is likely already being pulled in as a dependency of QtCore, and you shouldn't need to pull it in with any further calls in CMakeLists.txt.
Bookmarks