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

MCU specific libc #7

Open
pdgendt opened this issue Sep 2, 2015 · 4 comments
Open

MCU specific libc #7

pdgendt opened this issue Sep 2, 2015 · 4 comments

Comments

@pdgendt
Copy link

pdgendt commented Sep 2, 2015

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
Copy link
Owner

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
Copy link
Owner

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
Copy link

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
Copy link
Owner

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. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants