Commit 3be5493f authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Add generic find project generator

parent 9d6303d1
...@@ -87,3 +87,151 @@ function(phoenix_create_find_program projectName programTargetName extraIncludeF ...@@ -87,3 +87,151 @@ function(phoenix_create_find_program projectName programTargetName extraIncludeF
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${findFileName} DESTINATION share/cmake) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${findFileName} DESTINATION share/cmake)
endfunction(phoenix_create_find_program) endfunction(phoenix_create_find_program)
# Create the full CMake Find macro for this project
# projectName : name of the project to be used
# listIncludeFile : list of all include files of the project (or only the most important)
# listLibrary : list of all libraries of the project
# listProgram : list of the programs of the projet
# extraIncludeFile : extra include file to be used
# ARGN : list of extra dependencies of the project
function(phoenix_create_find_full projectName listIncludeFile listLibrary listProgram extraIncludeFile)
set(findFileName "${CMAKE_CURRENT_BINARY_DIR}/Find${projectName}.cmake")
string(TOUPPER ${projectName} PROJECT_NAME_UPPER)
if(extraIncludeFile STREQUAL "")
set(EXTRA_INCLUDE_CMAKE "")
else()
set(EXTRA_INCLUDE_CMAKE "include(${CMAKE_MODULE_PATH}/${extraIncludeFile})")
endif()
file(WRITE ${findFileName} "\n")
file(APPEND ${findFileName} "#########################################\n")
file(APPEND ${findFileName} "# Author : Pierre Aubert\n")
file(APPEND ${findFileName} "# Mail : aubertp7@gmail.com\n")
file(APPEND ${findFileName} "# Licence : CeCILL-C\n")
file(APPEND ${findFileName} "#########################################\n\n")
# Let's deal with the multiple inclusion in the same project
file(APPEND ${findFileName} "if(${PROJECT_NAME_UPPER}_FOUND)\n")
file(APPEND ${findFileName} "\tlink_directories(\${${PROJECT_NAME_UPPER}_LIBRARY_DIR})\n")
file(APPEND ${findFileName} "\tinclude_directories(\${${PROJECT_NAME_UPPER}_INCLUDE_DIR} \${${PROJECT_NAME_UPPER}_INCLUDE_DIR}/../)\n")
file(APPEND ${findFileName} "\t${EXTRA_INCLUDE_CMAKE}\n")
file(APPEND ${findFileName} "\treturn()\n")
file(APPEND ${findFileName} "endif()\n\n")
# Let's deal with the extra find package
set(EXTRA_DEPENDENCIES_LIB "")
foreach(dependencyModule ${ARGN})
file(APPEND ${findFileName} "find_package(${dependencyModule} REQUIRED)\n")
string(APPEND fullDependModule "")
string(TOUPPER ${dependencyModule} DEPENDENCY_MODULE_UPPER)
string(APPEND EXTRA_DEPENDENCIES_LIB " \${${DEPENDENCY_MODULE_UPPER}}")
endforeach(dependencyModule)
file(APPEND ${findFileName} "\n")
# Let's deal with the list of include
list(LENGTH listIncludeFile nbIncludeFile)
if(${nbIncludeFile} GREATER_EQUAL 1)
file(APPEND ${findFileName} "###############################################\n")
file(APPEND ${findFileName} "#\tFind Header of project ${projectName}\n")
file(APPEND ${findFileName} "###############################################\n\n")
file(APPEND ${findFileName} "find_path(${PROJECT_NAME_UPPER}_INCLUDE_DIR\n")
file(APPEND ${findFileName} "\tNAMES")
foreach(includeFile ${listIncludeFile})
file(APPEND ${findFileName} " ${includeFile}")
endforeach(includeFile)
file(APPEND ${findFileName} "\n")
file(APPEND ${findFileName} "\tPATHS \${${PROJECT_NAME_UPPER}_PREFIX}/include/${projectName} \${CMAKE_INSTALL_PREFIX}/include/${projectName}\n")
file(APPEND ${findFileName} "\t\$ENV{HOME}/usr/include/${projectName} \${CMAKE_INCLUDE_PATH}/${projectName} /usr/include/${projectName} /usr/local/include/${projectName}\n")
file(APPEND ${findFileName} ")\n\n")
file(APPEND ${findFileName} "if(${PROJECT_NAME_UPPER}_INCLUDE_DIR)\n")
file(APPEND ${findFileName} "\tmessage(STATUS \"Found ${PROJECT_NAME_UPPER} headers : \${${PROJECT_NAME_UPPER}_INCLUDE_DIR}\")\n")
file(APPEND ${findFileName} "\tset(${PROJECT_NAME_UPPER}_INCLUDE_DIR \"\${${PROJECT_NAME_UPPER}_INCLUDE_DIR}\" CACHE STRING \"${PROJECT_NAME_UPPER} include directory\")\n")
file(APPEND ${findFileName} "else(${PROJECT_NAME_UPPER}_INCLUDE_DIR)\n")
file(APPEND ${findFileName} "\tmessage(FATAL_ERROR \"${PROJECT_NAME_UPPER} headers not found\")\n")
file(APPEND ${findFileName} "endif(${PROJECT_NAME_UPPER}_INCLUDE_DIR)\n")
file(APPEND ${findFileName} "\n")
file(APPEND ${findFileName} "include_directories(\${${PROJECT_NAME_UPPER}_INCLUDE_DIR} \${${PROJECT_NAME_UPPER}_INCLUDE_DIR}/../)\n")
file(APPEND ${findFileName} "\n\n")
endif()
list(LENGTH listLibrary nbLibrary)
if(${nbLibrary} GREATER_EQUAL 1)
file(APPEND ${findFileName} "###############################################\n")
file(APPEND ${findFileName} "#\tFind Libraries of project ${projectName}\n")
file(APPEND ${findFileName} "###############################################\n\n")
file(APPEND ${findFileName} "set(LIBRARY_SUFFIX \".so\")\n")
file(APPEND ${findFileName} "if(APPLE)\n")
file(APPEND ${findFileName} "\tset(LIBRARY_SUFFIX \".dylib\")\n")
file(APPEND ${findFileName} "endif()\n\n")
file(APPEND ${findFileName} "find_path(${PROJECT_NAME_UPPER}_LIBRARY_DIR\n")
file(APPEND ${findFileName} "\tNAMES")
foreach(libraryName ${listLibrary})
file(APPEND ${findFileName} " lib${libraryName}\${LIBRARY_SUFFIX}")
endforeach(libraryName)
file(APPEND ${findFileName} "\n")
file(APPEND ${findFileName} "\tPATHS \${${PROJECT_NAME_UPPER}_PREFIX}/lib \${CMAKE_INSTALL_PREFIX}/lib \$ENV{HOME}/usr/lib \${CMAKE_INCLUDE_PATH}/lib /usr/lib /usr/local/lib /lib\n")
file(APPEND ${findFileName} ")\n\n")
file(APPEND ${findFileName} "if(${PROJECT_NAME_UPPER}_LIBRARY_DIR)\n")
file(APPEND ${findFileName} "\tset(${PROJECT_NAME_UPPER}_PREFIX \"\${${PROJECT_NAME_UPPER}_LIBRARY_DIR}/..\")\n")
file(APPEND ${findFileName} "\tset(${PROJECT_NAME_UPPER} ")
foreach(libraryName ${listLibrary})
file(APPEND ${findFileName} " ${libraryName}")
endforeach(libraryName)
file(APPEND ${findFileName} " ${EXTRA_DEPENDENCIES_LIB} CACHE PATHS \"${PROJECT_NAME_UPPER} libraries and dependencies\")\n")
file(APPEND ${findFileName} "\tset(${PROJECT_NAME_UPPER}_FOUND \"YES\" CACHE BOOL \"${PROJECT_NAME_UPPER} progect found\")\n")
file(APPEND ${findFileName} "\tlink_directories(\${${PROJECT_NAME_UPPER}_LIBRARY_DIR})\n")
file(APPEND ${findFileName} "else()\n")
file(APPEND ${findFileName} "\tmessage(FATAL_ERROR \"Libraries of ${PROJECT_NAME_UPPER} not found\")\n")
file(APPEND ${findFileName} "endif()\n\n")
endif()
list(LENGTH listProgram nbProgram)
if(${nbProgram} GREATER_EQUAL 1)
file(APPEND ${findFileName} "###############################################\n")
file(APPEND ${findFileName} "#\tFind Programs of project ${projectName}\n")
file(APPEND ${findFileName} "###############################################\n\n")
file(APPEND ${findFileName} "find_path(${PROJECT_NAME_UPPER}_EXECUTABLE_DIR\n")
file(APPEND ${findFileName} "\tNAMES")
foreach(programName ${listProgram})
file(APPEND ${findFileName} " ${programName}")
endforeach(programName)
file(APPEND ${findFileName} "\n")
file(APPEND ${findFileName} "\tPATHS \${${PROJECT_NAME_UPPER}_PREFIX}/bin \${CMAKE_INSTALL_PREFIX}/bin \$ENV{HOME}/usr/bin \${CMAKE_INCLUDE_PATH}/bin /usr/bin /usr/local/bin /bin\n")
file(APPEND ${findFileName} ")\n")
file(APPEND ${findFileName} "\n")
file(APPEND ${findFileName} "if(${PROJECT_NAME_UPPER}_EXECUTABLE_DIR)\n")
file(APPEND ${findFileName} "\tmessage(STATUS \"Found programs of ${PROJECT_NAME_UPPER} : \${${PROJECT_NAME_UPPER}_EXECUTABLE_DIR}\")\n")
file(APPEND ${findFileName} "\tset(${PROJECT_NAME_UPPER}_EXECUTABLE_DIR \"\${${PROJECT_NAME_UPPER}_EXECUTABLE_DIR}\" CACHE STRING \"${PROJECT_NAME_UPPER} program directory\")\n")
foreach(programName ${listProgram})
string(TOUPPER ${programName} PROGRAM_NAME_UPPER)
file(APPEND ${findFileName} "\tset(${PROJECT_NAME_UPPER}_${PROGRAM_NAME_UPPER}_EXECUTABLE \"\${${PROJECT_NAME_UPPER}_EXECUTABLE_DIR}/${programName}\" CACHE STRING \"${PROJECT_NAME_UPPER}'s ${programName} program\")\n")
endforeach(programName)
file(APPEND ${findFileName} "else(${PROJECT_NAME_UPPER}_EXECUTABLE_DIR)\n")
file(APPEND ${findFileName} "\tmessage(FATAL_ERROR \"Programs of ${PROJECT_NAME_UPPER} not found\")\n")
file(APPEND ${findFileName} "endif(${PROJECT_NAME_UPPER}_EXECUTABLE_DIR)\n")
file(APPEND ${findFileName} "\n\n")
endif()
file(APPEND ${findFileName} "${EXTRA_INCLUDE_CMAKE}\n\n")
install(FILES ${findFileName} DESTINATION share/cmake)
endfunction(phoenix_create_find_full)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment