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

Problem: No AVR support and path issues on windows #2

Open
wants to merge 12 commits into
base: xc8-cc
Choose a base branch
from
64 changes: 64 additions & 0 deletions Modules/AVREeprom2Hex.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#=============================================================================
# Copyright 2016 Sam Hanes
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file COPYING.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake-Microchip,
# substitute the full License text for the above reference.)


function(avr_eeprom2hex target)
find_program(AVR_EEPROM2HEX
NAMES ${_CMAKE_TOOLCHAIN_PREFIX}avr-objcopy avr-objcopy
HINTS ${_CMAKE_TOOLCHAIN_LOCATION}
)

if(NOT AVR_EEPROM2HEX)
message(SEND_ERROR "No avr-objcopy program was found")
endif()

function(get_target_property_fallback var target)
set(result NOTFOUND)
foreach(property ${ARGN})
get_target_property(result ${target} ${property})
if(result)
break()
endif()
endforeach()
set(${var} ${result} PARENT_SCOPE)
endfunction()

get_target_property_fallback(in_f ${target}
RUNTIME_OUTPUT_NAME
OUTPUT_NAME
NAME
)

get_target_property_fallback(dir ${target}
RUNTIME_OUTPUT_DIRECTORY
BINARY_DIR
)

get_filename_component(out_f ${in_f} NAME_WE)
set(out_f "${out_f}$<$<CONFIG:DEBUG>:${CMAKE_DEBUG_POSTFIX}>.eep")

add_custom_command(
TARGET ${target} POST_BUILD
WORKING_DIRECTORY ${dir}/$<CONFIG>
COMMAND "${AVR_EEPROM2HEX}" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings ${ARGN} -O ihex "${in_f}$<$<CONFIG:DEBUG>:${CMAKE_DEBUG_POSTFIX}>.elf" "${out_f}"
BYPRODUCTS ${dir}/$<CONFIG>/${out_f}
VERBATIM
)

set_property(DIRECTORY APPEND
PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
${dir}/$<CONFIG>/${out_f}
)

install(FILES ${dir}/$<CONFIG>/${out_f} TYPE BIN)
endfunction()
64 changes: 64 additions & 0 deletions Modules/AVRObj2Hex.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#=============================================================================
# Copyright 2016 Sam Hanes
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file COPYING.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake-Microchip,
# substitute the full License text for the above reference.)


function(avr_obj2hex target)
find_program(AVR_OBJ2HEX
NAMES ${_CMAKE_TOOLCHAIN_PREFIX}avr-objcopy avr-objcopy
HINTS ${_CMAKE_TOOLCHAIN_LOCATION}
)

if(NOT AVR_OBJ2HEX)
message(SEND_ERROR "No avr-objcopy program was found")
endif()

function(get_target_property_fallback var target)
set(result NOTFOUND)
foreach(property ${ARGN})
get_target_property(result ${target} ${property})
if(result)
break()
endif()
endforeach()
set(${var} ${result} PARENT_SCOPE)
endfunction()

get_target_property_fallback(in_f ${target}
RUNTIME_OUTPUT_NAME
OUTPUT_NAME
NAME
)

get_target_property_fallback(dir ${target}
RUNTIME_OUTPUT_DIRECTORY
BINARY_DIR
)

get_filename_component(out_f ${in_f} NAME_WE)
set(out_f "${out_f}$<$<CONFIG:DEBUG>:${CMAKE_DEBUG_POSTFIX}>.hex")

add_custom_command(
TARGET ${target} POST_BUILD
WORKING_DIRECTORY ${dir}/$<CONFIG>
COMMAND "${AVR_OBJ2HEX}" -O ihex ${ARGN} "${in_f}$<$<CONFIG:DEBUG>:${CMAKE_DEBUG_POSTFIX}>.elf" "${out_f}"
BYPRODUCTS ${dir}/$<CONFIG>/${out_f}
VERBATIM
)

set_property(DIRECTORY APPEND
PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
${dir}/$<CONFIG>/${out_f}
)

install(FILES ${dir}/$<CONFIG>/${out_f} TYPE BIN)
endfunction()
44 changes: 44 additions & 0 deletions Modules/Compiler/AVRGCC-C.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#=============================================================================
# Copyright 2019 Sam Hanes
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file COPYING.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake-Microchip,
# substitute the full License text for the above reference.)

# called by `CMakeCInformation`
# to configure the AVR GCC compiler interface for C files

string(TOLOWER ${MICROCHIP_MCU_MODEL} MMCU)

string(APPEND CMAKE_C_FLAGS_INIT
# build for the configured MCU model
" -mmcu=${MMCU}"
)

set(CMAKE_C_OUTPUT_EXTENSION ".p1")
set(CMAKE_EXECUTABLE_SUFFIX ".elf")

set(CMAKE_C_COMPILE_OBJECT)
string(APPEND CMAKE_C_COMPILE_OBJECT
"<CMAKE_C_COMPILER> <FLAGS> <DEFINES> <INCLUDES>"
" -o <OBJECT> -c <SOURCE>"
)

