mkleemann / cmake-avr

cmake toolchain for AVR
Other
174 stars 61 forks source link

MCU specific libc #7

Open pdgendt opened 9 years ago

pdgendt commented 9 years ago

When I use find_package(C_LIB c) for my (atmega128) project, I get the wrong /usr/lib/avr/lib/libc.a when I require /usr/lib/avr/lib/avr51/libc.a. Is there a way to indicate this architecture specific setting to cmake?

mkleemann commented 9 years ago

Try setting your system search path(s) within the find_package() command. See http://www.cmake.org/cmake/help/v3.0/command/find_package.html as reference.

mkleemann commented 9 years ago

In general, there are many options. You may create a symbolic link or just adapt the main CMakeLists.txt in your project.

If you look at the sample file (or the examples) you get some entries like:

if(DEFINED ENV{AVR_FIND_ROOT_PATH})
    set(CMAKE_FIND_ROOT_PATH $ENV{AVR_FIND_ROOT_PATH})
else(DEFINED ENV{AVR_FIND_ROOT_PATH})
    if(EXISTS "/opt/local/avr")
      set(CMAKE_FIND_ROOT_PATH "/opt/local/avr")
    elseif(EXISTS "/usr/avr")
      set(CMAKE_FIND_ROOT_PATH "/usr/avr")
    elseif(EXISTS "/usr/lib/avr")
      set(CMAKE_FIND_ROOT_PATH "/usr/lib/avr")
    else(EXISTS "/opt/local/avr")
      message(FATAL_ERROR "Please set AVR_FIND_ROOT_PATH in your environment.")
    endif(EXISTS "/opt/local/avr")
endif(DEFINED ENV{AVR_FIND_ROOT_PATH})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# not added automatically, since CMAKE_SYSTEM_NAME is "generic"
set(CMAKE_SYSTEM_INCLUDE_PATH "${CMAKE_FIND_ROOT_PATH}/include")
set(CMAKE_SYSTEM_LIBRARY_PATH "${CMAKE_FIND_ROOT_PATH}/lib")

Just change your root path in the environment or directly in your main CMakeLists.txt. The first option can be achieved by simply add AVR_FIND_ROOT_PATH=/usr/lib/avr/lib/avr51 to your environment.

I hope that helps.

igormiktor commented 7 years ago

Just doing:

avr_target_link_libraries( MyExecutable c )

Adds an -lc in the appropriate places, and gcc automagically selects the right variant for whatever AVR MCU is set by the AVR_MCU parameter.

No need to do anything else (e.g., find_library() or find_package()), at least on the various linux systems I tested. I haven't tested on Windows or OS X.

mkleemann commented 7 years ago

As far as I remembered, this didn't work for the Windows variant - almost two years ago. If someone could check this as I don't use this OS anymore, this part of the examples can be removed. The same goes with OSX. :-)