[CMake] CMake Error: Cannot determine link language for target "io".

Mats Kindahl mats at Sun.COM
Tue May 19 08:23:43 EDT 2009


Hi all,

I have an example case where I want to decide the subsystems to include
dynamically. However, when running CMake, I get the error above.

Anybody can tell me why I get the error and what to do about it?

Best wishes,
Mats Kindahl

I have the following CMakeLists.txt files:

<root>/CMakeLists.txt
---------------------

project(build-test)

cmake_minimum_required(VERSION 2.6)

set(PACKAGE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)

file(MAKE_DIRECTORY ${INCLUDE_DIR})
include_directories(${INCLUDE_DIR})

# add_includes_for(<type> <file> ...)
#
# This function is used by package-specific CMakeLists.txt files to
# tell the main make system what include files it has. The files are
# resolved relative the package directory.

function(add_includes_for TYPE)
  math(EXPR stop "${ARGC} - 1")
  foreach(idx RANGE 1 ${stop})
    if(${TYPE} STREQUAL "server")
      list(GET ARGV ${idx} header)
      add_custom_command(OUTPUT ${INCLUDE_DIR}/${header}
        COMMAND configure_file ${header} ${INCLUDE_DIR}/${header} COPYONLY
        MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${header}
        COMMENT "Updating ${INCLUDE_DIR}/${header}")
    endif(${TYPE} STREQUAL "server")
  endforeach(idx)
endfunction(add_includes_for)

# Check all directories in the packages directory for
# packages. Packages are identified by having a CMakeLists.txt in the
# root.
file(GLOB pkgs ${PACKAGE_DIR}/*)
foreach(pkg ${pkgs})
  if(EXISTS ${pkg}/CMakeLists.txt)
    add_subdirectory(${pkg})
  endif(EXISTS ${pkg}/CMakeLists.txt)
endforeach(pkg)


<root>/src/io/CMakeLists.txt
----------------------------

add_library(io output)
add_includes_for(server output.h)


<root>/src/exec/CMakeLists.txt
------------------------------

add_executable(run main)
target_link_libraries(run io)

-- 
Mats Kindahl
Senior Software Engineer
Database Technology Group
Sun Microsystems


More information about the CMake mailing list