Skip to content

Instantly share code, notes, and snippets.

@robertmaynard
Created March 15, 2013 14:19
Show Gist options
  • Save robertmaynard/5170173 to your computer and use it in GitHub Desktop.
Save robertmaynard/5170173 to your computer and use it in GitHub Desktop.
cmake example of optional libraries
find_package(Python)
if(Python_FOUND)
#if python exists enable plugins that depend on python, this allows the user
#to turn off the python plugins even if python is found
option(ENABLE_Python_plugins "Turn on Plugins that depend on python existing" ${Python_FOUND})
endif()
#if you have your python dependent plugins in a directory you can do this
if(ENABLE_Python_plugins)
add_subdirectory(python_plugins)
endif()
#or if they python plugins are mixed into your source code directories
#you will have to wrap the add_library
if(ENABLE_Python_plugins)
add_library(python_Lib)
target_link_library(python_Lib)
endif()
#now if you have lots of places where you are adding libraries that depend on
#python or V8 you might want to create macros that handle all the logic for
#you.
macro (addPythonLibrary name)
if(ENABLE_Python_plugins)
add_library(${name} ${ARGV})
endif()
endmacro()
#now to call the macro use:
addPythonLibrary(python_Lib)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment