cmake_minimum_required(VERSION 3.18) project(Yerbacon VERSION 0.0.1 LANGUAGES C CXX) if (NOT DEFINED CODENAME) set(CODENAME "Unknown") if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/misc/codename.txt") file(READ "${CMAKE_CURRENT_SOURCE_DIR}/misc/codename.txt" CODENAME) endif () endif() file(COPY "resources/Yerbacon.manifest" "resources/Yerbacon.ico" DESTINATION "processed") configure_file("resources/Yerbacon.rc" "processed/Yerbacon.rc" @ONLY) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_FLAGS "-Wall") if (NOT MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") endif() set(CMAKE_CXX_FLAGS_RELEASE "-Os") if((${CMAKE_CXX_COMPILER_ID} STREQUAL GNU) OR (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)) set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc") set(CMAKE_CXX_FLAGS "-flto ${CMAKE_CXX_FLAGS} -fpie -pipe -fstack-protector-strong -fstack-clash-protection") endif() if (${CMAKE_CXX_COMPILER_ID} STREQUAL GNU) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fira-loop-pressure -ftree-loop-distribution -floop-interchange -ftree-vectorize -fipa-pta -s") set(CMAKE_CXX_FLAGS "-fno-use-linker-plugin -fwhole-program ${CMAKE_CXX_FLAGS}") elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL Clang) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ftree-vectorize") set(CMAKE_CXX_FLAGS "-fwhole-program-vtables ${CMAKE_CXX_FLAGS}") endif() if(MINGW OR MSVC) if (UNIX) SET(CMAKE_RC_COMPILE_OBJECT " -O coff -i -o ") SET(CMAKE_RC_COMPILER i686-w64-mingw32-windres) endif() ENABLE_LANGUAGE(RC) endif() # CPack configuration set(CPACK_STRIP_FILES TRUE) set(CPACK_VERBATIM_VARIABLES TRUE) string(TIMESTAMP TIME "%Y.%m+%d") set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}-${TIME}") set(CPACK_PACKAGE_VENDOR "Contributor(s)") set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/resources/Yerbacon.png") set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/misc/desc.txt") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Transpiler for the yerbacon language.") set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt") set(CPACK_PACKAGE_CONTACT "Username404 ") set(CPACK_PACKAGE_INSTALL_DIRECTORY "Yerbacon ${CMAKE_PROJECT_VERSION_MAJOR}.${CMAKE_PROJECT_VERSION_MINOR}") set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CMAKE_PROJECT_VERSION}-${TIME}") set(CPACK_STRIP_FILES TRUE) include_directories(${CMAKE_CURRENT_LIST_DIR}) add_executable(ybcon src/main.cpp ${CMAKE_CURRENT_BINARY_DIR}/processed/Yerbacon.rc src/parser/MainParse.cpp src/transpiler/MainTranspile.cpp src/etc/filefuncs.cpp src/etc/lexer.cpp src/headers/lex.hpp src/headers/misc.hpp src/headers/parsing/ParseComponents.hpp src/headers/parsing/StandardComponents.hpp) target_compile_definitions(ybcon PRIVATE YBCON_VERSION="${PROJECT_VERSION}") # lpkg = linux package, wpkg = windows package if (UNIX AND NOT MINGW) include(GNUInstallDirs) set(CMAKE_INSTALL_PREFIX "/opt") set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}_lpkg") set(CPACK_SYSTEM_NAME "Linux-${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}") set(CPACK_TOPLEVEL_TAG "Linux-${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}") set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/scripts/postinst.sh") set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA}) set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.14), libstdc++6 (>= 9)") set(CPACK_DEBIAN_COMPRESSION_TYPE lzma) set(CPACK_RPM_COMPRESSION_TYPE lzma) set(CPACK_RPM_PACKAGE_AUTOREQ YES) set(CPACK_RPM_PACKAGE_LICENSE "MPL-2.0") set(CPACK_RPM_CHANGELOG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/changelog.txt") set(CPACK_RPM_PACKAGE_VERSION ${PROJECT_VERSION}) set(CPACK_RPM_PACKAGE_RELEASE ${TIME}) set(CPACK_RPM_PACKAGE_RELEASE_DIST ON) if (CPACK_RPM_PACKAGE_SOURCES) set(CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX "/") set(CPACK_GENERATOR RPM) set(CPACK_RPM_BUILDREQUIRES "cmake >= 3.18, clang >= 11.0.0") install(DIRECTORY src DESTINATION ${CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX}) install(DIRECTORY resources DESTINATION ${CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX}) install(DIRECTORY scripts DESTINATION ${CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX}) install(FILES CMakeLists.txt misc/desc.txt LICENSE.txt README.md changelog.txt DESTINATION ${CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX}) else() if (NOT DEFINED CPACK_GENERATOR) set(CPACK_GENERATOR TGZ;STGZ;RPM;DEB) endif() install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/ybcon DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts/completions DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/ybcon.d) install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/ybcon DESTINATION yerbacon/${CMAKE_INSTALL_BINDIR}) endif() elseif(MINGW OR MSVC) set(CMAKE_EXE_LINKER_FLAGS "-static -static-libstdc++ ${CMAKE_EXE_LINKER_FLAGS}") set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}_wpkg") set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}/resources/Yerbacon.ico") set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}/resources/Yerbacon.ico") set(CPACK_NSIS_DEFINES "RequestExecutionLevel highest") set(CPACK_SYSTEM_NAME "Win32-${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}") set(CPACK_TOPLEVEL_TAG "Win32-${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}") set(CPACK_NSIS_MODIFY_PATH ON) set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON) set(CPACK_GENERATOR ZIP;NSIS) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ybcon.exe DESTINATION bin) endif() include(CPack)