Skip to content

Instantly share code, notes, and snippets.

@igilham igilham/CMakeLists.txt
Last active Aug 29, 2015

Embed
What would you like to do?
CMake Template
cmake_minimum_required(VERSION 2.8)
project(mylib C CXX)
# TODO: in cmake 3.2, we can set the version without making new variables
# project(asimux VERSION "1.0.0" C CXX)
set(VERSION_MAJOR "1")
set(VERSION_MINOR "0")
set(VERSION_PATCH "0")
set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
########## external libraries ##########
find_package(Threads REQUIRED)
########## source files ##########
set(HEADERS
src/Hello.h
)
set(SOURCE
src/Hello.cc
${HEADERS}
)
########## executable targets and linker instructions ##########
## myapp
add_executable(myapp
src/Hello.cpp
)
add_executable(myapp
my::myapp ALIAS myapp
)
target_include_directories(myapp
PUBLIC ${THREADS_INCLUDE_DIRS}
)
target_link_libraries(myapp
PUBLIC ${CMAKE_THREAD_LIBS_INIT}
)
## mylib
add_library(mylib STATIC
src/lib.cpp
)
target_include_directories(mylib
PUBLIC ${THREADS_INCLUDE_DIRS}
)
target_link_libraries(mylib
PUBLIC ${CMAKE_THREAD_LIBS_INIT}
)
########## Doxygen documentation target ##########
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif(DOXYGEN_FOUND)
########## install targets ##########
# install in binary directory, typically /usr/local/bin
install(
TARGETS mylib myapp
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
# install header files
install(
FILES
includes/mylib.h
DESTINATION
include/mylib
)
########## installer package generation ##########
set(CPACK_PACKAGE_NAME "libmylib")
set(CPACK_PACKAGE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
set(CPACK_PACKAGE_RELEASE 1)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "package summary")
set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README.md)
set(CPACK_GENERATOR "RPM" "DEB")
set(CPACK_PACKAGE_CONTACT "contact details")
set(CPACK_PACKAGE_VENDOR "Me")
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
set(
CPACK_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}-${CPACK_PACKAGE_RELEASE}.${CMAKE_SYSTEM_PROCESSOR}"
)
set(CPACK_RPM_PACKAGE_LICENSE "Copyright (c) Me 2013")
set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Me")
set(CPACK_DEBIAN_PACKAGE_SECTION "Development")
include(CPack)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.