From c0a23866edfa56643dae19548555b085a4ac3aab Mon Sep 17 00:00:00 2001 From: Victor Zarubkin Date: Wed, 8 Feb 2017 21:47:20 +0300 Subject: [PATCH] Cross-compiler way of C++11 standard requirement (NOTICE: Need to test on Unix systems) --- easy_profiler_core/CMakeLists.txt | 22 +++++++++++++--------- profiler_gui/CMakeLists.txt | 13 ++++++++++++- sample/CMakeLists.txt | 17 ++++++++++++----- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/easy_profiler_core/CMakeLists.txt b/easy_profiler_core/CMakeLists.txt index 2e55b9e..8a286cc 100644 --- a/easy_profiler_core/CMakeLists.txt +++ b/easy_profiler_core/CMakeLists.txt @@ -1,4 +1,5 @@ -project(easy_profiler) +cmake_minimum_required(VERSION 2.8) +project(easy_profiler CXX) IF (NOT DEFINED LIB_NAME) SET(LIB_NAME ${PROJECT_NAME}) @@ -143,14 +144,6 @@ add_definitions( #-DEASY_PROFILER_API_DISABLED # uncomment this to disable profiler api only (you will have to rebuild only easy_profiler) ) -if (CMAKE_VERSION VERSION_LESS "3.1") - if (UNIX) - set (CMAKE_CXX_FLAGS "-std=gnu++11 ${CMAKE_CXX_FLAGS}") - endif (UNIX) - else () - set (CMAKE_CXX_STANDARD 11) -endif (CMAKE_VERSION VERSION_LESS "3.1") - if(WIN32) add_definitions( -D_WINSOCK_DEPRECATED_NO_WARNINGS @@ -160,6 +153,17 @@ endif(WIN32) add_library(${LIB_NAME} SHARED ${SOURCES} resources.rc) +if (CMAKE_VERSION VERSION_LESS "3.1") + if (UNIX OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set (CMAKE_CXX_FLAGS "-std=gnu++11 ${CMAKE_CXX_FLAGS}") + endif (UNIX OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") +else () + set_target_properties(${LIB_NAME} PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED ON + ) +endif (CMAKE_VERSION VERSION_LESS "3.1") + if(UNIX) set(PLATFORM_LIBS pthread) endif(UNIX) diff --git a/profiler_gui/CMakeLists.txt b/profiler_gui/CMakeLists.txt index e0e3d78..5db6431 100644 --- a/profiler_gui/CMakeLists.txt +++ b/profiler_gui/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR) -project(profiler_gui) +project(profiler_gui CXX) #set(CMAKE_PREFIX_PATH f:/qt/5.5/5.6/msvc2013_64/lib/cmake) @@ -58,6 +58,17 @@ add_executable(${PROJECT_NAME} resources.rc ) +if (CMAKE_VERSION VERSION_LESS "3.1") + if (UNIX OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set (CMAKE_CXX_FLAGS "-std=gnu++11 ${CMAKE_CXX_FLAGS}") + endif (UNIX OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") +else () + set_target_properties(${PROJECT_NAME} PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED ON + ) +endif (CMAKE_VERSION VERSION_LESS "3.1") + if(UNIX) set(SPECIAL_LIB pthread) endif(UNIX) diff --git a/sample/CMakeLists.txt b/sample/CMakeLists.txt index f866697..fdc7fa8 100644 --- a/sample/CMakeLists.txt +++ b/sample/CMakeLists.txt @@ -1,5 +1,5 @@ -project(profiler_sample) cmake_minimum_required(VERSION 2.8) +project(profiler_sample CXX) set(CPP_FILES main.cpp @@ -14,10 +14,6 @@ include_directories( ) link_directories(${CMAKE_SOURCE_DIR}/../bin) -if(UNIX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") -endif(UNIX) - add_executable(${PROJECT_NAME} ${SOURCES}) set(DISABLED_PROFILER_NAME @@ -32,4 +28,15 @@ endif(UNIX) target_link_libraries(${PROJECT_NAME} easy_profiler ${SPEC_LIB}) target_link_libraries(${DISABLED_PROFILER_NAME} easy_profiler ${SPEC_LIB}) +if (CMAKE_VERSION VERSION_LESS "3.1") + if (UNIX OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") + endif (UNIX OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") +else () + set_target_properties(${PROJECT_NAME} PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED ON + ) +endif (CMAKE_VERSION VERSION_LESS "3.1") + target_compile_definitions(${PROJECT_NAME} PRIVATE BUILD_WITH_EASY_PROFILER)