set(FIND_PROJECT_TEMPLATE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/template_find_project.cmake" CACHE STRING "Name of the file which contains the template to generate FindProgram.cmake files") set(FIND_HEADER_PROJECT_TEMPLATE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/template_find_header_project.cmake" CACHE STRING "Name of the file which contains the template to generate FindProgram.cmake files but only with header") set(FIND_PROGRAM_PROJECT_TEMPLATE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/template_find_program.cmake" CACHE STRING "Name of the file which contains the template to generate FindProgram.cmake files but only with program") # Create the target to create the find cmake file # projectName : name of the project to be used # libraryTargetName : name of the library to be searched # headerFile : header to be searched # extraIncludeFile : extra include file to be used function(phoenix_create_find projectName libraryTargetName headerFile extraIncludeFile) set(findFileName "Find${projectName}.cmake") string(TOUPPER ${projectName} PROJECT_NAME_UPPER) set(fullDependModule "") set(EXTRA_DEPENDENCIES_LIB "") foreach(dependencyModule ${ARGN}) string(APPEND fullDependModule "find_package(${dependencyModule} REQUIRED)\n") string(TOUPPER ${dependencyModule} DEPENDENCY_MODULE_UPPER) string(APPEND EXTRA_DEPENDENCIES_LIB " \${${DEPENDENCY_MODULE_UPPER}}") endforeach(dependencyModule) set(PHOENIX_PACKAGE_PEDENDENCIES "${fullDependModule}") if(extraIncludeFile STREQUAL "") set(EXTRA_INCLUDE_CMAKE "") else() set(EXTRA_INCLUDE_CMAKE "include(${CMAKE_MODULE_PATH}/${extraIncludeFile})") endif() configure_file(${FIND_PROJECT_TEMPLATE_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${findFileName} @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${findFileName} DESTINATION share/cmake) endfunction(phoenix_create_find) # Create the target to create the find cmake file # projectName : name of the project to be used # libraryTargetName : name of the library to be searched # headerFile : header to be searched (will be used in the header template) # extraIncludeFile : extra include file to be used function(phoenix_create_find_header projectName headerFile extraIncludeFile) set(findFileName "Find${projectName}.cmake") string(TOUPPER ${projectName} PROJECT_NAME_UPPER) set(fullDependModule "") set(EXTRA_DEPENDENCIES_LIB "") foreach(dependencyModule ${ARGN}) string(APPEND fullDependModule "find_package(${dependencyModule} REQUIRED)\n") string(TOUPPER ${dependencyModule} DEPENDENCY_MODULE_UPPER) string(APPEND EXTRA_DEPENDENCIES_LIB " \${${DEPENDENCY_MODULE_UPPER}}") endforeach(dependencyModule) set(PHOENIX_PACKAGE_PEDENDENCIES "${fullDependModule}") if(extraIncludeFile STREQUAL "") set(EXTRA_INCLUDE_CMAKE "") else() set(EXTRA_INCLUDE_CMAKE "include(${CMAKE_MODULE_PATH}/${extraIncludeFile})") endif() configure_file(${FIND_HEADER_PROJECT_TEMPLATE_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${findFileName} @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${findFileName} DESTINATION share/cmake) endfunction(phoenix_create_find_header) # Create the target to create the find cmake file # projectName : name of the project to be used # libraryTargetName : name of the library to be searched # programFile : header to be searched (will be used in the program template) # extraIncludeFile : extra include file to be used function(phoenix_create_find_program projectName programTargetName extraIncludeFile) set(findFileName "Find${projectName}.cmake") string(TOUPPER ${projectName} PROJECT_NAME_UPPER) set(fullDependModule "") set(EXTRA_DEPENDENCIES_LIB "") foreach(dependencyModule ${ARGN}) string(APPEND fullDependModule "find_package(${dependencyModule} REQUIRED)\n") string(TOUPPER ${dependencyModule} DEPENDENCY_MODULE_UPPER) string(APPEND EXTRA_DEPENDENCIES_LIB " \${${DEPENDENCY_MODULE_UPPER}}") endforeach(dependencyModule) set(PHOENIX_PACKAGE_PEDENDENCIES "${fullDependModule}") if(extraIncludeFile STREQUAL "") set(EXTRA_INCLUDE_CMAKE "") else() set(EXTRA_INCLUDE_CMAKE "include(${CMAKE_MODULE_PATH}/${extraIncludeFile})") endif() configure_file(${FIND_PROGRAM_PROJECT_TEMPLATE_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${findFileName} @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${findFileName} DESTINATION share/cmake) 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})") install(FILES ${extraIncludeFile} DESTINATION share/cmake) 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 STRING \"${PROJECT_NAME_UPPER} libraries and dependencies\")\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} "set(${PROJECT_NAME_UPPER}_FOUND \"YES\" CACHE BOOL \"${PROJECT_NAME_UPPER} progect found\")\n") file(APPEND ${findFileName} "${EXTRA_INCLUDE_CMAKE}\n\n") install(FILES ${findFileName} DESTINATION share/cmake) endfunction(phoenix_create_find_full)