Snippets

Víctor Goñi Sanz CMakeLists_SUBPROJECT.txt

Created by Víctor Goñi Sanz last modified Pipero man
######### Remane file to CMakeLists.txt
#########     Use in a subfolder of your Main project, this file compile code in folders src and include.
#########     Use macro PRINTBASICINFO to check what directories are using by includes, link libraries.
########################################################################################################################################################################################
# Header
#-----------------------------------------------------------------------#
SET(PROJ_NAME project-name)
PROJECT(${PROJ_NAME})
STATUS(" + Adding module ${PROJ_NAME} ")				# In info

# Include directories with headers
#-----------------------------------------------------------------------#
INCLUDE_DIRECTORIES( directory1 directory2 ...)		# This projects' includes
#INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/include )		# This projects' includes
#INCLUDE_DIRECTORIES( ${${PROJ_MAIN_NAME}_PATH_MAIN}/modules/xxx )	# Other includes in modules

# Source, macro to find all files. If you add more, regenerate project
#-----------------------------------------------------------------------#
FILE(GLOB ${PROJ_NAME}_SRC
    "src/*.cpp"
)
FILE(GLOB ${PROJ_NAME}_HEADERS
    "include/*.h"
)
# Specify directories in which the linker will look for libraries
#-----------------------------------------------------------------------#
LINK_DIRECTORIES(directory1 directory2 ...)

# Add a library to the project using the specified source files
#-----------------------------------------------------------------------#
ADD_LIBRARY(${PROJ_NAME} ${${PROJ_MAIN_NAME}_LIB_TYPE} ${${PROJ_NAME}_HEADERS} ${${PROJ_NAME}_SRC} ) 

# Link targets to given libraries
#-----------------------------------------------------------------------#
TARGET_LINK_LIBRARIES(${PROJ_NAME} project-dependency1)

# Install
#-----------------------------------------------------------------------#
INSTALL(TARGETS ${PROJ_NAME}
        DESTINATION "${${PROJ_MAIN_NAME}_PATH_INSTALL}/${PROJ_NAME}/lib"
        )
INSTALL(FILES ${${PROJ_NAME}_HEADERS}
        DESTINATION "${${PROJ_MAIN_NAME}_PATH_INSTALL}/${PROJ_NAME}/include"
        )

#PRINTBASICINFO(${PROJ_NAME})						# Macro cmake_tools to print, uncomment to add info
STATUS(" - Module ${PROJ_NAME} added!")					# Out info

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.