cmake_minimum_required(VERSION 3.18) project(AngelscriptDebugger) include(CPM.cmake) 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(STATICC "Whether gcc and stdc++ should be linked statically to the library." OFF) 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) 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 (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) file(GLOB_RECURSE SRC_FILES "src/*.cpp" "src/*.hpp") add_library(AngelscriptDebugger ${LIBTYPE} ${SRC_FILES}) target_compile_options(AngelscriptDebugger PRIVATE -Wall -Wextra -Werror) target_include_directories(AngelscriptDebugger PRIVATE extern/asio-1.18.2/include) CPMAddPackage( NAME Angelscript GIT_REPOSITORY https://git.p-epsilon.com/Deukhoofd/Angelscript.git GIT_TAG master DOWNLOAD_ONLY YES ) if (Angelscript_ADDED) execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . -B ${Angelscript_BINARY_DIR} -DBUILD_SHARED_LIBS=${SHARED} -DMSVC=${WINDOWS} -DLINK_STD_STATICALLY=${STATICC} -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON RESULT_VARIABLE result WORKING_DIRECTORY ${Angelscript_SOURCE_DIR}/angelscript/projects/cmake) execute_process(COMMAND ${CMAKE_COMMAND} --build ${Angelscript_BINARY_DIR} RESULT_VARIABLE result WORKING_DIRECTORY ${Angelscript_SOURCE_DIR}/angelscript/projects/cmake) endif() include_directories(${Angelscript_SOURCE_DIR}/angelscript/include) target_link_directories(AngelscriptDebugger PUBLIC ${Angelscript_BINARY_DIR}) find_package(Threads REQUIRED) CPMAddPackage("gh:chriskohlhoff/asio#asio-1-21-0@1.21.0") if(asio_ADDED) add_library(asio INTERFACE) target_include_directories(asio SYSTEM INTERFACE ${asio_SOURCE_DIR}/asio/include) target_compile_definitions(asio INTERFACE ASIO_STANDALONE ASIO_NO_DEPRECATED) target_link_libraries(asio INTERFACE Threads::Threads) if(WIN32) # macro see @ https://stackoverflow.com/a/40217291/1746503 macro(get_win32_winnt version) if(CMAKE_SYSTEM_VERSION) set(ver ${CMAKE_SYSTEM_VERSION}) string(REGEX MATCH "^([0-9]+).([0-9])" ver ${ver}) string(REGEX MATCH "^([0-9]+)" verMajor ${ver}) # Check for Windows 10, b/c we'll need to convert to hex 'A'. if("${verMajor}" MATCHES "10") set(verMajor "A") string(REGEX REPLACE "^([0-9]+)" ${verMajor} ver ${ver}) endif("${verMajor}" MATCHES "10") # Remove all remaining '.' characters. string(REPLACE "." "" ver ${ver}) # Prepend each digit with a zero. string(REGEX REPLACE "([0-9A-Z])" "0\\1" ver ${ver}) set(${version} "0x${ver}") endif() endmacro() if(NOT DEFINED _WIN32_WINNT) get_win32_winnt(ver) set(_WIN32_WINNT ${ver}) endif() message(STATUS "Set _WIN32_WINNET=${_WIN32_WINNT}") target_compile_definitions(asio INTERFACE _WIN32_WINNT=${_WIN32_WINNT} WIN32_LEAN_AND_MEAN) endif() endif() CPMAddPackage("gh:nlohmann/json@3.10.5") SET(_LINKS -langelscript -pthread asio nlohmann_json::nlohmann_json) 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(AngelscriptDebugger PROPERTIES SUFFIX ".dll") endif(SHARED) set(_LINKS ${_LINKS} -Wl,-Bstatic -lws2_32 -Wl,-Bdynamic) endif (WINDOWS) if (STATICC) set (CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed") message(STATUS "Linking C library statically") set(_LINKS ${_LINKS} -static-libgcc -static-libstdc++) endif() target_link_libraries(AngelscriptDebugger PUBLIC ${_LINKS}) file(GLOB_RECURSE RUNNER_SRC_FILES "TestRunner/*.cpp" "TestRunner/*.hpp") add_executable(AngelscriptDebuggerRunner ${RUNNER_SRC_FILES}) target_link_libraries(AngelscriptDebuggerRunner AngelscriptDebugger)