PkmnLib/CMakeLists.txt

106 lines
3.1 KiB
CMake

cmake_minimum_required(VERSION 3.13)
project(pkmnLib)
# Enable all warnings, and make them error when occurring.
add_compile_options(-Wall -Wextra -Werror)
# We like new stuff, so set the c++ standard to c++20.
set(CMAKE_CXX_STANDARD 20)
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." OFF)
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.")
if (WINDOWS)
SET(CMAKE_SYSTEM_NAME Windows)
ADD_DEFINITIONS(-D WINDOWS=1)
endif (WINDOWS)
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}")
include(CmakeConanSetup.cmake)
SetupConan()
message(STATUS "Using Conan Libs:")
foreach (_conanLib ${CONAN_LIBS})
message(STATUS "\t ${_conanLib}")
endforeach ()
# 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"
)
ADD_DEFINITIONS(-D AS_USE_ACCESSORS=1)
endif()
file(GLOB_RECURSE CORE_SRC_FILES ${FILE_SOURCE})
add_library(pkmnLib ${LIBTYPE} ${CORE_SRC_FILES})
SET(_LINKS CreatureLibLibrary CreatureLibBattling Arbutils)
SET(_TESTLINKS pkmnLib CreatureLibLibrary CreatureLibBattling Arbutils)
if (SCRIPT_PROVIDER STREQUAL "angelscript")
message(STATUS "Using Angelscript as script provider.")
ADD_DEFINITIONS(-D ANGELSCRIPT=1)
SET(_LINKS angelscript ${_LINKS})
SET(_TESTLINKS angelscript ${_TESTLINKS})
endif ()
if (WINDOWS)
message(STATUS "Using Windows build.")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L ${CMAKE_BINARY_DIR}/bin")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -Wa,-mbig-obj -Wl,-allow-multiple-definition")
endif (WINDOWS)
if (STATICC)
message(STATUS "Linking C library statically")
SET(_LINKS ${_LINKS} -static-libgcc -static-libstdc++)
endif()
target_link_libraries(pkmnLib PUBLIC ${_LINKS})
if (TESTS)
# Create Test executable
file(GLOB_RECURSE TEST_FILES "tests/*.cpp" "tests/*.hpp")
add_executable(pkmnLibTests ${TEST_FILES} extern/catch.hpp)
message(STATUS "${_TESTLINKS}")
target_link_libraries(pkmnLibTests PUBLIC ${_TESTLINKS})
# Add a definition for the test library
target_compile_definitions(pkmnLibTests PRIVATE TESTS_BUILD)
endif ()