CMakeLists.txt
1 include_directories(${PROJECT_SOURCE_DIR}/include) 2 3 option(ENABLE_IO_THREAD "Start up a separate I/O thread, otherwise I'd need to call an update function" ON) 4 option(USE_STATIC_CRT "Use /MT[d] for dynamic library" OFF) 5 option(WARNINGS_AS_ERRORS "When enabled, compiles with `-Werror` (on *nix platforms)." OFF) 6 7 set(CMAKE_CXX_STANDARD 14) 8 9 set(BASE_RPC_SRC 10 ${PROJECT_SOURCE_DIR}/include/discord_rpc.h 11 discord_rpc.cpp 12 ${PROJECT_SOURCE_DIR}/include/discord_register.h 13 rpc_connection.h 14 rpc_connection.cpp 15 serialization.h 16 serialization.cpp 17 connection.h 18 backoff.h 19 msg_queue.h 20 ) 21 22 if (${BUILD_SHARED_LIBS}) 23 if(WIN32) 24 set(BASE_RPC_SRC ${BASE_RPC_SRC} dllmain.cpp) 25 endif(WIN32) 26 endif(${BUILD_SHARED_LIBS}) 27 28 if(WIN32) 29 add_definitions(-DDISCORD_WINDOWS) 30 set(BASE_RPC_SRC ${BASE_RPC_SRC} connection_win.cpp discord_register_win.cpp) 31 add_library(discord-rpc ${BASE_RPC_SRC}) 32 if (MSVC) 33 if(USE_STATIC_CRT) 34 foreach(CompilerFlag 35 CMAKE_CXX_FLAGS 36 CMAKE_CXX_FLAGS_DEBUG 37 CMAKE_CXX_FLAGS_RELEASE 38 CMAKE_C_FLAGS 39 CMAKE_C_FLAGS_DEBUG 40 CMAKE_C_FLAGS_RELEASE) 41 string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") 42 endforeach() 43 endif(USE_STATIC_CRT) 44 target_compile_options(discord-rpc PRIVATE /EHsc 45 /Wall 46 /wd4100 # unreferenced formal parameter 47 /wd4514 # unreferenced inline 48 /wd4625 # copy constructor deleted 49 /wd5026 # move constructor deleted 50 /wd4626 # move assignment operator deleted 51 /wd4668 # not defined preprocessor macro 52 /wd4710 # function not inlined 53 /wd4711 # function was inlined 54 /wd4820 # structure padding 55 /wd4946 # reinterpret_cast used between related classes 56 /wd5027 # move assignment operator was implicitly defined as deleted 57 ) 58 endif(MSVC) 59 target_link_libraries(discord-rpc PRIVATE psapi advapi32) 60 endif(WIN32) 61 62 if(UNIX) 63 set(BASE_RPC_SRC ${BASE_RPC_SRC} connection_unix.cpp) 64 65 if (APPLE) 66 add_definitions(-DDISCORD_OSX) 67 set(BASE_RPC_SRC ${BASE_RPC_SRC} discord_register_osx.m) 68 else (APPLE) 69 add_definitions(-DDISCORD_LINUX) 70 set(BASE_RPC_SRC ${BASE_RPC_SRC} discord_register_linux.cpp) 71 endif(APPLE) 72 73 add_library(discord-rpc ${BASE_RPC_SRC}) 74 target_link_libraries(discord-rpc PUBLIC pthread) 75 76 if (APPLE) 77 target_link_libraries(discord-rpc PRIVATE "-framework AppKit, -mmacosx-version-min=10.10") 78 endif (APPLE) 79 80 target_compile_options(discord-rpc PRIVATE 81 -g 82 -Wall 83 -Wextra 84 -Wpedantic 85 ) 86 87 if (${WARNINGS_AS_ERRORS}) 88 target_compile_options(discord-rpc PRIVATE -Werror) 89 endif (${WARNINGS_AS_ERRORS}) 90 91 target_compile_options(discord-rpc PRIVATE 92 -Wno-unknown-pragmas # pragma push thing doesn't work on clang 93 -Wno-old-style-cast # it's fine 94 -Wno-c++98-compat # that was almost 2 decades ago 95 -Wno-c++98-compat-pedantic 96 -Wno-missing-noreturn 97 -Wno-padded # structure padding 98 -Wno-covered-switch-default 99 -Wno-exit-time-destructors # not sure about these 100 -Wno-global-constructors 101 ) 102 103 if (${BUILD_SHARED_LIBS}) 104 target_compile_options(discord-rpc PRIVATE -fPIC) 105 endif (${BUILD_SHARED_LIBS}) 106 107 if (APPLE) 108 target_link_libraries(discord-rpc PRIVATE "-framework AppKit") 109 endif (APPLE) 110 endif(UNIX) 111 112 target_include_directories(discord-rpc PRIVATE ${RAPIDJSON}/include) 113 114 if (NOT ${ENABLE_IO_THREAD}) 115 target_compile_definitions(discord-rpc PUBLIC -DDISCORD_DISABLE_IO_THREAD) 116 endif (NOT ${ENABLE_IO_THREAD}) 117 118 if (${BUILD_SHARED_LIBS}) 119 target_compile_definitions(discord-rpc PUBLIC -DDISCORD_DYNAMIC_LIB) 120 target_compile_definitions(discord-rpc PRIVATE -DDISCORD_BUILDING_SDK) 121 endif(${BUILD_SHARED_LIBS}) 122 123 if (CLANG_FORMAT_CMD) 124 add_dependencies(discord-rpc clangformat) 125 endif(CLANG_FORMAT_CMD) 126 127 # install 128 129 install( 130 TARGETS discord-rpc 131 EXPORT "discord-rpc" 132 RUNTIME 133 DESTINATION "${CMAKE_INSTALL_BINDIR}" 134 LIBRARY 135 DESTINATION "${CMAKE_INSTALL_LIBDIR}" 136 ARCHIVE 137 DESTINATION "${CMAKE_INSTALL_LIBDIR}" 138 INCLUDES 139 DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" 140 ) 141 142 install( 143 FILES 144 "../include/discord_rpc.h" 145 "../include/discord_register.h" 146 DESTINATION "include" 147 )