Correcting CMake rules to handle distinct Linux/Windows/Darwin implementations

This commit is contained in:
Dmitry Mikushin
2021-11-09 18:08:40 +01:00
parent fab1f4990a
commit 330d413445
2 changed files with 13 additions and 34 deletions

View File

@@ -21,37 +21,39 @@ add_library(tray_base INTERFACE)
target_compile_features(tray_base INTERFACE c_std_99) target_compile_features(tray_base INTERFACE c_std_99)
file(GLOB src
${CMAKE_CURRENT_LIST_DIR}/*.h
${CMAKE_CURRENT_LIST_DIR}/*.ico
${CMAKE_CURRENT_LIST_DIR}/*.png)
if(WIN32) if(WIN32)
include(WinApiLevels) include(WinApiLevels)
add_compile_definitions(TRAY_WINAPI=1) add_compile_definitions(TRAY_WINAPI=1)
list(APPEND src ${CMAKE_CURRENT_SOURCE_DIR}/tray_windows.c)
else() else()
add_library(tray INTERFACE)
target_link_libraries(tray INTERFACE tray_base)
if(UNIX) if(UNIX)
if(APPLE) if(APPLE)
add_compile_definitions(TRAY_APPKIT=1) add_compile_definitions(TRAY_APPKIT=1)
find_library(COCOA Cocoa REQUIRED) find_library(COCOA Cocoa REQUIRED)
list(APPEND src ${CMAKE_CURRENT_SOURCE_DIR}/tray_darwin.m)
else() else()
FIND_PACKAGE(PkgConfig) FIND_PACKAGE(PkgConfig)
PKG_CHECK_MODULES(APPINDICATOR REQUIRED appindicator3-0.1) PKG_CHECK_MODULES(APPINDICATOR REQUIRED appindicator3-0.1)
ADD_DEFINITIONS(${APPINDICATOR_CFLAGS}) ADD_DEFINITIONS(${APPINDICATOR_CFLAGS})
LINK_DIRECTORIES(${APPINDICATOR_LIBRARY_DIRS}) LINK_DIRECTORIES(${APPINDICATOR_LIBRARY_DIRS})
add_compile_definitions(TRAY_APPINDICATOR=1) add_compile_definitions(TRAY_APPINDICATOR=1)
list(APPEND src ${CMAKE_CURRENT_SOURCE_DIR}/tray_windows.c)
endif() endif()
endif() endif()
endif() endif()
add_library(tray STATIC ${src})
target_link_libraries(tray INTERFACE tray_base)
add_library(tray::tray ALIAS tray) add_library(tray::tray ALIAS tray)
file(GLOB src add_executable(tray_example ${CMAKE_CURRENT_SOURCE_DIR}/example.c)
${CMAKE_CURRENT_LIST_DIR}/*.c target_link_libraries(tray_example tray::tray)
${CMAKE_CURRENT_LIST_DIR}/*.h
${CMAKE_CURRENT_LIST_DIR}/*.ico
${CMAKE_CURRENT_LIST_DIR}/*.png)
add_executable(tray_example ${src})
target_link_libraries(tray_example tray)
configure_file(${CMAKE_CURRENT_LIST_DIR}/icon.ico ${CMAKE_BINARY_DIR}/icon.ico COPYONLY) configure_file(${CMAKE_CURRENT_LIST_DIR}/icon.ico ${CMAKE_BINARY_DIR}/icon.ico COPYONLY)
configure_file(${CMAKE_CURRENT_LIST_DIR}/icon.png ${CMAKE_BINARY_DIR}/icon.png COPYONLY) configure_file(${CMAKE_CURRENT_LIST_DIR}/icon.png ${CMAKE_BINARY_DIR}/icon.png COPYONLY)

View File

@@ -1,23 +0,0 @@
ifeq ($(OS),Windows_NT)
TRAY_CFLAGS := -DTRAY_WINAPI=1
TRAY_LDFLAGS :=
else ifeq ($(shell uname -s),Linux)
TRAY_CFLAGS := -DTRAY_APPINDICATOR=1 $(shell pkg-config --cflags appindicator3-0.1)
TRAY_LDFLAGS := $(shell pkg-config --libs appindicator3-0.1)
else ifeq ($(shell uname -s),Darwin)
TRAY_CFLAGS := -DTRAY_APPKIT=1
TRAY_LDFLAGS := -framework Cocoa
endif
CFLAGS := -g -Wall $(TRAY_CFLAGS) -Wall -Wextra -std=c99 -pedantic
LDFLAGS := -g $(TRAY_LDFLAGS)
all: example
example: example.o
$(CC) $^ $(LDFLAGS) -o $@
example.o: example.c tray.h
clean:
rm -f example.o example example.exe