MalachScript/CMakeLists.txt

50 lines
1.7 KiB
CMake

cmake_minimum_required(VERSION 3.17)
project(MalachScript)
# Enable all warnings, and make them error when occurring.
add_compile_options(-Wall -Wextra -Werror)
# Except this warning, which goes against bugprone-macro-parentheses in clang-tidy
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Wno-parentheses)
endif ()
# We like new stuff, so set the c++ standard to c++20.
set(CMAKE_CXX_STANDARD 20)
option(TESTS "Whether the test executable should be build as well." OFF)
option(REPL "Whether the repl should be build as well." OFF)
option(STATICC "Whether gcc and stdc++ should be linked statically to the library." OFF)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_link_options(-fuse-ld=lld)
endif ()
file(GLOB_RECURSE SRC_FILES "src/*.cpp")
add_library(MalachScript SHARED ${SRC_FILES})
set(LINKS)
if (STATICC)
set(LINKS ${LINKS} -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread)
endif(STATICC)
target_link_libraries(MalachScript ${LINKS})
if (TESTS)
# Create Test executable
file(GLOB_RECURSE TEST_FILES "tests/*.cpp" "tests/*.hpp")
add_executable(MalachScriptTests ${TEST_FILES} extern/doctest.hpp)
target_link_libraries(MalachScriptTests PUBLIC MalachScript)
# Add a definition for the test library
target_compile_definitions(MalachScriptTests PRIVATE TESTS_BUILD)
endif ()
if (REPL)
# Create Test executable
file(GLOB_RECURSE REPL_FILES "repl/*.cpp" "repl/*.hpp" "extern/backward.cpp")
add_executable(MalachScriptREPL ${REPL_FILES})
target_compile_definitions(MalachScriptREPL PRIVATE BACKWARD_HAS_DW)
target_link_libraries(MalachScriptREPL PUBLIC MalachScript cursesw -ldw)
endif ()