+ # Setting DIMDIR, ODIR and ROOTSYS in the environment, they are needed by date-config
+ set(ENV{DIMDIR} ${DIMDIR})
+ set(ENV{ODIR} ${ODIR})
+ set(ENV{ROOTSYS} ${ROOTSYS})
+
+ # Checking DATE version
+ execute_process(COMMAND ${DATE_CONFIG} --version OUTPUT_VARIABLE DATE_VERSION ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
+ if(error)
+ message(FATAL_ERROR "Error retrieving DATE version : ${error}")
+ endif(error)
+ string(STRIP ${DATE_VERSION} DATE_VERSION)
+
+ # Extract major, minor, and patch versions from
+ string(REGEX REPLACE "^([0-9]+)\\.[0-9]+" "\\1" DATE_VERSION_MAJOR "${DATE_VERSION}")
+ string(REGEX REPLACE "^[0-9]+\\.([0-9]+)" "\\1" DATE_VERSION_MINOR "${DATE_VERSION}")
+ message(STATUS "DATE version ${DATE_VERSION_MAJOR}.${DATE_VERSION_MINOR} found.")
+
+ # setting the cflags
+ execute_process(COMMAND ${DATE_CONFIG} --cflags OUTPUT_VARIABLE DATE_CFLAGS ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
+ if(error)
+ message(FATAL_ERROR "Error retrieving DATE cflags : ${error}")
+ endif(error)
+
+ # If flags not empty we strip them
+ if(DATE_CFLAGS)
+ string(STRIP ${DATE_CFLAGS} DATE_CFLAGS)
+ endif()
+
+ set(DATE_CFLAGS "-DALI_DATE ${DATE_CFLAGS}")
+
+ # setting the ldflags
+ execute_process(COMMAND ${DATE_CONFIG} --ldflags OUTPUT_VARIABLE DATE_LDFLAGS ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
+ if(error)
+ message(FATAL_ERROR "Error retrieving DATE ldflags : ${error}")
+ endif(error)
+
+ # If the flags are not empty we strip them
+ if(DATE_LDFLAGS)
+ string(STRIP ${DATE_LDFLAGS} DATE_LDFLAGS)
+ endif()
+
+ # setting the libs
+ execute_process(COMMAND ${DATE_CONFIG} --libs OUTPUT_VARIABLE DATE_LIBS ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
+ if(error)
+ message(FATAL_ERROR "Error retrieving DATE libs : ${error}")
+ endif(error)
+
+ # If the flags are not empty we strip them
+ if(DATE_LIBS)
+ string(STRIP ${DATE_LIBS} DATE_LIBS)
+ endif()
+
+ # DATE_LIBRARIES
+ # Extracting the list of dynamic and static libraries from the --libs
+ # The list is needed during the generation of the DAs
+ # using a find_library in order to get the full path and not need to use -L during linking of the DAs
+ string(REGEX MATCHALL "[-]l[^- ]+" DATE_LIBRARIES_TMP ${DATE_LIBS})
+ string(REGEX REPLACE "[-]l" ";" DATE_LIBRARIES_TMP ${DATE_LIBRARIES_TMP})
+ # Get the list of search path using -Lyyy -> yyy
+ string(REGEX MATCHALL "[-]L[^- ]+" DATE_LIBRARIES_PATH_TMP ${DATE_LIBS})
+ string(REGEX REPLACE "[-]L" ";" DATE_LIBRARIES_PATH_TMP ${DATE_LIBRARIES_PATH_TMP})
+ find_date_libraries(DATE_LIBRARIES "${DATE_LIBRARIES_TMP}" "${DATE_LIBRARIES_PATH_TMP}")
+
+ # Fix for mysql bug https://bugs.launchpad.net/percona-server/+bug/1287374
+ set(DATE_LIBS "${DATE_LIBS} -L/usr/lib64/mysql/")
+
+ # setting the monlibs
+ execute_process(COMMAND ${DATE_CONFIG} --monitorlibs=noshift OUTPUT_VARIABLE DATE_MONLIBS ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
+ if(error)
+ message(FATAL_ERROR "Error retrieving DATE monitorlibs : ${error}")
+ endif(error)
+
+ # If the flags are not empty we strip them
+ if(DATE_MONLIBS)
+ string(STRIP ${DATE_MONLIBS} DATE_MONLIBS)
+ endif()
+
+ # DATE_MONLIBRARIES
+ # Extracting the list of dynamic and static libraries from the --libs
+ # The list is needed during the generation of the DAs
+ # Removing everything that starts with - to leave all the static libraries
+ # Replacing space with ; to create a list that will be sent to the linked
+ string(REGEX REPLACE "-[^ \r\n\t].+( |$)?" "" DATE_STATICMON ${DATE_MONLIBS})
+ if(DATE_STATICMON)
+ string(REPLACE " " ";" DATE_STATICMON ${DATE_STATICMON})
+ endif(DATE_STATICMON)
+
+ # Extracting all the shared libraries
+ # using a find_library in order to get the full path and not need to use -L during linking of the DAs
+ string(REGEX MATCHALL "[-]l[^- ]+" DATE_MONLIBRARIES_TMP ${DATE_MONLIBS})
+ string(REGEX REPLACE "[-]l" ";" DATE_MONLIBRARIES_TMP ${DATE_MONLIBRARIES_TMP})
+ # Get the list of search path using -Lyyy -> yyy
+ string(REGEX MATCHALL "[-]L[^- ]+" DATE_MONLIBRARIES_PATH_TMP ${DATE_MONLIBS})
+ string(REGEX REPLACE "[-]L" ";" DATE_MONLIBRARIES_PATH_TMP ${DATE_MONLIBRARIES_PATH_TMP})
+ find_date_libraries(DATE_MONLIBRARIES "${DATE_MONLIBRARIES_TMP}" "${DATE_MONLIBRARIES_PATH_TMP}")
+ set(DATE_MONLIBRARIES ${DATE_STATICMON} ${DATE_MONLIBRARIES})
+
+ # Fix for mysql bug https://bugs.launchpad.net/percona-server/+bug/1287374
+ set(DATE_MONLIBS "${DATE_MONLIBS} -L/usr/lib64/mysql/")
+
+ # setting the rclibs
+ execute_process(COMMAND ${DATE_CONFIG} --rcproxylibs OUTPUT_VARIABLE DATE_RCPROXYLIBS ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
+ if(error)
+ message(FATAL_ERROR "Error retrieving DATE rcproxylibs")
+ endif(error)
+
+ # If the flags are not empty we strip them
+ if(DATE_RCPROXYLIBS)
+ string(STRIP ${DATE_RCPROXYLIBS} DATE_RCPROXYLIBS)
+ endif()
+
+ # DATE_LIBRARIES
+ # Extracting the list of dynamic and static libraries from the --libs
+ # The list is needed during the generation of the DAs
+ string(REGEX MATCHALL "[-]l[^- ]+" DATE_RCPROXYLIBRARIES_TMP ${DATE_RCPROXYLIBS})
+ string(REGEX REPLACE "[-]l" ";" DATE_RCPROXYLIBRARIES_TMP ${DATE_RCPROXYLIBRARIES_TMP})
+ # Get the list of search path using -Lyyy -> yyy
+ string(REGEX MATCHALL "[-]L[^- ]+" DATE_RCPROXYLIBRARIES_PATH_TMP ${DATE_RCPROXYLIBS})
+ string(REGEX REPLACE "[-]L" ";" DATE_RCPROXYLIBRARIES_PATH_TMP ${DATE_RCPROXYLIBRARIES_PATH_TMP})
+ find_date_libraries(DATE_RCPROXYLIBRARIES "${DATE_RCPROXYLIBRARIES_TMP}" "${DATE_RCPROXYLIBRARIES_PATH_TMP}")
+
+ # setting the monlibs
+ execute_process(COMMAND ${DATE_CONFIG} --monitorlibs=dyn OUTPUT_VARIABLE DATE_DYNMONLIBS ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
+ if(error)
+ message(FATAL_ERROR "Error retrieving DATE monitorlibs : ${error}")
+ endif(error)
+
+ # If the flags are not empty we strip them
+ if(DATE_DYNMONLIBS)
+ string(STRIP ${DATE_DYNMONLIBS} DATE_DYNMONLIBS)
+ endif()
+
+ # unsetting all environment variables
+ unset(ENV{DIMDIR})
+ unset(ENV{ODIR})
+ unset(ENV{ROOTSYS})
+
+ set(DATE_FOUND TRUE)