Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added cstd detection, and tidied variable names #654

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 58 additions & 46 deletions conan_provider.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,18 @@ function(detect_arch ARCH)
endfunction()


function(detect_cxx_standard CXX_STANDARD)
set(${CXX_STANDARD} ${CMAKE_CXX_STANDARD} PARENT_SCOPE)
function(detect_c_standard c_standard)
set(${c_standard} ${CMAKE_C_STANDARD} PARENT_SCOPE)
if(CMAKE_C_EXTENSIONS)
set(${c_standard} "gnu${CMAKE_C_STANDARD}" PARENT_SCOPE)
endif()
endfunction()


function(detect_cxx_standard cxx_standard)
set(${cxx_standard} ${CMAKE_CXX_STANDARD} PARENT_SCOPE)
if(CMAKE_CXX_EXTENSIONS)
set(${CXX_STANDARD} "gnu${CMAKE_CXX_STANDARD}" PARENT_SCOPE)
set(${cxx_standard} "gnu${CMAKE_CXX_STANDARD}" PARENT_SCOPE)
endif()
endfunction()

Expand Down Expand Up @@ -358,74 +366,78 @@ endmacro()


function(detect_host_profile output_file)
detect_os(MYOS MYOS_API_LEVEL MYOS_SDK MYOS_SUBSYSTEM MYOS_VERSION)
detect_arch(MYARCH)
detect_compiler(MYCOMPILER MYCOMPILER_VERSION MYCOMPILER_RUNTIME MYCOMPILER_RUNTIME_TYPE)
detect_cxx_standard(MYCXX_STANDARD)
detect_lib_cxx(MYLIB_CXX)
detect_build_type(MYBUILD_TYPE)
detect_os(_os _api_level _sdk _subsystem _version)
detect_arch(_argch)
detect_compiler(_compiler _compiler_version _compiler_runtime _compiler_runtime_type)
detect_c_standard(_c_standard)
detect_cxx_standard(_cxx_standard)
detect_lib_cxx(_lib_cxx)
detect_build_type(_build_type)

set(PROFILE "")
string(APPEND PROFILE "[settings]\n")
if(MYARCH)
string(APPEND PROFILE arch=${MYARCH} "\n")
set(_profile "")
string(APPEND _profile "[settings]\n")
if(_argch)
string(APPEND _profile arch=${_argch} "\n")
endif()
if(_os)
string(APPEND _profile os=${_os} "\n")
endif()
if(MYOS)
string(APPEND PROFILE os=${MYOS} "\n")
if(_api_level)
string(APPEND _profile os.api_level=${_api_level} "\n")
endif()
if(MYOS_API_LEVEL)
string(APPEND PROFILE os.api_level=${MYOS_API_LEVEL} "\n")
if(_version)
string(APPEND _profile os.version=${_version} "\n")
endif()
if(MYOS_VERSION)
string(APPEND PROFILE os.version=${MYOS_VERSION} "\n")
if(_sdk)
string(APPEND _profile os.sdk=${_sdk} "\n")
endif()
if(MYOS_SDK)
string(APPEND PROFILE os.sdk=${MYOS_SDK} "\n")
if(_subsystem)
string(APPEND _profile os.subsystem=${_subsystem} "\n")
endif()
if(MYOS_SUBSYSTEM)
string(APPEND PROFILE os.subsystem=${MYOS_SUBSYSTEM} "\n")
if(_compiler)
string(APPEND _profile compiler=${_compiler} "\n")
endif()
if(MYCOMPILER)
string(APPEND PROFILE compiler=${MYCOMPILER} "\n")
if(_compiler_version)
string(APPEND _profile compiler.version=${_compiler_version} "\n")
endif()
if(MYCOMPILER_VERSION)
string(APPEND PROFILE compiler.version=${MYCOMPILER_VERSION} "\n")
if(_compiler_runtime)
string(APPEND _profile compiler.runtime=${_compiler_runtime} "\n")
endif()
if(MYCOMPILER_RUNTIME)
string(APPEND PROFILE compiler.runtime=${MYCOMPILER_RUNTIME} "\n")
if(_compiler_runtime_type)
string(APPEND _profile compiler.runtime_type=${_compiler_runtime_type} "\n")
endif()
if(MYCOMPILER_RUNTIME_TYPE)
string(APPEND PROFILE compiler.runtime_type=${MYCOMPILER_RUNTIME_TYPE} "\n")
if(_c_standard)
string(APPEND _profile compiler.cstd=${_c_standard} "\n")
endif()
if(MYCXX_STANDARD)
string(APPEND PROFILE compiler.cppstd=${MYCXX_STANDARD} "\n")
if(_cxx_standard)
string(APPEND _profile compiler.cppstd=${_cxx_standard} "\n")
endif()
if(MYLIB_CXX)
string(APPEND PROFILE compiler.libcxx=${MYLIB_CXX} "\n")
if(_lib_cxx)
string(APPEND _profile compiler.libcxx=${_lib_cxx} "\n")
endif()
if(MYBUILD_TYPE)
string(APPEND PROFILE "build_type=${MYBUILD_TYPE}\n")
if(_build_type)
string(APPEND _profile "build_type=${_build_type}\n")
endif()

if(NOT DEFINED output_file)
set(_FN "${CMAKE_BINARY_DIR}/profile")
set(_file_name "${CMAKE_BINARY_DIR}/profile")
else()
set(_FN ${output_file})
set(_file_name ${output_file})
endif()

string(APPEND PROFILE "[conf]\n")
string(APPEND PROFILE "tools.cmake.cmaketoolchain:generator=${CMAKE_GENERATOR}\n")
string(APPEND _profile "[conf]\n")
string(APPEND _profile "tools.cmake.cmaketoolchain:generator=${CMAKE_GENERATOR}\n")

# propagate compilers via profile
append_compiler_executables_configuration()

if(MYOS STREQUAL "Android")
string(APPEND PROFILE "tools.android:ndk_path=${CMAKE_ANDROID_NDK}\n")
if(_os STREQUAL "Android")
string(APPEND _profile "tools.android:ndk_path=${CMAKE_ANDROID_NDK}\n")
endif()

message(STATUS "CMake-Conan: Creating profile ${_FN}")
file(WRITE ${_FN} ${PROFILE})
message(STATUS "CMake-Conan: Profile: \n${PROFILE}")
message(STATUS "CMake-Conan: Creating profile ${_file_name}")
file(WRITE ${_file_name} ${_profile})
message(STATUS "CMake-Conan: Profile: \n${_profile}")
endfunction()


Expand Down
Loading