[CMake] header files with visual studio

Ryan Pavlik rpavlik at iastate.edu
Thu Nov 4 13:54:30 EDT 2010


I just add them in the normal calls, then set them as "PUBLIC_HEADER"
if I am making a library.  (Visual Studio seems to automatically
separate source and header files - easy to override if you prefer
something else.)

set(SOURCES
	whatever.c
	morestuff.c)
set(API
	whatever.h)

add_library(whatever SHARED ${SOURCES} ${API})

set_property(TARGET
	whatever
	PROPERTY
	PUBLIC_HEADER
	${API})

install(TARGETS
	whatever
	RUNTIME DESTINATION bin COMPONENT Runtime
	LIBRARY DESTINATION lib COMPONENT SDK
	PUBLIC_HEADER DESTINATION include COMPONENT SDK)


On Thu, Nov 4, 2010 at 12:34 PM, Michael Jackson
<mike.jackson at bluequartz.net> wrote:
> I have a macro to help with this:
>
> MACRO (cmp_IDE_SOURCE_PROPERTIES SOURCE_PATH HEADERS SOURCES INSTALL_FILES)
>    if (${INSTALL_FILES} EQUAL "1")
>        INSTALL (FILES ${HEADERS}
>                 DESTINATION include/${SOURCE_PATH}
>                 COMPONENT Headers
>        )
>    endif()
>    STRING(REPLACE "/" "\\\\" source_group_path ${SOURCE_PATH}  )
>    source_group(${source_group_path} FILES ${HEADERS} ${SOURCES})
> ENDMACRO (cmp_IDE_SOURCE_PROPERTIES NAME HEADERS SOURCES INSTALL_FILES)
>
> So an example would be:
>
> set (my_HDRS  ${PROJECT_SOURCE_DIR}/Headers/MyHeader.h )
> set (my_SRCS  ${PROJECT_SOURCE_DIR}/Source/MySource.cpp)
> set (my_INSTALL "0")
> cmp_IDE_SOURCE_PROPERTIES("Source" "${my_HDRS}" "${my_SRCS}"
> "${my_INSTALL}")
> add_executable(my ${my_HDRS} ${my_SRCS})
>
> Like, others have stated: You MUST include them in the add_executable or
> add_library call. The macro I give above can help keep those files organized
> in the Project/Solution file if you want the organization to mimic the file
> system for instance. Otherwise CMake will create the project will all the
> files in a single "Source" folder.
> HTH
> ___________________________________________________________
> Mike Jackson                      www.bluequartz.net
> Principal Software Engineer       mike.jackson at bluequartz.net
> BlueQuartz Software               Dayton, Ohio
>
>
>
> On Nov 4, 2010, at 1:26 PM, David Cole wrote:
>
>> That's funny...
>>
>> Google for "cmake header visual studio" and hit #1 explains it pretty
>> well:
>>
>> http://stackoverflow.com/questions/1167154/listing-header-files-in-visual-studio-c-project-generated-by-cmake
>>
>> So do hits #2 through 10.
>>
>>
>> On Thu, Nov 4, 2010 at 11:58 AM, Oliver kfsone Smith <osmith at playnet.com>
>> wrote:
>>>
>>> Checked the faq and googled as much as I could but I couldn't find
>>> anything
>>> describing how to make visual studio include header files in the
>>> solution/project files?
>>>
>>> - Oliver
>>>
>>> _______________________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the CMake FAQ at:
>>> http://www.cmake.org/Wiki/CMake_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.cmake.org/mailman/listinfo/cmake
>>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the CMake FAQ at:
>> http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.cmake.org/mailman/listinfo/cmake
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>



-- 
Ryan Pavlik
HCI Graduate Student
Virtual Reality Applications Center
Iowa State University

rpavlik at iastate.edu
http://academic.cleardefinition.com
Internal VRAC/HCI Site: http://tinyurl.com/rpavlik


More information about the CMake mailing list