c++ - How to setup Cmake to generate header-only projects? -


the title : want setup headers-only c++ (or c) library projects, can't find clean way.

after searches i've found can't setup normal library using add_library because requires compilable source file. way use add_custom_target instead, way :

# headers (using search instead of explicit filenames example) file( glob_recurse xsd_headers      *.hxx ) add_custom_target( libsxsd sources ${xsd_headers} ) 

but don't seem work here can't see sources in project generated in vs2010. don't know if it's bug or if i'm doing wrong or if there prefered way this, if have simple solution, please guest.

update: cmake include library target called interface ideal header-only projects. feature in master branch. reference.

using command add_custom_target propose works me (vs2010). files neatly listed within project has drawback can't define "additional include directories" custom target. instead, use following:

add_library(header_only_target static test1.hpp test2.hpp) set_target_properties(header_only_target properties linker_language cxx) 

this sets header-only project dummy archive target. don't worry, no actual binaries generated if should try , build (at least not in vs2010 , xcode 4). command set_target_properties there because cmake otherwise complain cannot infer target language .hpp files only.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -