cmake_minimum_required(VERSION 3.13) include(CheckIPOSupported) project(pkmnLib) # We like new stuff, so set the c++ standard to c++20. set(CMAKE_CXX_STANDARD 20) set(CMAKE_POSITION_INDEPENDENT_CODE ON) option(WINDOWS "Whether the build target is Windows or not." OFF) option(SHARED "Whether we should build a shared library, instead of a static one." ON) option(TESTS "Whether the test executable should be build as well." OFF) option(STATICC "Whether gcc and stdc++ should be linked statically to the library." OFF) set(SCRIPT_PROVIDER "angelscript" CACHE STRING "Which script provider to use.") set(LEVEL_SIZE "8" CACHE STRING "Number of bits to store the level as. Can be 8") include(CMakeLists.txt.creaturelib.in) include(CMakeLists.txt.angelscript.in) include_creaturelib() include_angelscript() if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") add_compile_options(-fconcepts) endif () if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") add_link_options(-fuse-ld=lld) endif () if (WINDOWS) SET(CMAKE_SYSTEM_NAME Windows) ADD_DEFINITIONS(-D WINDOWS=1) endif (WINDOWS) if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # The angelscript libraries break these warnings extensively. Turn them off. add_compile_options(-Wno-error=cast-function-type -Wno-cast-function-type) add_compile_options(-Wno-error=type-limits -Wno-type-limits) endif () message(STATUS "Using: \t C ${CMAKE_C_COMPILER} \t C++ ${CMAKE_CXX_COMPILER} \t CXX ABI ${CMAKE_CXX_COMPILER_ABI} \t C++ Version ${CMAKE_CXX_STANDARD}") if (LEVEL_SIZE STREQUAL "8") add_definitions(-DLEVEL_U8) message(STATUS "Using level size of 8") elseif (LEVEL_SIZE STREQUAL "16") add_definitions(-DLEVEL_U16) message(STATUS "Using level size of 16") elseif (LEVEL_SIZE STREQUAL "32") add_definitions(-DLEVEL_U32) message(STATUS "Using level size of 32") elseif (LEVEL_SIZE STREQUAL "64") add_definitions(-DLEVEL_U64) message(STATUS "Using level size of 64") else () message(FATAL_ERROR, "Invalid level size was given.") endif () if (CMAKE_BUILD_TYPE MATCHES Release AND NOT WINDOWS) # Include debug symbols in all linux builds message("Including debug symbols") add_compile_options(-g -gline-tables-only) endif () # Set whether we want a static or shared library. set(LIBTYPE STATIC) if (SHARED) set(LIBTYPE SHARED) endif (SHARED) SET(FILE_SOURCE "src/Battling/*.cpp" "src/Battling/*.hpp" "src/Library/*.cpp" "src/Library/*.hpp" "CInterface/Core.*" "CInterface/Library/*.cpp" "CInterface/Library/*.hpp" "CInterface/Battling/*.cpp" "CInterface/Battling/*.hpp" ) if (SCRIPT_PROVIDER STREQUAL "angelscript") SET(FILE_SOURCE ${FILE_SOURCE} "src/ScriptResolving/AngelScript/*.cpp" "src/ScriptResolving/AngelScript/*.hpp" "extern/angelscript_addons/*.cpp" "extern/angelscript_addons/*.h" "CInterface/AngelScript/*.cpp" "CInterface/AngelScript/*.hpp" "extern/AngelscriptDebuggerServer/src/*.cpp" ) ADD_DEFINITIONS(-D AS_USE_ACCESSORS=1) endif () file(GLOB_RECURSE CORE_SRC_FILES ${FILE_SOURCE}) add_library(pkmnLib ${LIBTYPE} ${CORE_SRC_FILES}) target_precompile_headers(pkmnLib PUBLIC src/Precompiled.hxx) # Enable all warnings, and make them error when occurring. target_compile_options(pkmnLib PRIVATE -Wall -Wextra -Werror) # If interprocedural optimization is available, apply it check_ipo_supported(RESULT IPO_SUPPORTED) if (IPO_SUPPORTED) message(STATUS "IPO / LTO enabled") set_property(TARGET pkmnLib PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) endif () SET(_LINKS CreatureLib Arbutils) SET(_TESTLINKS pkmnLib CreatureLib Arbutils) if (SCRIPT_PROVIDER STREQUAL "angelscript") message(STATUS "Using Angelscript as script provider.") ADD_DEFINITIONS(-D ANGELSCRIPT=1) SET(_LINKS ${_LINKS} angelscript) SET(_TESTLINKS ${_TESTLINKS} angelscript) endif () # If we are building for Windows we need to set some specific variables. if (WINDOWS) MESSAGE(WARNING, "Using Windows Build.") # Add a definition for the compiler, so we can use it in C++ as well. ADD_DEFINITIONS(-D WINDOWS=1) # -m64: Build a 64 bit library add_compile_options(-m64) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-allow-multiple-definition") if (SHARED) set_target_properties(pkmnLib PROPERTIES SUFFIX ".dll") endif (SHARED) endif (WINDOWS) if (NOT WINDOWS) set(_LINKS -lbfd -ldl ${_LINKS}) endif () if (STATICC) set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed") message(STATUS "Linking C library statically") set(_LINKS ${_LINKS} -Wl,-Bstatic -lm -lgcc -lstdc++ -Wl,-Bdynamic) SET(_TESTLINKS ${_TESTLINKS} -Wl,-Bstatic -lm -lgcc -lstdc++ -Wl,-Bdynamic) else () SET(_LINKS ${_LINKS} -Wl,--whole-archive -lpthread -Wl,--no-whole-archive) endif () target_link_libraries(pkmnLib PRIVATE ${_LINKS}) if (TESTS) # Create Test executable file(GLOB_RECURSE TEST_FILES "tests/*.cpp" "tests/*.hpp") add_executable(pkmnLibTests ${TEST_FILES} extern/doctest.hpp) # Enable all warnings, and make them error when occurring. target_compile_options(pkmnLibTests PRIVATE -Wall -Wextra -Werror) message(STATUS "${_TESTLINKS}") target_link_libraries(pkmnLibTests PUBLIC ${_TESTLINKS}) # Add a definition for the test library target_compile_definitions(pkmnLibTests PRIVATE TESTS_BUILD) endif () include_directories(extern/AngelscriptDebuggerServer/extern/asio-1.18.2/include)