I remember seeing mac apps out there that will do it. Some of them cost a small fee. I have never used any of them but they look easy to use.
I will tell you how I do it and it is free.
1) back up you iphone. Your sms messages are stored in your backup.
2) download Iphone Backup Extractor. This will allow you to see the contents of your backup. Extract IOS Files. What you get is a bunch of IOS system files and librarys and such. just do a search for sms.db which is the db file that contains all your txt messages.
3) run the shell script from below.
#!/bin/bash
# Extracts SMSs in CSV format from iPhone backup
SQL="select datetime(date, 'unixepoch', 'localtime') as \"date\", case when flags=3 then 'sent to' else 'rec from' end as \"from\", address as phone, text as \"message\" from message;"
FILE="./sms.db"
sqlite3 -csv -header -separator ',' "${FILE}" "${SQL}"