cpputils-cmake icon indicating copy to clipboard operation
cpputils-cmake copied to clipboard

add_library 处理有瑕疵

Open laiall opened this issue 9 years ago • 7 comments

chenbin,您好。

在使用cpputils-cmake的过程中发现,对于如下示例工程,打开 test.cc 后会显示 test.h file not found,使用的是flycheck

mkdir -p test/include test/src;

echo "cmake_minimum_required(VERSION 2.8) project(Test) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) include_directories(${PROJECT_SOURCE_DIR}/include) add_subdirectory(src)" > test/CMakeLists.txt ;

echo "add_library(test test)" > test/src/CMakeLists.txt

echo "#include "test.h"" > test/src/test.cc;

touch test/include/test.h

debug 信息如下

cppcm-reload-all called cppcm-get-dirs called cppcm-query-var-from-last-matched-line called 2 times=(t nil /home/ruizhi/test/build/debug/ /home/ruizhi/test) [2 times] cppcm-scan-info-from-cmake called => /home/ruizhi/test /home/ruizhi/test /home/ruizhi/test/build/debug/ CMakeLists.txt=/home/ruizhi/test/CMakeLists.txt possible-targets=nil cppcm-scan-info-from-cmake called => /home/ruizhi/test /home/ruizhi/test/build /home/ruizhi/test/build/debug/ cppcm-scan-info-from-cmake called => /home/ruizhi/test /home/ruizhi/test/build/debug /home/ruizhi/test/build/debug/ cppcm-scan-info-from-cmake called => /home/ruizhi/test /home/ruizhi/test/build/debug/CMakeFiles /home/ruizhi/test/build/debug/ cppcm-scan-info-from-cmake called => /home/ruizhi/test /home/ruizhi/test/build/debug/CMakeFiles/2.8.11 /home/ruizhi/test/build/debug/ cppcm-scan-info-from-cmake called => /home/ruizhi/test /home/ruizhi/test/build/debug/CMakeFiles/2.8.11/CompilerIdC /home/ruizhi/test/build/debug/ cppcm-scan-info-from-cmake called => /home/ruizhi/test /home/ruizhi/test/build/debug/CMakeFiles/2.8.11/CompilerIdCXX /home/ruizhi/test/build/debug/ cppcm-scan-info-from-cmake called => /home/ruizhi/test /home/ruizhi/test/build/debug/CMakeFiles/CMakeTmp /home/ruizhi/test/build/debug/ cppcm-scan-info-from-cmake called => /home/ruizhi/test /home/ruizhi/test/build/debug/lib /home/ruizhi/test/build/debug/ cppcm-scan-info-from-cmake called => /home/ruizhi/test /home/ruizhi/test/build/debug/src /home/ruizhi/test/build/debug/ cppcm-scan-info-from-cmake called => /home/ruizhi/test /home/ruizhi/test/build/debug/src/CMakeFiles /home/ruizhi/test/build/debug/ cppcm-scan-info-from-cmake called => /home/ruizhi/test /home/ruizhi/test/build/debug/src/CMakeFiles/test.dir /home/ruizhi/test/build/debug/ cppcm-scan-info-from-cmake called => /home/ruizhi/test /home/ruizhi/test/include /home/ruizhi/test/build/debug/ cppcm-scan-info-from-cmake called => /home/ruizhi/test /home/ruizhi/test/src /home/ruizhi/test/build/debug/ CMakeLists.txt=/home/ruizhi/test/src/CMakeLists.txt possible-targets=((add_library test)) cppcm-handle-one-executable called => /home/ruizhi/test /home/ruizhi/test/build/debug/ /home/ruizhi/test/src (add_library test) cppcm--guess-dir-containing-cmakelists-dot-txt called => /home/ruizhi/test/src cppcm--guess-dir-containing-cmakelists-dot-txt: dir=/home/ruizhi/test/src flag-make=/home/ruizhi/test/build/debug/src/CMakeFiles/test.dir/flags.make cppcm-proj-max-dir-level called => /home/ruizhi/test/build/debug/src/ (add_library test) cppcm-guess-exe-full-path: type=add_library cppcm-guess-exe-full-path: tgt=(add_library test) cppcm-guess-exe-full-path: exe-dir=/home/ruizhi/test/build/debug/src/ cppcm-guess-exe-full-path: cppcm-cmake-target-regex=^ [^#] *(add_executable|add_library) *( *([^ ]+) cppcm-guess-exe-full-path: base-exe-name=/home/ruizhi/test/build/debug/src/libtest cppcm--find-physical-lib-file called => /home/ruizhi/test/build/debug/src/libtest cppcm--find-physical-lib-file return =nil exe-full-path=nil cppcm-set-c-flags-current-buffer called cppcm--guess-dir-containing-cmakelists-dot-txt called => nil cppcm--guess-dir-containing-cmakelists-dot-txt: dir=/home/ruizhi/test/src/ c-compiling-flags-list=nil cppcm-include-dirs=(-I"/home/ruizhi/test/src/" -I"/home/ruizhi/test/src/" -I"/home/ruizhi/test/src/") ac-clang-flags=(-I/home/ruizhi/test/src/ -I/home/ruizhi/test/src/ -I/home/ruizhi/test/src/) company-clang-arguments=(-I/home/ruizhi/test/src/ -I/home/ruizhi/test/src/ -I/home/ruizhi/test/src/) flycheck-clang-include-path=(/home/ruizhi/test/src/ /home/ruizhi/test/src/ /home/ruizhi/test/src/) flycheck-clang-definitions=nil company-c-headers-path-system=(/home/ruizhi/test/src/ /home/ruizhi/test/src/ /home/ruizhi/test/src/)

cppcm-hash is a variable defined in `cpputils-cmake.el'. Its value is #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 data ())

Documentation: Not documented as a variable.

cppcm-version 0.5.2

emacs --version 24.5.1 cmake --version 2.8.11

laiall avatar Feb 14 '16 13:02 laiall

content of flags.make?

redguardtoo avatar Feb 14 '16 13:02 redguardtoo

CMAKE generated file: DO NOT EDIT!

Generated by "Unix Makefiles" Generator, CMake Version 2.8

compile CXX with /usr/bin/c++

CXX_FLAGS = -g -I/home/ruizhi/test/include

CXX_DEFINES =

laiall avatar Feb 14 '16 14:02 laiall

flycheck version?

redguardtoo avatar Feb 14 '16 22:02 redguardtoo

Flycheck version: 0.26snapshot (package: 20160208.706)

laiall avatar Feb 15 '16 01:02 laiall

flycheck works fine, stick to stable version 0.25.1.

M-x cppcm-reload-all then C-h v flycheck-clang-include-path. You should see list of strings in that flag.

As said in README, you need compile your program at least once to make sure your binary is compiled out.

redguardtoo avatar Feb 15 '16 11:02 redguardtoo

我个人感觉这个问题可能不是在 flycheck 上,从上面的debug info 中看 cppcm-include-dirs=(-I"/home/ruizhi/test/src/" -I"/home/ruizhi/test/src/" -I"/home/ruizhi/test/src/") 我的理解中就是说,cppcm-reload-all 后,没有把/home/ruizhi/test/include 放进include-dirs,不知道这么理解是否正确

flycheck-clang-include-path 是 ("/home/ruizhi/test/src/" "/home/ruizhi/test/src")

同时对上述示例工程进行 mkdir build; cd build; cmake ..; make; 是能够将工程编译成功,在build/lib 目录下,能看到目标的lib文件

另外就我自己的尝试来说,有一些重现的条件是在cmake文件中要有如下三句设置 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 同时如果工程当中有 add_executable 的话,先打开 executable 相关cc文件后,再打开library的cc文件就能正确识别出 /home/ruizhi/test/include 的路径,相当于不能识别出 include 路径只是在很少的情形下出现。

感谢您的耐心回复:)

laiall avatar Feb 15 '16 15:02 laiall

send a complete project to my mail chenbin.sh AT gmail

redguardtoo avatar Feb 15 '16 22:02 redguardtoo