2020-08-20 21:21:43 +00:00
cmake_minimum_required ( VERSION 3.13 )
2020-08-20 19:59:54 +00:00
project ( OpenFusion )
set ( CMAKE_CXX_STANDARD 17 )
2020-09-16 18:12:12 +00:00
execute_process ( COMMAND git describe --tags OUTPUT_VARIABLE GIT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE )
2020-08-21 05:18:19 +00:00
# OpenFusion supports multiple packet/struct versions
2020-08-21 17:38:45 +00:00
# 104 is the default version to build which can be changed
# For example: cmake -B build -DPROTOCOL_VERSION=728
set ( PROTOCOL_VERSION 104 CACHE STRING "The packet version to build" )
2020-08-21 05:18:19 +00:00
2020-08-21 17:38:45 +00:00
add_compile_definitions ( PROTOCOL_VERSION= ${ PROTOCOL_VERSION } )
2020-08-21 05:18:19 +00:00
2020-08-20 19:59:54 +00:00
# Disallow in-source builds
if ( ${ CMAKE_SOURCE_DIR } STREQUAL ${ CMAKE_BINARY_DIR } )
message ( FATAL_ERROR "In-source builds not allowed. Please refer to the wiki for more information. Please remove the CMakeFiles folder and the CMakeCache.txt file." )
endif ( )
# Output binaries to the bin folder in the source directory
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ CMAKE_SOURCE_DIR } /bin )
# Put CMake targets (ALL_BUILD/ZERO_CHECK) into a folder
set_property ( GLOBAL PROPERTY USE_FOLDERS ON )
# Set the OpenFusion project as the default startup project for VS
set_property ( DIRECTORY ${ CMAKE_CURRENT_SOURCE_DIR } PROPERTY VS_STARTUP_PROJECT openfusion )
2020-08-20 21:47:27 +00:00
if ( WIN32 )
# Set the output binary name to winfusion to match the regular Makefile
set ( BIN_NAME winfusion )
else ( )
set ( BIN_NAME fusion )
endif ( )
2021-03-12 17:50:21 +00:00
include_directories ( src vendor )
2020-08-20 19:59:54 +00:00
2021-03-12 17:50:21 +00:00
file ( GLOB_RECURSE SOURCES src/**.[ch]pp vendor/**.[ch]pp vendor/**.[ch] version.h )
2020-09-16 18:12:12 +00:00
configure_file ( version.h.in ${ CMAKE_SOURCE_DIR } /version.h @ONLY )
2020-08-20 19:59:54 +00:00
add_executable ( openfusion ${ SOURCES } )
2020-08-20 21:47:27 +00:00
set_target_properties ( openfusion PROPERTIES OUTPUT_NAME ${ BIN_NAME } )
2022-04-05 00:38:05 +00:00
# find sqlite3 and use it
2023-07-11 16:29:08 +00:00
find_package ( SQLite3 REQUIRED )
2022-04-05 00:38:05 +00:00
target_include_directories ( openfusion PRIVATE ${ SQLite3_INCLUDE_DIRS } )
target_link_libraries ( openfusion PRIVATE ${ SQLite3_LIBRARIES } )
2020-12-14 02:42:11 +00:00
2021-04-20 22:17:24 +00:00
# Makes it so config, tdata, etc. get picked up when starting via the debugger in VS
set_property ( TARGET openfusion PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" )
2020-08-20 21:47:27 +00:00
# Use pthreads if not generating a VS solution or MinGW makefile (because MinGW will prefer Win32 threads)
2020-08-20 22:44:30 +00:00
# Checking if the compiler ID is MSVC will allow us to open the project as a CMake project in VS.
# It's not something you should do, but it's there if you need it...
if ( NOT CMAKE_GENERATOR MATCHES "Visual Studio" AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND NOT CMAKE_GENERATOR MATCHES "MinGW Makefiles" )
2020-08-20 21:47:27 +00:00
find_package ( Threads REQUIRED )
2023-07-11 16:29:08 +00:00
target_link_libraries ( openfusion PRIVATE pthread )
2020-08-21 05:18:19 +00:00
endif ( )