Quantcast

CMAKE_BUILD_TYPE does not work in CMAKE_TOOLCHAIN_FILE - how to proceed?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

CMAKE_BUILD_TYPE does not work in CMAKE_TOOLCHAIN_FILE - how to proceed?

Steffen Dettmer
Hi,

I'm new to cmake and we started using it to build proprietary embedded
projects with a proprietary toolchain. We love the new build system's
performance and its simplicity! Compared with what we were used to
have, it is just superior in every aspect we met, really great!

We hopefully based our approach correctly based on examples found in
the web, stackoverflow answers, tutorials and of course the cmake
documentation. For each embedded system toolchain (i.e. device, major
lib versions etc) we wrote a  CMAKE_TOOLCHAIN_FILE, which sets
CMAKE_C_COMPILER, CMAKE_C_FLAGS and so on. We needed to use the force
(CACHE STRING "" FORCE).

What is left open is to select debug or release binaries. I googled a
lot, but unfortunately did not find a solution, so I hope you please
can point me into the right direction.

I think a (non-working) example illustrates pretty clear what I would
like to archive. Having in ToolchainFile.cmake:

     if(CMAKE_BUILD_TYPE MATCHES DEBUG)
        set(XYZ_LDPATH "${XYZ_LDPATH} -L${XYZ_PATH}/linux-arm-g++/Debug/")
      elseif(CMAKE_BUILD_TYPE MATCHES Release)
        set(XYZ_LDPATH "${XYZ_LDPATH} -L${XYZ_PATH}/linux-arm-g++/Release/")
      else(CMAKE_BUILD_TYPE MATCHES DEBUG)
        message(FATAL_ERROR "unknown CMAKE_BUILD_TYPE=\"${CMAKE_BUILD_TYPE}\"")
      endif(CMAKE_BUILD_TYPE MATCHES DEBUG)
      # ...
      set(CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT}
${XYZ_LDPATH}")
      set(CMAKE_SHARED_LINKER_FLAGS_INIT
"${CMAKE_SHARED_LINKER_FLAGS_INIT} ${XYZ_LDPATH}")

This unfortunately does not work, because the Toolchain file is
included / executed multiple times and at least one inclusions have
CMAKE_BUILD_TYPE empty. --trace shows that some CMake own file
overwrites it.

Do you have any hint how to do this correctly? Some workaround? Should
we somehow save the value in an own variable and use this own variable
if set (if this is possible at all)? Or are we supposed to have a
different toolchain file for Debug and Release (would double the
number of files)? We could also consider adding an own
"-DXYZ_CMAKE_BUILD_TYPE=Debug" variable, would this be suited?

What would be the best and "most standard" way to handle Debug and
Release libraries in an own toolchain?

Thank you for your time reading this!

Best regards,
Steffen
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Loading...