0

Let me use a simple example to illustrate my problem, and suppose now I have the following files:

src
---CMakeLists.txt
---a.h
---a.cpp
---script.py

In the CMakeLists.txt file, a target called lib_proj is created:

add_library(lib_proj STATIC a.h a.cpp)

Then in Visual Studio, we can see an object target called 'lib_proj' is created, which includes a.h and a.cpp. Then how can script.py be added to this target as well?

Wolf
  • 9,246
  • 7
  • 59
  • 101
feelfree
  • 10,375
  • 18
  • 86
  • 152

1 Answers1

0
add_library(lib_proj STATIC a.h a.cpp script.py)
Peter
  • 9,045
  • 4
  • 39
  • 65
  • Thanks, but I am afraid that those additional files will not contribute to the static library building. – feelfree Jun 19 '15 at 08:59
  • What do you mean by contribute? You will see them in VS, but obviously they will not be compiled or part of static library. – Peter Jun 19 '15 at 09:00
  • You won't need `CMakeLists.txt` because that's added by CMake itself to the VS project. The C++ extensions handled by CMake: `set(CMAKE_CXX_IGNORE_EXTENSIONS inl;h;hpp;HPP;H;o;O;obj;OBJ;def;DEF;rc;RC)` and `set(CMAKE_CXX_SOURCE_FILE_EXTENSIONS C;M;c++;cc;cpp;cxx;mm;CPP)` (see [How to add in a CMake project a global file extension (*.pde) to GCC which is treated like C++ code](http://stackoverflow.com/questions/30556429/how-to-add-in-a-cmake-project-a-global-file-extension-pde-to-gcc-which-is-tr)). I assume you have to add `set_source_files_properties(script.py PROPERTIES HEADER_FILE_ONLY 1)`. – Florian Jun 19 '15 at 14:22