Skip to content

Commit

Permalink
Use target_sources & target_compile_definitions in CMake file
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Mar 5, 2024
1 parent db48e04 commit 835cd0f
Showing 1 changed file with 32 additions and 52 deletions.
84 changes: 32 additions & 52 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,89 +21,69 @@ if(UNIX AND NOT APPLE)
option(CLIP_X11_WITH_PNG "Compile with libpng to support copy/paste image in png format" on)
endif()

set(CLIP_SOURCES clip.cpp)
add_library(clip clip.cpp)

if(CLIP_ENABLE_IMAGE)
list(APPEND CLIP_SOURCES image.cpp)
target_sources(clip PRIVATE image.cpp)
target_compile_definitions(clip PUBLIC -DCLIP_ENABLE_IMAGE=1)
endif()

if(WIN32)
option(CLIP_SUPPORT_WINXP "Enable Windows XP support" OFF)

target_sources(clip PRIVATE clip_win.cpp)
if(MSVC)
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
target_compile_definitions(clip PRIVATE -D_SCL_SECURE_NO_WARNINGS)
endif()
if (CLIP_SUPPORT_WINXP)
target_compile_definitions(clip PRIVATE -DCLIP_SUPPORT_WINXP)
endif()
target_link_libraries(clip shlwapi)

# MinGW requires the windowscodecs just because CLSIDs are defined
# in the windowscodecs.a file instead of the wincodec.h file (?!)
if(MINGW)
find_library(CLIP_WINDOWSCODECS_LIBRARY windowscodecs)
if(CLIP_WINDOWSCODECS_LIBRARY)
target_link_libraries(clip ${CLIP_WINDOWSCODECS_LIBRARY})
endif()
endif()
list(APPEND CLIP_SOURCES clip_win.cpp)
elseif(APPLE)
add_definitions(-fobjc-arc)
target_link_options(clip PRIVATE -fobjc-arc)

find_library(COCOA_LIBRARY Cocoa)
if(COCOA_LIBRARY)
list(APPEND CLIP_SOURCES clip_osx.mm)
target_sources(clip PRIVATE clip_osx.mm)
target_link_libraries(clip ${COCOA_LIBRARY})
else()
list(APPEND CLIP_SOURCES clip_none.cpp)
target_sources(clip PRIVATE clip_none.cpp)
endif()
elseif(UNIX)
include(CheckIncludeFiles)
check_include_files(xcb/xcb.h HAVE_XCB_XLIB_H)

if(HAVE_XCB_XLIB_H)
add_definitions(-DHAVE_XCB_XLIB_H)
target_compile_definitions(clip PRIVATE -DHAVE_XCB_XLIB_H)
target_link_libraries(clip xcb pthread)

if(CLIP_X11_WITH_PNG)
if(CLIP_ENABLE_IMAGE AND CLIP_X11_WITH_PNG)
check_include_files(png.h HAVE_PNG_H)
if(CLIP_X11_PNG_LIBRARY)
set(PNG_LIBRARY ${CLIP_X11_PNG_LIBRARY})
else()
find_library(PNG_LIBRARY png)
endif()
if(HAVE_PNG_H AND PNG_LIBRARY)
add_definitions(-DHAVE_PNG_H)
target_compile_definitions(clip PRIVATE -DHAVE_PNG_H)
endif()
target_link_libraries(clip ${PNG_LIBRARY})
endif()

list(APPEND CLIP_SOURCES clip_x11.cpp)
target_sources(clip PRIVATE clip_x11.cpp)
else()
list(APPEND CLIP_SOURCES clip_none.cpp)
target_sources(clip PRIVATE clip_none.cpp)
endif()
else()
list(APPEND CLIP_SOURCES clip_none.cpp)
endif()

add_library(clip ${CLIP_SOURCES})

if(CLIP_ENABLE_IMAGE)
target_compile_definitions(clip PUBLIC
-DCLIP_ENABLE_IMAGE=1)
endif()

if(WIN32)
option(CLIP_SUPPORT_WINXP "Enable Windows XP support" OFF)
if (CLIP_SUPPORT_WINXP)
add_definitions(-DCLIP_SUPPORT_WINXP)
endif()
target_link_libraries(clip shlwapi)

# MinGW requires the windowscodecs just because CLSIDs are defined
# in the windowscodecs.a file instead of the wincodec.h file (?!)
if(MINGW)
find_library(CLIP_WINDOWSCODECS_LIBRARY windowscodecs)
if(CLIP_WINDOWSCODECS_LIBRARY)
target_link_libraries(clip ${CLIP_WINDOWSCODECS_LIBRARY})
endif()
endif()
elseif(APPLE)
if(COCOA_LIBRARY)
target_link_libraries(clip ${COCOA_LIBRARY})
endif()
elseif(UNIX)
if(HAVE_XCB_XLIB_H)
target_link_libraries(clip xcb pthread)
if(CLIP_ENABLE_IMAGE AND
CLIP_X11_WITH_PNG AND
HAVE_PNG_H AND
PNG_LIBRARY)
target_link_libraries(clip ${PNG_LIBRARY})
endif()
endif()
target_sources(clip PRIVATE clip_none.cpp)
endif()

if(CLIP_EXAMPLES)
Expand Down

0 comments on commit 835cd0f

Please sign in to comment.