[CMake] Bug? Broken header files in Visual C++ 2008 project
Mike Jackson
mike.jackson at bluequartz.net
Thu Aug 28 10:56:45 EDT 2008
On Aug 28, 2008, at 10:16 AM, John Drescher wrote:
>> What about those of us that do not want the header files compiled (no
>> pre-compiled headers, etc.), but still want the folders to show up
>> in Visual
>> Studio (or any other IDE)?
>>
> That is how it works in my example.
>
> John
This is how I have things setup in my projects. For each source folder
I have a SourceList.cmake file that lists the sources and headers into
2 cmake variables, for example:
SET (MXA_DATA_IMPORT_SRCS
${MXA_SOURCE_DIR}/src/DataImport/ImportDelegateManager.cpp
)
SET (MXA_DATA_IMPORT_HEADERS
${MXA_SOURCE_DIR}/src/DataImport/AbstractImportDelegateFactory.h
${MXA_SOURCE_DIR}/src/DataImport/ImportDelegateManager.h
)
MXA_SOURCE_PROPERTIES(DataImport "${MXA_DATA_IMPORT_HEADERS}" "$
{MXA_DATA_IMPORT_SRCS}")
"MXA_SOURCE_PROPERTIES" is a macro with the following content:
##-----------------
MACRO (MXA_SOURCE_PROPERTIES NAME HEADERS SOURCES)
INSTALL (FILES ${HEADERS}
DESTINATION include/MXADataModel/${NAME}
COMPONENT Headers
)
source_group(src\\${NAME} FILES ${HEADERS} ${SOURCES})
#-- The following is needed if we ever start to use OS X Frameworks
but only
#-- works on CMake 2.6 and greater
#set_property(SOURCE ${HEADERS}
# PROPERTY MACOSX_PACKAGE_LOCATION Headers/${NAME}
#)
ENDMACRO (MXA_SOURCE_PROPERTIES NAME HEADERS SOURCES)
#---------------------------------
Then in the top level CMakeLists.txt file I include those sub
directory cmake files and then gather all those variables into one
cmake variable and use that in the add_library(...) call.
INCLUDE (${MXA_SOURCE_DIR}/src/DataImport/DataImport_SourceList.cmake)
# ------- Set up the MXADataModel Project Source Files -----------
SET( MXADATAMODEL_SRCS
${MXA_BASE_SRCS}
${MXA_BMPIO_SRCS}
${MXA_COMMON_SRCS}
${MXA_CORE_SRCS}
${MXA_DATA_IMPORT_SRCS}
${MXA_DATA_WRAPPERS_SRCS}
${MXA_UTILITIES_SRCS}
)
#--- Adding headers is NOT needed unless you want Visual Studio or
Xcode to have them in their projects
SET (MXADATAMODEL_HEADERS
${MXA_BASE_HEADERS}
${MXA_BMPIO_HEADERS}
${MXA_COMMON_HEADERS}
${MXA_CORE_HEADERS}
${MXA_DATA_IMPORT_HEADERS}
${MXA_DATA_WRAPPERS_HEADERS}
${MXA_UTILITIES_HEADERS}
)
ADD_LIBRARY (${MXADATAMODEL_LIB_NAME} ${LIB_TYPE} ${PROJECT_SRCS} )
if you want to take a look at the project, try going to:
<http://www.bluequartz.net/viewvc/CTMD/MXADataModel/> and take a look
around. This setup at least will give me subgroups in Visual Studio
and list both the headers and source files. There are other ways of
doing the same thing but this seems to work for me.
----------------------------------------
Mike Jackson - BlueQuartz Software Consulting
<www.bluequartz.net>
mike.jackson at bluequartz.net
More information about the CMake
mailing list