The easiest way is to find (e.g. with google) a FindMySQL.cmake script that works for you. This script can be used with the find_package command, as usual:
list(CMAKE_MODULE_PATH APPEND <directory-where-FindMySQL.cmake-exists>) find_package(MySQL REQUIRED) include_directories(${MYSQL_INCLUDE_DIR}) target_link_libraries(cgm ${MYSQL_LIB})
(The variable names MYSQL_INCLUDE_DIR and MYSQL_LIB may be different for a particular script).
But itβs easy to manually link the MySQL library, knowing the way to calculate CFLAGS and LIBS.
During the configuration phase (execution of cmake ), programs can be executed with execute_process , to add CFLAGS and LIBS for a specific purpose, use target_compile_options and target_link_libraries respectively:
execute_process(COMMAND mysql_config --cflags OUTPUT_VARIABLE MYSQL_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND mysql_config --libs OUTPUT_VARIABLE MYSQL_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE) target_compile_options(cgm PUBLIC ${MYSQL_CFLAGS}) target_link_libraries(cgm ${MYSQL_LIBS})
Tsyvarev
source share