PkmnLib/CMakeLists.txt

79 lines
2.4 KiB
CMake
Raw Normal View History

2019-12-29 14:29:52 +00:00
cmake_minimum_required(VERSION 3.13)
# Make warnings trigger errors.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
project(pkmnLib)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (WINDOWS)
ADD_DEFINITIONS(-D WINDOWS=1)
endif(WINDOWS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
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 (NOT EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
message(WARNING "The file conanbuildinfo.cmake doesn't exist, running conan install.")
string(REPLACE "." ";" VERSION_LIST "${CMAKE_C_COMPILER_VERSION}")
list(GET VERSION_LIST 0 VERSION)
list(GET VERSION_LIST 1 MINOR)
if (NOT MINOR MATCHES 0)
2019-12-31 19:25:47 +00:00
SET(VERSION ${VERSION}.${MINOR})
endif()
2019-12-31 18:40:46 +00:00
if (NOT WINDOWS)
execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR} --install-folder=${CMAKE_BINARY_DIR} --build missing -s compiler=clang -s compiler.libcxx=libstdc++11 -s compiler.version=${VERSION})
2019-12-31 18:40:46 +00:00
else()
execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR} --install-folder=${CMAKE_BINARY_DIR} --build missing -s compiler=gcc -s compiler.libcxx=libstdc++11 -s compiler.version=${VERSION})
2019-12-31 18:40:46 +00:00
endif()
2019-12-29 14:29:52 +00:00
endif ()
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
2019-12-29 14:29:52 +00:00
# Create Core library with files in src/Core
file(GLOB_RECURSE CORE_SRC_FILES "src/*.cpp" "src/*.hpp")
add_library(pkmnLib SHARED ${CORE_SRC_FILES})
foreach (_variableName ${CONAN_LIBS})
message(STATUS "Lib: ${_variableName}")
endforeach()
SET(_LINKS ${CONAN_LIBS})
SET(_TESTLINKS pkmnLib ${CONAN_LIBS})
if (WINDOWS)
message(STATUS "Using Windows build.")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -Wa,-mbig-obj -Wl,-allow-multiple-definition")
# Statically link libraries we need in Windows.
SET(_LINKS -static -static-libgcc -static-libstdc++ ${_LINKS})
SET(_TESTLINKS -static -static-libgcc -static-libstdc++ ${_TESTLINKS})
endif (WINDOWS)
target_link_libraries(pkmnLib PUBLIC ${_LINKS})
2019-12-31 12:58:43 +00:00
if (NOT DEFINED CONAN_EXPORTED)
# Create Test executable
file(GLOB_RECURSE TEST_FILES "tests/*.cpp" "tests/*.hpp")
add_executable(pkmnLibTests ${TEST_FILES} extern/catch.hpp)
target_link_libraries(pkmnLibTests PUBLIC ${_TESTLINKS})
2019-12-31 12:58:43 +00:00
# Add a definition for the test library
target_compile_definitions(pkmnLibTests PRIVATE TESTS_BUILD)
endif ()
2019-12-29 14:29:52 +00:00