set(CMAKE_C_LINK_EXECUTABLE)
string(APPEND CMAKE_C_LINK_EXECUTABLE
"<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS>"
" <OBJECTS> <LINK_LIBRARIES>"
" -o <TARGET>"
)

set(CMAKE_C_CREATE_STATIC_LIBRARY)
string(APPEND CMAKE_C_CREATE_STATIC_LIBRARY
"<CMAKE_AR> -r <TARGET>"
" <OBJECTS> <LINK_LIBRARIES>"
)
44 changes: 44 additions & 0 deletions Modules/Compiler/AVRGCC-CXX.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#=============================================================================
# Copyright 2019 Sam Hanes
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file COPYING.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake-Microchip,
# substitute the full License text for the above reference.)

# called by `CMakeCInformation`
# to configure the AVR GCC compiler interface for C files

string(TOLOWER ${MICROCHIP_MCU_MODEL} MMCU)

string(APPEND CMAKE_CXX_FLAGS_INIT
# build for the configured MCU model
" -mmcu=${MMCU}"
)

set(CMAKE_CXX_OUTPUT_EXTENSION ".p1")
set(CMAKE_EXECUTABLE_SUFFIX ".elf")

set(CMAKE_CXX_COMPILE_OBJECT)
string(APPEND CMAKE_CXX_COMPILE_OBJECT
"<CMAKE_CXX_COMPILER> <FLAGS> <DEFINES> <INCLUDES>"
" -o <OBJECT> -c <SOURCE>"
)

set(CMAKE_CXX_LINK_EXECUTABLE)
string(APPEND CMAKE_CXX_LINK_EXECUTABLE
"<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS>"
" <OBJECTS> <LINK_LIBRARIES>"
" -o <TARGET>"
)

set(CMAKE_CXX_CREATE_STATIC_LIBRARY)
string(APPEND CMAKE_CXX_CREATE_STATIC_LIBRARY
"<CMAKE_AR> -r <TARGET>"
" <OBJECTS> <LINK_LIBRARIES>"
)
12 changes: 12 additions & 0 deletions Modules/Compiler/XC8-C.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

# called by `CMakeCInformation`
# to configure the XC8 compiler interface for C files
# this supports the `xc8` CLI driver in XC8 1.x
# and the equivalent legacy CLI driver in XC8 2.x


set(MICROCHIP_XC8_MODE "free"
Expand All @@ -28,7 +30,10 @@ string(APPEND CMAKE_C_FLAGS_INIT
" --chip=${MICROCHIP_MCU_MODEL}"
)


set(CMAKE_C_OUTPUT_EXTENSION ".p1")
set(CMAKE_STATIC_LIBRARY_SUFFIX_C ".lpp")


set(CMAKE_C_COMPILE_OBJECT)
string(APPEND CMAKE_C_COMPILE_OBJECT
Expand All @@ -42,3 +47,10 @@ string(APPEND CMAKE_C_LINK_EXECUTABLE
" <OBJECTS> <LINK_LIBRARIES>"
" -o<TARGET>"
)

set(CMAKE_C_CREATE_STATIC_LIBRARY)
string(APPEND CMAKE_C_CREATE_STATIC_LIBRARY
"<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS>"
" <OBJECTS> <LINK_LIBRARIES>"
" --output=lpp -o<TARGET>"
)
50 changes: 50 additions & 0 deletions Modules/Compiler/XC8CC-C.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#=============================================================================
# Copyright 2019 Sam Hanes
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file COPYING.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake-Microchip,
# substitute the full License text for the above reference.)

# called by `CMakeCInformation`
# to configure the XC8CC compiler interface for C files
# this supports the xc8-cc CLI driver from XC8 v2.x


string(APPEND CMAKE_C_FLAGS_INIT
# build for the configured MCU model
" -mcpu=${MICROCHIP_MCU_MODEL}"
)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "PIC_8")
string(APPEND CMAKE_C_FLAGS_INIT
# fail if the requested optimization level is forbidden by the license
" --nofallback"
)
endif()

set(CMAKE_C_OUTPUT_EXTENSION ".p1")
set(CMAKE_EXECUTABLE_SUFFIX ".elf")

set(CMAKE_C_COMPILE_OBJECT)
string(APPEND CMAKE_C_COMPILE_OBJECT
"<CMAKE_C_COMPILER> <FLAGS> <DEFINES> <INCLUDES>"
" -o <OBJECT> -c <SOURCE>"
)

set(CMAKE_C_LINK_EXECUTABLE)
string(APPEND CMAKE_C_LINK_EXECUTABLE
"<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS>"
" <OBJECTS> <LINK_LIBRARIES>"
" -o <TARGET>"
)

set(CMAKE_C_CREATE_STATIC_LIBRARY)
string(APPEND CMAKE_C_CREATE_STATIC_LIBRARY
"<CMAKE_AR> -r <TARGET>"
" <OBJECTS> <LINK_LIBRARIES>"
)
Loading