1

我正在尝试在 CMake 中添加一种新的类 C 语言,称为“foo”,它需要使用特定的修改编译器

我尝试了从 makefile 到 CMake 的通用规则,它在编译单个foo文件时似乎有效。

但是我发现该命令include_directories在我使用时不起作用。

在这里,我列出了我所做的更改

CMakeDetermineFOOCompiler.cmake:

find_program(CMAKE_FOO_COMPILER NAMES "clang++" PATHS "~/out/install/bin" DOC "FOO Compiler")

mark_as_advanced(CMAKE_FOO_COMPILER)
message(STATUS CMAKE_FOO_COMPILER:  ${CMAKE_FOO_COMPILER})
set(CMAKE_FOO_SOURCE_FILE_EXTENSIONS foo)
set(CMAKE_FOO_COMPILER_ENV_VAR "FOO")
configure_file(${CMAKE_ROOT}/Modules/CMakeFOOCompiler.cmake.in
               ${CMAKE_PLATFORM_INFO_DIR}/CMakeFOOCompiler.cmake @ONLY)

CMakeFOOInformation.cmake:

include(CMakeCommonLanguageInclude)

if(UNIX)
  set(CMAKE_FOO_OUTPUT_EXTENSION .o)
else()
  set(CMAKE_FOO_OUTPUT_EXTENSION .obj)
endif()

set(_INCLUDED_FILE 0)

if(NOT CMAKE_FOO_COMPILE_OBJECT)
    set(CMAKE_FOO_COMPILE_OBJECT "<CMAKE_FOO_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
endif()

if(NOT CMAKE_FOO_CREATE_SHARED_LIBRARY)
  set(CMAKE_FOO_CREATE_SHARED_LIBRARY
      "<CMAKE_FOO_COMPILER> <CMAKE_SHARED_LIBRARY_FOO_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_FOO_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
endif()

if(NOT CMAKE_FOO_CREATE_SHARED_MODULE)
  set(CMAKE_FOO_CREATE_SHARED_MODULE ${CMAKE_FOO_CREATE_SHARED_LIBRARY})
endif()

if(NOT CMAKE_FOO_LINK_EXECUTABLE)
  set(CMAKE_FOO_LINK_EXECUTABLE
    "<CMAKE_FOO_COMPILER> <FLAGS> <CMAKE_FOO_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
endif()

set(CMAKE_FOO_INFORMATION_LOADED 1)

CMakeFOOCompiler.cmake.in:

set(CMAKE_FOO_COMPILER "@CMAKE_FOO_COMPILER@")
set(CMAKE_FOO_COMPILER_LOADED 1)
set(CMAKE_FOO_SOURCE_FILE_EXTENSIONS @CMAKE_FOO_SOURCE_FILE_EXTENSIONS@)
set(CMAKE_FOO_OUTPUT_EXTENSION @CMAKE_FOO_OUTPUT_EXTENSION@)
set(CMAKE_FOO_COMPILER_ENV_VAR "@CMAKE_FOO_COMPILER_ENV_VAR@")

CMakeTestFOOCompiler.cmake:

set(CMAKE_FOO_COMPILER_WORKS 1 CACHE INTERNAL "")

我的 CMakeLists.txt:

cmake_minimum_required(VERSION 3.0.0)
project(FOO_demo)

enable_language(FOO)

set(FOO_home /home/FOO_20210731/operations)

include_directories(${FOO_home}/include)
add_executable(test_foo test.foo)

当我使用 commandmake时,我收到一个警告:

/home/FOO_20210731/operations/include: 'linker' input unused [-Wunused-command-line-argument]

然后就来了一个致命错误,显示找不到包含的头文件:</p>

/home/FOO_20210731/operations/include/FOO_header/foo_rt.h:3:10: fatal error: 'FOO_header/foo_rt.h' file not found
#include "FOO_header/foo_rt.h"

似乎这include_directories不起作用,我想需要在这些.cmake文件上添加一些更改。如何include_directories为我的案子工作?

4

0 回答 0