Jump to content

[patch/dev] CMake for MaNGOS.


Recommended Posts

First I've to mention there was already a cmake try: http://getmangos.eu/community/viewtopic.php?id=5024

even if it was really oversimplified :)

Second: it took me a good amount of time to apply it on my windows-system. Maybe it would be much easier if you set up a git-clone.

and most important: doesn't work on windows

  • * mysql path should be "dep/include/mysql" and "dep/lib/xxxx" (findmysql.cmake line 63/64)
    * same for SSLib and ZLIB .. looks like the test of these are missing
    * also for ace..but ace should be a sub-project and so doesn't requires a 'find' in this way
    * some cmakefiles are missing / must be removed:

  • * dep/src/cmakelists.txt
    * src/bindings/cmakelists.txt
    * src/shared/database/cmakelists.txt

since I run out-of-time I stopped testing at this point.

suggestions:

  • * rename options to something like "MANGOS_USE_MYSQL" 'cause newer cmake gui's support name grouping.
    * "LARGE_CELL" and "SHORT_SLEEP" aren't options of mangos..as fas as I know.
    * On a first gaze the main cmakelists.txt looks messed up and unprofessional. I would prefer a rework but some comments and tabs could also do it :)
Link to comment
Share on other sites

  • 40 years later...

CMake is a fantastic cross-platform build tool, which allows to unify build scripts like Unix Makefiles and Visual Studio project files into one easily script-able format which then can be used to build an application on many more platforms.

Think of CMake as... generic build definitions convertible to anything what people use these days.

Link to comment
Share on other sites

Let me add a few hints to get this working:

  • * Comments, comments, comments. CMake is great, but you should comment what each section does.
    * CMake allows you to add custom modules for a build. This is recommended, for all external libraries, including MySQL, OpenSSL, etc.
    * Make proper use of platform detection, and add file groupings for the Windows users. File groups allow to create the header and source folder for Visual Studio users.

As for modules: add a cmake/modules subdirectory, place your FindXXX.cmake modules there.

In you main CMakeLists.txt add

set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)

Below is an example of how a FindXXX.cmake module should be written.

# - Try to find MySQL / MySQL Embedded library
# Find the MySQL includes and client library
# This module defines
#  MYSQL_INCLUDE_DIR, where to find mysql.h
#  MYSQL_LIBRARIES, the libraries needed to use MySQL.
#  MYSQL_LIB_DIR, path to the MYSQL_LIBRARIES
#  MYSQL_EMBEDDED_LIBRARIES, the libraries needed to use MySQL Embedded.
#  MYSQL_EMBEDDED_LIB_DIR, path to the MYSQL_EMBEDDED_LIBRARIES
#  MYSQL_FOUND, If false, do not try to use MySQL.
#  MYSQL_EMBEDDED_FOUND, If false, do not try to use MySQL Embedded.

# Copyright (c) 2006-2008, Jarosław Staniek <[email protected]>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

include(CheckCXXSourceCompiles)
include(MacroPushRequiredVars)

if(WIN32)
  find_path(MYSQL_INCLUDE_DIR mysql.h
     PATHS
     $ENV{MYSQL_INCLUDE_DIR}
     $ENV{MYSQL_DIR}/include
     $ENV{ProgramFiles}/MySQL/*/include
     $ENV{SystemDrive}/MySQL/*/include
  )
else(WIN32)
  find_path(MYSQL_INCLUDE_DIR mysql.h
     PATHS
     $ENV{MYSQL_INCLUDE_DIR}
     $ENV{MYSQL_DIR}/include
     /usr/local/mysql/include
     /opt/mysql/mysql/include
     PATH_SUFFIXES
     mysql
  )
endif(WIN32)

if(WIN32)
  string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_TOLOWER)

  # path suffix for debug/release mode
  # binary_dist: mysql binary distribution
  # build_dist: custom build
  if(CMAKE_BUILD_TYPE_TOLOWER MATCHES "debug")
     set(binary_dist debug)
     set(build_dist Debug)
  else(CMAKE_BUILD_TYPE_TOLOWER MATCHES "debug")
     ADD_DEFINITIONS(-DDBUG_OFF)
     set(binary_dist opt)
     set(build_dist Release)
  endif(CMAKE_BUILD_TYPE_TOLOWER MATCHES "debug")

