# (C) Copyright 2008-2009 SDML (www.sdml.info) # # Use, modification and distribution is subject to the Boost Software # License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) # Declare a new origin library project. # # origin_library_project(libname # [DEPENDS dep1 dep2 ...] # [AUTHORS author1 author2 ...] # [MAINTAINERS maintainer1 maintainer2 ...] # [DESCRIPTION description]) # # This macro sets the following variables that describe the library. # # The ORIGIN_${LIBNAME}_ROOT variable gives the path to the root directory # of the described project. This macro currently assumes a fixed, modular # layout. # # The ORIGIN_${LIBNAME}_INCLUDE_DIR variable gives the path to the primary # include directory for the libaray. # # The ORIGIN_${LIBNAME}_INCLUDE_DIRS variable is a list of all the include # directories computed from the dependencies given in the macro. If empty, this # will only include the include directory (above). # # # TODO: There's probably a lot more work that could be done describing library # projects. For example, we should be able list several source, test, or include # directories. macro(origin_library_project libname) parse_arguments(parsed "DEPENDS;AUTHORS;MAINTAINERS;DESCRIPTION" "" ${ARGN}) # Generate upper/lowercase versions of the library name. string(TOUPPER ${libname} upper_libname) string(TOLOWER ${libname} lower_libname) # Generate some variables that describe the structure of the project # being created. This includes the paths to header, tests, etc. For now # this assumes a simple fixed structure and that none of the libraries # in question are actually building binary components. string(TOUPPER "ORIGIN_${libname}" prefix) set("${prefix}_ROOT" ${CMAKE_CURRENT_SOURCE_DIR}) # Define some variables that are useful locally... set(ORIGIN_CURRENT_PROJECT ${lower_libname}) # Define this library's include directory. set(include_dir "${prefix}_INCLUDE_DIR") set(${include_dir} ${CMAKE_CURRENT_SOURCE_DIR}/include) # Enumerate dependencies on other libraries. For now, this will translate # the dependent libraries into path names that are required in order for # the build to succeed. For now, we're just assuming that we can find them # in a trunk relative to the source (i.e. root/dep). In other words, we're # relying on a fixed directory structure rather than trying to be # flexible. # TODO: This doesn't really work as well as I'd like it to. What if you # want to re-target the dependency (i.e,. tags/core-1.2) or something. # set("ORIGIN_${prefix}_INCLUDE_DIRS") set(include_dirs "${prefix}_INCLUDE_DIRS") if(parsed_DEPENDS) # Define a globally available variable that stores the dependencies # for the library. set(deps "${prefix}_DEPENDS") set(${deps} ${parsed_DEPENDS}) foreach(dep ${${deps}}) set(dep_root ${ORIGIN_ROOT}/${dep}) set(dep_inc ${dep_root}/include) list(APPEND incs ${dep_inc}) endforeach() set(${include_dirs} ${incs}) endif() # Set include_dirs to the this libraries include directory plus those of # the configured dependencies. Also, automatically register these include # directories for the project. set(${include_dirs} ${${include_dir}} ${${include_dirs}}) include_directories(${${include_dirs}}) # Generate some targets that will be used in testing. Essentially, each # the regression build will depend on individual project-tests. Note that # the "driver" installs a target that simply prints what's being built # prior to the actual compilation. add_custom_target(${ORIGIN_CURRENT_PROJECT}-test) add_dependencies(tests ${ORIGIN_CURRENT_PROJECT}-test) endmacro()