Skip to content

Commit

Permalink
Merge branch 'feature/generate-conan-profile' into 'master'
Browse files Browse the repository at this point in the history
Generate conan profile.

See merge request kubasejdak-libs/hal!8
  • Loading branch information
kubasejdak committed Mar 17, 2020
2 parents f954cb9 + 667e10d commit 9f106bb
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Expand Up @@ -20,13 +20,15 @@ if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif ()

conan_init()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Project-wide compilation options.
add_compile_options(-Wall -Wextra -Wpedantic -Werror)

# Generate coverage report.
if (COVERAGE)
# Generate coverage report.
add_lcov_coverage(${CMAKE_CURRENT_SOURCE_DIR}/test/*)
endif ()

Expand Down
67 changes: 65 additions & 2 deletions cmake/conan.cmake
@@ -1,12 +1,75 @@
include(${CMAKE_CURRENT_LIST_DIR}/conan-wrapper.cmake)

function(conan_init)
# Value for settings.os.
if (PLATFORM STREQUAL linux)
if (CMAKE_HOST_SYSTEM_NAME STREQUAL Linux)
set(CONAN_OS Linux)
else ()
set(CONAN_OS Macos)
endif ()
elseif (PLATFORM STREQUAL linux-arm)
set(CONAN_OS Linux)
elseif (PLATFORM STREQUAL freertos-arm OR PLATFORM STREQUAL baremetal-arm)
set(CONAN_OS Generic)
endif ()

# Value for settings.os_build.
if (CMAKE_HOST_SYSTEM_NAME STREQUAL Linux)
set(CONAN_HOST_OS Linux)
else ()
set(CONAN_HOST_OS Macos)
endif ()

# Value for settings.arch.
if (NOT DEFINED CONAN_ARCH)
if (PLATFORM STREQUAL linux)
if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES arm)
set(CONAN_ARCH armv8_32)
else ()
set(CONAN_ARCH x86_64)
endif ()
elseif (PLATFORM STREQUAL linux-arm)
set(CONAN_ARCH armv8_32)
elseif (PLATFORM STREQUAL freertos-arm OR PLATFORM STREQUAL baremetal-arm)
set(CONAN_ARCH armv7)
endif ()
endif ()

# Value for settings.arch_build.
if (CMAKE_CROSSCOMPILING)
set(CONAN_HOST_ARCH x86_64)
else ()
set(CONAN_HOST_ARCH ${CONAN_ARCH})
endif ()

# Value for settings.compiler.
if (CMAKE_CXX_COMPILER_ID STREQUAL GNU)
set(CONAN_COMPILER gcc)
else ()
set(CONAN_COMPILER clang)
endif ()

# Value for settings.compiler.version.
string(REPLACE "." ";" VERSION_LIST ${CMAKE_CXX_COMPILER_VERSION})
list(GET VERSION_LIST 0 CONAN_COMPILER_MAJOR)

# Values for env.CFLAGS, env.CXXFLAGS and env.LDFLAGS.
string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE)
set(CONAN_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${BUILD_TYPE}}")
set(CONAN_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${BUILD_TYPE}}")
set(CONAN_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_${BUILD_TYPE}}")

message(STATUS "Configuring '${CMAKE_BINARY_DIR}/conan-profile'")
configure_file(${CMAKE_SOURCE_DIR}/tools/profile.in ${CMAKE_BINARY_DIR}/conan-profile)
endfunction ()

macro(conan_get)
set(CMAKE_SYSTEM_NAME_TMP ${CMAKE_SYSTEM_NAME})
set(CMAKE_SYSTEM_NAME ${CMAKE_HOST_SYSTEM_NAME})
conan_cmake_run(
REQUIRES ${ARGN}
PROFILE ${CONAN_PROFILE}
PROFILE_AUTO build_type
PROFILE ${CMAKE_BINARY_DIR}/conan-profile
BUILD missing
GENERATORS cmake_find_package cmake_paths
)
Expand Down
27 changes: 27 additions & 0 deletions tools/profile.in
@@ -0,0 +1,27 @@
[settings]
os=@CONAN_OS@
os_build=@CONAN_HOST_OS@
arch=@CONAN_ARCH@
arch_build=@CONAN_HOST_ARCH@
compiler=@CONAN_COMPILER@
compiler.version=@CONAN_COMPILER_MAJOR@
compiler.libcxx=libstdc++11
build_type=@CMAKE_BUILD_TYPE@

[options]

[build_requires]

[env]
CFLAGS="@CONAN_C_FLAGS@"
CXXFLAGS="@CONAN_CXX_FLAGS@"
LDFLAGS="@CONAN_LINKER_FLAGS@"

AR=@CMAKE_AR@
AS=@CMAKE_ASM_COMPILER@
CC=@CMAKE_C_COMPILER@
CXX=@CMAKE_CXX_COMPILER@
OBJCOPY=@CMAKE_OBJCOPY@
RANLIB=@CMAKE_RANLIB@
SIZE=@CMAKE_SIZE_UTIL@
STRIP=@CMAKE_STRIP@

0 comments on commit 9f106bb

Please sign in to comment.