Search code examples
cmakevala

Compile Vala project with CMake


I want to compile a Vala project that relies on libappindicator with CMake.

However, make aborts with this output:

Linking C executable calm
CMakeFiles/calm.dir/src/CalmWindow.c.o: In function `__lambda6_':
CalmWindow.c:(.text+0x5b8): undefined reference to `app_indicator_set_status'
CMakeFiles/calm.dir/src/CalmWindow.c.o: In function `calm_calm_indicator_construct':
CalmWindow.c:(.text+0x6ee): undefined reference to `app_indicator_new'
CalmWindow.c:(.text+0x746): undefined reference to `app_indicator_set_status'
CalmWindow.c:(.text+0x76c): undefined reference to `app_indicator_set_attention_icon'
CalmWindow.c:(.text+0xe87): undefined reference to `app_indicator_set_menu'
collect2: ld gab 1 als Ende-Status zurück
make[2]: *** [calm] Fehler 1
make[1]: *** [CMakeFiles/calm.dir/all] Fehler 2
make: *** [all] Fehler 2

Is something wrong with my CMakeLists.txt?

This command works:

valac -g --pkg gtk+-3.0 --pkg gstreamer-0.10 --pkg gstreamer-audio-0.10 --pkg granite --pkg appindicator3-0.1 CalmApp.vala Calm.vala CalmWindow.vala

Solution

  • That way it works:

    [...]
    ###########
    set(COMPILE_OPTIONS_VALA ${COMPILE_OPTIONS_VALA} -D USE_APPINDICATOR)
    set(PACKAGES_VALA ${PACKAGES_VALA} "appindicator3-0.1")
    ###########
    
    include(ValaPrecompile)
    vala_precompile(VALA_C
            src/Calm.vala
            src/CalmApp.vala
            src/CalmWindow.vala
    PACKAGES
            gtk+-3.0
            gstreamer-0.10
            gstreamer-audio-0.10
            appindicator3-0.1
    CUSTOM_VAPIS
            vapi/config.vapi
    OPTIONS
            --thread
    )
    [...]