{"id":24505712,"url":"https://github.com/caseymcc/cmake_add_package","last_synced_at":"2026-01-02T00:56:47.302Z","repository":{"id":150339306,"uuid":"63953273","full_name":"caseymcc/CMake_add_package","owner":"caseymcc","description":"CMake package handler.","archived":false,"fork":false,"pushed_at":"2016-07-28T22:17:01.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-21T23:33:25.331Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"CMake","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/caseymcc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-07-22T12:55:12.000Z","updated_at":"2016-07-28T22:04:09.000Z","dependencies_parsed_at":"2023-04-06T09:53:53.414Z","dependency_job_id":null,"html_url":"https://github.com/caseymcc/CMake_add_package","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caseymcc%2FCMake_add_package","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caseymcc%2FCMake_add_package/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caseymcc%2FCMake_add_package/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caseymcc%2FCMake_add_package/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/caseymcc","download_url":"https://codeload.github.com/caseymcc/CMake_add_package/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243707298,"owners_count":20334614,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-21T23:31:18.707Z","updated_at":"2026-01-02T00:56:47.276Z","avatar_url":"https://github.com/caseymcc.png","language":"CMake","funding_links":[],"categories":[],"sub_categories":[],"readme":"CMake AddPackage\n======\n\nThis is a CMake package handler. It will attempt to download a package (either cloning a git repo or downloading precompiled libs) and add it to your project. If it is a git repo and cmake based it will add the package project to your project.\n\n_It is pretty rough at the moment but does handle a few libs pretty well. I have also only tested on windows thus far and some of the download only packages will likely only work on windows._\n\n##How it works\nYou need to put the AddPackage.cmake and included directory \"packages\" somewhere CMake can find them. I usually create a directory along side my CMakeLists.txt file called CMakeModules then in the CMakeLists.txt add the following near the top\n\n```\nset(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules)\n```\n\nthen in the same CMakeLists.txt or per project CMakeLists.txt add the following _(add_package can be called multiple times with the same package)_\n\n```\ninclude(AddPackage)\n\nadd_package(\"opencl\")\nadd_package(\"glew\" VERSION \"2.0.0\")\n```\n\nProviding the optional VERSION tells the packager which version to get, assuming all goes well the packager creates a few CMake vars that can be used to add the include directory and libraries in your project.\n```\n${PACKAGE_NAME}_ROOT\n${PACKAGE_NAME}_INCLUDE_DIRS \n${PACKAGE_NAME}_BIN_DIRS\n${PACKAGE_NAME}_LIBRARIES\n${PACKAGE_NAME}_TARGET\n```\nfor example in the snippet above opencl would end up being OPENCL_INCLUDE_DIRS for header include folder.\n* ${PACKAGE_NAME}_ROOT - root to install folder\n* ${PACKAGE_NAME}_INCLUDE_DIRS - list of directories required for include\n* ${PACKAGE_NAME}_BIN_DIRS - list of directories where executables go\n* ${PACKAGE_NAME}_LIBRARIES - list of libraries provided by package\n* ${PACKAGE_NAME}_TARGET - CMake Target name for the added package\n\nGenerally what you do with these things is\n```\ninclude_directories(${OPENCL_INCLUDE_DIRS}) #provides include directories for including package\ntarget_link_libraries($YouProject ${OPENCL_LIBRARIES}) #includes libraries from the package to your project\nadd_dependencies(Base ${OPENCL_TARGET}) #forces opencl package to be compiled before your project\n```\n${PACKAGE_NAME}_ROOT helps if you have a find_package some where in your CMake calls that starts search at ${PACKAGE}_ROOT.\n\n\nYou can add a cmake argument ADD_PACKAGE_DIR which will tell the packager where to store all the files. \n```\ncmake -DADD_PACKAGE_DIR=\u003cdirectory for packages\u003e\n```\nIf not provided it selects ${CMAKE_SOURCE_DIR}/packages/. This var is nice if you have multiple independant projects that use the same packages then there will only be 1 copy.\n\n\n##Current Packages\n* _dlib_\n* _fftw_\n* _glew_\n* _glfw_\n* _glm_\n* _libpng_\n* _opencl_\n* _rapidjson_\n* _zlib_\n\n##More Details\nWhen add_package is called it attempts to locate a cmake file package${PACKAGE_NAME}.cmake, if that fails it will try to get it a repository from github https://github.com/${PACKAGE_NAME}/${PACKAGE_NAME}.git (which will likely fail as naming convention are not that good)\n\nIf it finds the cmake package file it will run what is inside. Generally that is something like the following\n```\n#zlib puts a v in front of their version labels\nset(ZLIB_GIT_TAG \"v${ADD_PACKAGE_VERSION}\")\n\nadd_git_package(${DEPENDENCY_PACKAGE_NAME} \"https://github.com/madler/zlib.git\" GIT_TAG ${ZLIB_GIT_TAG})\n\nset(${DEPENDENCY_PACKAGE_NAME}_LIBRARIES ${DEPENDENCY_PACKAGE_INSTALL_DIR}/lib/zlib.lib PARENT_SCOPE)\n```\nBasically converting the VERSION into a git tag and setting the repo url. Also setting the library(ies) that the package provides.\n\nWhen executed add_package will search for git on your machine and then get CPM from github.(used to update repos) When processing a package the uses git, it will place the repo in a directory ${ADD_PACKAGE_DIR}/source/${PACKAGE_NAME}-${VERSION}. It will then add the project to your project using ExternalProject_Add while setting ${ADD_PACKAGE_DIR}/build/${PACKAGE_NAME}-${VERSION} as the build folder and ${ADD_PACKAGE_DIR}/${PACKAGE_NAME}-{VERSION} as the install folder for the included package.\n\n##Writing package files\n\nFrom the package file the following functions can be called that are in AddPackage (and should only be called from there)\n* _add_git_package_ - will fetch the git repo with the tag provided and add and ExternalProject to the build.\n* _add_package_update_git_ - will update repo with tag\n* _add_package_project_ - will ExternalProject to the build\n\nAlong with those you can call any other CMake command. \n\nThe file also need to set the libraries it will build (or downloaded)\n```\n${PACKAGE_NAME}_LIBRARIES\n```\n\nIf you dont use add_git_package (or the directories reside somewhere else) you need to setup \n```\n${PACKAGE_NAME}_INCLUDE_DIRS\n${PACKAGE_NAME}_BIN_DIRS\n${PACKAGE_NAME}_LIBRARIES\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaseymcc%2Fcmake_add_package","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaseymcc%2Fcmake_add_package","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaseymcc%2Fcmake_add_package/lists"}