summaryrefslogtreecommitdiffstats
path: root/CMakeLists.txt
blob: 8592b8c6a30cae0a8384094ac0ba0d92071ff4b3 (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
project(mcc)

cmake_minimum_required(VERSION 3.1)

if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE Debug)
endif()

set(CMAKE_C_FLAGS_DEBUG "-DDEBUG -g")
set(CMAKE_MACOSX_RPATH OFF)

set(mcc_VERSION_MAJOR 0)
set(mcc_VERSION_MINOR 1)

find_package(PkgConfig REQUIRED)
pkg_search_module(PKG_libevent REQUIRED IMPORTED_TARGET libevent)
pkg_search_module(PKG_json_c REQUIRED IMPORTED_TARGET json-c)

find_package(ZLIB)

add_subdirectory(subprojects/cNBT)
include_directories(subprojects)
include_directories("${PROJECT_BINARY_DIR}")

find_program(
  nbted
  nbted
)
add_custom_command(
  OUTPUT "${PROJECT_BINARY_DIR}/config.dat"
  COMMAND ${nbted} -r -i ${PROJECT_SOURCE_DIR}/data/config.nbted > ${PROJECT_BINARY_DIR}/config.dat
  DEPENDS "${PROJECT_SOURCE_DIR}/data/config.nbted"
)
add_custom_command(
  OUTPUT "${PROJECT_BINARY_DIR}/dimension_registry.dat"
  COMMAND ${nbted} -r -i ${PROJECT_SOURCE_DIR}/data/dimension_registry.nbted > ${PROJECT_BINARY_DIR}/dimension_registry.dat
  DEPENDS "${PROJECT_SOURCE_DIR}/data/dimension_registry.nbted"
)

if (NOT DEFINED mcc_RESOURCE_PATH)
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
  message(STATUS "building on macOS with ../Resource path")
  set(mcc_RESOURCE_PATH ../Resources)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  message(STATUS "building on linux with ./Resource path")
  set(mcc_RESOURCE_PATH ./Resources)
endif()
endif()

configure_file(
 "${PROJECT_SOURCE_DIR}/config.h.in"
 "${PROJECT_BINARY_DIR}/config.h"
)

add_executable(mcc
  main.c
  main.h
  socket.c
  socket.h
  protocol.c
  protocol.h
  parser.c
  parser.h
  package.c
  package.h
  world.c
  world.h
  ${PROJECT_SOURCE_DIR}/config.h.in

  
  # config source
  ${PROJECT_SOURCE_DIR}/data/config.nbted
  ${PROJECT_SOURCE_DIR}/data/dimension_registry.nbted
  
  # config
  ${PROJECT_BINARY_DIR}/config.dat
  ${PROJECT_BINARY_DIR}/dimension_registry.dat
)

set(RESOURCE_FILES
  ${PROJECT_BINARY_DIR}/config.dat
  ${PROJECT_BINARY_DIR}/dimension_registry.dat
)

if(NOT ${CMAKE_GENERATOR} STREQUAL "Xcode")
  message(STATUS "generator: Not Xcode")
  message(STATUS "set entitlements for mcc")
  set_target_properties(mcc PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS "${CMAKE_CURRENT_LIST_DIR}/mcc.entitlements")
endif()

set_target_properties(mcc PROPERTIES
    MACOSX_BUNDLE TRUE
    MACOSX_FRAMEWORK_IDENTIFIER dev.kloenk.mcc
    RESOURCE "${RESOURCE_FILES}"
)

#TARGET_LINK_LIBRARIES(mcc PkgConfig::PKG_json_c PkgConfig::PKG_libevent )
TARGET_LINK_LIBRARIES(mcc PkgConfig::PKG_json_c)
TARGET_LINK_LIBRARIES(mcc PkgConfig::PKG_libevent)
TARGET_LINK_LIBRARIES(mcc nbt)
TARGET_LINK_LIBRARIES(mcc ZLIB::ZLIB)

install(TARGETS mcc DESTINATION "${CMAKE_INSTALL_PREFIX}")