Skip to content

Commit

Permalink
Detect compiler.cppstd from CMAKE_CXX_STANDARD (#343)
Browse files Browse the repository at this point in the history
* detect compiler cpp standard

* add cxx standard test

Co-authored-by: czoido <mrgalleta@gmail.com>
  • Loading branch information
guy-david and czoido authored Nov 16, 2021
1 parent 43e3858 commit 9dcc51d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
7 changes: 6 additions & 1 deletion conan.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ macro(_conan_detect_compiler)
set(_CONAN_SETTING_ARCH ${ARGUMENTS_ARCH})
endif()

if(USING_CXX)
set(_CONAN_SETTING_COMPILER_CPPSTD ${CMAKE_CXX_STANDARD})
endif()

if (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL GNU)
# using GCC
# TODO: Handle other params
Expand Down Expand Up @@ -417,7 +421,8 @@ endfunction()

function(_collect_settings result)
set(ARGUMENTS_PROFILE_AUTO arch build_type compiler compiler.version
compiler.runtime compiler.libcxx compiler.toolset)
compiler.runtime compiler.libcxx compiler.toolset
compiler.cppstd)
foreach(ARG ${ARGUMENTS_PROFILE_AUTO})
string(TOUPPER ${ARG} _arg_name)
string(REPLACE "." "_" _arg_name ${_arg_name})
Expand Down
26 changes: 26 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,32 @@ def test_conan_cmake_install_find_package(self):
run("cmake .. {} -DCMAKE_BUILD_TYPE=Release".format(generator))
run("cmake --build . --config Release")

def test_conan_cmake_autodetect_cxx_standard(self):
content = textwrap.dedent("""
cmake_minimum_required(VERSION 3.5)
project(FormatOutput CXX)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
set(CMAKE_CXX_STANDARD 14)
include(conan.cmake)
conan_cmake_configure(REQUIRES fmt/6.1.2 GENERATORS cmake_find_package)
conan_cmake_autodetect(settings)
conan_cmake_install(PATH_OR_REFERENCE .
BUILD missing
REMOTE conancenter
SETTINGS ${settings})
find_package(fmt)
add_executable(main main.cpp)
target_link_libraries(main fmt::fmt)
""")
save("CMakeLists.txt", content)
os.makedirs("build")
os.chdir("build")
run("cmake .. {} -DCMAKE_BUILD_TYPE=Release > output.txt".format(generator))
with open('output.txt', 'r') as file:
data = file.read()
assert "compiler.cppstd=14" in data

# https://github.com/conan-io/cmake-conan/issues/315
def test_issue_315(self):
content = textwrap.dedent("""
Expand Down

0 comments on commit 9dcc51d

Please sign in to comment.