I don’t believe that’s related to the sort of exports that gmodule is looking for, and regardless it’s unnecessary because…
And because that’s a requirement, it’s encoded into the pkg-config data for the library:
$ pkg-config --cflags --libs gmodule-export-2.0 |fmt
-I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include
-I/usr/include/sysprof-6 -pthread -Wl,--export-dynamic -lgmodule-2.0
-pthread -lglib-2.0
So if you get the pkg_check_modules stuff right, it’ll be taken care of automatically.
A couple of observations:
- While it’s not wrong to set up each pkg-config dependency separately, if they’re all targeted to the same executable/library, you can also do them all at once for convenience — it’s called
pkg_check_moduleS()
, plural. - I’d suggest raising your
cmake_minimum_required()
version to the still-ancient 3.7, and tellingFindPkgConfig
to create a target with the pkg-config dependencies, so that you can consume all of its results with a simpletarget_link_libraries()
call.
So, something like this should work:
cmake_minimum_required(3.7 .. 3.30)
find_package(PkgConfig REQUIRED)
pkg_check_modules(
Dependencies REQUIRED
IMPORTED_TARGET
gtk4>=4.16.5
libadwaita-1>=1.6.1
gmodule-export-2.0>=2.82.2
)
FindPkgConfig will create a target named PkgConfig::Dependencies
with all of the CFLAGS, linker args, and etc. set up on it, which you can use on your executable:
add_executable(DrogonCMS ${SOURCES})
# ...after all of the dependency-finding...
target_link_libraries(
DrogonCMS PRIVATE
PkgConfig::Dependencies
)
…that replaces all of the ${[GTK4|ADW|GMODULE-EXPORTS-2.0]_INCLUDE_DIRS}
, ${..._LIBRARY_DIRS}
, ${... CFLAGS_OTHER}
, etc. you were consuming.
Note that you’ll still have to set up the other dependencies on your executable target, though I’d suggest doing that with the targeted (no pun) commands instead:
target_include_directories(
DrogonCMS PRIVATE
${PostgreSQL_INCLUDE_DIRS}
# etc...
)
…Or, better yet, if you up your cmake_minimum_required()
version a bit farther to CMake 3.14 (which is still pretty old), FindPostgreSQL will create an IMPORTED target just like pkg-config. So then you just do,
find_package (PostgreSQL)
if (TARGET PostgreSQL::PostgreSQL)
target_link_libraries(DrogonCMS PRIVATE
PostgreSQL::PostgreSQL
)
else()
pkg_check_modules(
Sqlite3 REQUIRED
IMPORTED_TARGET
sqlite3>=3.43.1
)
# Not technically necessary because the
# REQUIRED would cause pkg_check_modules
# to fail if it couldn't create it, but...
if(TARGET PkgConfig::Sqlite3)
target_link_libraries(DrogonCMS PRIVATE
PkgConfig::Sqlite3
)
endif()
endif()
…Oh, and as a final style note (you’re clearly working from some very old CMakeLists.txt
files as examples)… the endif (<repeat_the_if_conditions>)
style is long deprecated. Just use endif ()
. Same thing for endforeach()
, endfunction()
, etc.
I’d recommend giving An Introduction to Modern CMake a read, and unlearning all of the bad old habits demonstrated by those ancient, ancient CMakeLists.txt
files.