aboutsummaryrefslogtreecommitdiff
path: root/libs/lootcli/src/CMakeLists.txt
blob: fdc292e88bbee423074a7898609564ba98b2ecce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
cmake_minimum_required(VERSION 3.16)

# Qt is not required, this allows us to skip building the executable and only create
# the single-header interface when using this as a VCPKG dependency

find_package(Qt6 CONFIG COMPONENTS Core)

if (Qt6_FOUND)

message(STATUS "Qt6 found, building lootcli executable")

find_package(tomlplusplus CONFIG REQUIRED)
find_package(Boost REQUIRED CONFIG COMPONENTS locale)

# Try to find libloot via cmake config, then fall back to pkg-config
find_package(libloot CONFIG QUIET)
if(NOT libloot_FOUND)
  # On Linux with AUR package, libloot installs a .pc file
  find_package(PkgConfig)
  if(PkgConfig_FOUND)
    pkg_check_modules(LIBLOOT REQUIRED IMPORTED_TARGET libloot)
  endif()
endif()

if(TARGET libloot::loot)
  # avoid CMake error/warning
  set_target_properties(libloot::loot PROPERTIES
    MAP_IMPORTED_CONFIG_RELEASE RelWithDebInfo
    MAP_IMPORTED_CONFIG_MINSIZEREL RelWithDebInfo
  )
endif()

if(WIN32)
  add_executable(lootcli WIN32)
  set_target_properties(lootcli PROPERTIES
    CXX_STANDARD 20
    WIN32_EXECUTABLE TRUE)
else()
  add_executable(lootcli)
  set_target_properties(lootcli PROPERTIES
    CXX_STANDARD 20)
endif()

set(LOOTCLI_SOURCES
  game_settings.cpp
  game_settings.h
  lootthread.cpp
  lootthread.h
  main.cpp
  pch.h
  version.h
  ${CMAKE_CURRENT_SOURCE_DIR}/../include/lootcli/lootcli.h
)

if(WIN32)
  list(APPEND LOOTCLI_SOURCES version.rc)
endif()

target_sources(lootcli PRIVATE ${LOOTCLI_SOURCES})

if(WIN32)
  target_compile_definitions(lootcli
    PRIVATE
    _UNICODE UNICODE
    _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING)
endif()

target_include_directories(lootcli PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include)
target_precompile_headers(lootcli PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/pch.h)

# Link libraries
if(TARGET libloot::loot)
  target_link_libraries(lootcli PRIVATE libloot::loot)
elseif(TARGET PkgConfig::LIBLOOT)
  target_link_libraries(lootcli PRIVATE PkgConfig::LIBLOOT)
else()
  # Fallback: try to find the library manually
  find_library(LIBLOOT_LIBRARY NAMES loot libloot)
  find_path(LIBLOOT_INCLUDE_DIR NAMES loot/api.h)
  if(LIBLOOT_LIBRARY AND LIBLOOT_INCLUDE_DIR)
    target_link_libraries(lootcli PRIVATE ${LIBLOOT_LIBRARY})
    target_include_directories(lootcli PRIVATE ${LIBLOOT_INCLUDE_DIR})
  else()
    message(FATAL_ERROR "libloot not found. Install libloot or set CMAKE_PREFIX_PATH.")
  endif()
endif()

target_link_libraries(lootcli
    PRIVATE Boost::headers Boost::locale
    tomlplusplus::tomlplusplus Qt6::Core)

if(NOT WIN32)
  find_package(CURL REQUIRED)
  target_link_libraries(lootcli PRIVATE CURL::libcurl)
endif()

if (MSVC)
  target_compile_options(lootcli
    PRIVATE
    "/MP"
    "/W4"
    "/external:anglebrackets"
    "/external:W0"
  )
  target_link_options(lootcli
    PRIVATE
    $<$<CONFIG:RelWithDebInfo>:/LTCG /INCREMENTAL:NO /OPT:REF /OPT:ICF>
  )
  target_compile_definitions(lootcli PRIVATE _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING)

  set_target_properties(lootcli PROPERTIES VS_STARTUP_PROJECT lootcli)
endif()

if(WIN32)
  install(FILES
    $<TARGET_FILE:lootcli>
    $<TARGET_FILE:libloot::loot>
  DESTINATION bin/loot)
else()
  install(TARGETS lootcli DESTINATION bin/loot)
endif()

endif()

# library to make the header available
add_library(lootcli-header INTERFACE)
target_sources(lootcli-header INTERFACE
  FILE_SET HEADERS
  BASE_DIRS ${CMAKE_CURRENT_LIST_DIR}/../include
  FILES ${CMAKE_CURRENT_LIST_DIR}/../include/lootcli/lootcli.h)
add_library(mo2::lootcli-header ALIAS lootcli-header)

install(TARGETS lootcli-header EXPORT lootcliHeaderTargets FILE_SET HEADERS)
install(EXPORT lootcliHeaderTargets
  FILE mo2-lootcli-header-targets.cmake
  NAMESPACE mo2::
  DESTINATION lib/cmake/mo2-lootcli-header
)