#   find_library(MYSQL_LIBRARIES NAMES mysqlclient
  find_library(MYSQL_LIBRARIES NAMES libmysql
     PATHS
     $ENV{MYSQL_DIR}/lib/${binary_dist}
     $ENV{MYSQL_DIR}/libmysql/${build_dist}
     $ENV{MYSQL_DIR}/client/${build_dist}
     $ENV{ProgramFiles}/MySQL/*/lib/${binary_dist}
     $ENV{SystemDrive}/MySQL/*/lib/${binary_dist}
  )
else(WIN32)
#   find_library(MYSQL_LIBRARIES NAMES mysqlclient
  find_library(MYSQL_LIBRARIES NAMES libmysql
     PATHS
     $ENV{MYSQL_DIR}/libmysql_r/.libs
     $ENV{MYSQL_DIR}/lib
     $ENV{MYSQL_DIR}/lib/mysql
     /usr/local/mysql/lib
     /opt/mysql/mysql/lib
     PATH_SUFFIXES 
     mysql
  )
endif(WIN32)

if(WIN32)
  set(MYSQL_LIB_PATHS
     $ENV{MYSQL_DIR}/lib/opt
     $ENV{MYSQL_DIR}/client/release
     $ENV{ProgramFiles}/MySQL/*/lib/opt
     $ENV{SystemDrive}/MySQL/*/lib/opt
  )
  find_library(MYSQL_LIBRARIES NAMES mysqlclient
     PATHS
     ${MYSQL_LIB_PATHS}
  )
else(WIN32)
  set(MYSQL_LIB_PATHS
     $ENV{MYSQL_DIR}/libmysql_r/.libs
     $ENV{MYSQL_DIR}/lib
     $ENV{MYSQL_DIR}/lib/mysql
     /usr/local/mysql/lib
     /opt/mysql/mysql/lib
     PATH_SUFFIXES
     mysql
  )
  find_library(MYSQL_LIBRARIES NAMES mysqlclient
     PATHS
     ${MYSQL_LIB_PATHS}
  )
endif(WIN32)

find_library(MYSQL_EMBEDDED_LIBRARIES NAMES mysqld
  PATHS
  ${MYSQL_LIB_PATHS}
)

if(MYSQL_LIBRARIES)
  get_filename_component(MYSQL_LIB_DIR ${MYSQL_LIBRARIES} PATH)
endif(MYSQL_LIBRARIES)

if(MYSQL_EMBEDDED_LIBRARIES)
  get_filename_component(MYSQL_EMBEDDED_LIB_DIR ${MYSQL_EMBEDDED_LIBRARIES} PATH)
endif(MYSQL_EMBEDDED_LIBRARIES)

macro_push_required_vars()
set( CMAKE_REQUIRED_INCLUDES ${MYSQL_INCLUDE_DIR} )
set( CMAKE_REQUIRED_LIBRARIES ${MYSQL_EMBEDDED_LIBRARIES} )
check_cxx_source_compiles( "#include <mysql.h>\\nint main() { int i = MYSQL_OPT_USE_EMBEDDED_CONNECTION; }" HAVE_MYSQL_OPT_EMBEDDED_CONNECTION )
macro_pop_required_vars()

if(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES)
  set(MYSQL_FOUND TRUE)
  message(STATUS "Found MySQL: ${MYSQL_INCLUDE_DIR}, ${MYSQL_LIBRARIES}")
else(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES)
  set(MYSQL_FOUND FALSE)
  message(STATUS "MySQL not found.")
endif(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES)

if(MYSQL_INCLUDE_DIR AND MYSQL_EMBEDDED_LIBRARIES AND HAVE_MYSQL_OPT_EMBEDDED_CONNECTION)
  set(MYSQL_EMBEDDED_FOUND TRUE)
  message(STATUS "Found MySQL Embedded: ${MYSQL_INCLUDE_DIR}, ${MYSQL_EMBEDDED_LIBRARIES}")
else(MYSQL_INCLUDE_DIR AND MYSQL_EMBEDDED_LIBRARIES AND HAVE_MYSQL_OPT_EMBEDDED_CONNECTION)
  set(MYSQL_EMBEDDED_FOUND FALSE)
  message(STATUS "MySQL Embedded not found.")
endif(MYSQL_INCLUDE_DIR AND MYSQL_EMBEDDED_LIBRARIES AND HAVE_MYSQL_OPT_EMBEDDED_CONNECTION)

mark_as_advanced(MYSQL_INCLUDE_DIR MYSQL_LIBRARIES MYSQL_EMBEDDED_LIBRARIES)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use