Enable threads only when they are available, and replace "ybcon" occurrences with "${EXENAME}" in the CMakeLists.txt file

This commit is contained in:
Username404 2021-12-21 19:47:53 +01:00
parent 106a2f0be9
commit 96efa6b0fb
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
1 changed files with 17 additions and 9 deletions

View File

@ -44,15 +44,17 @@ if (NOT NO_CCACHE)
endif()
endif()
find_package(Threads)
if (${IS_GNU} OR ${IS_CLANG})
if (NOT MINGW)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
if (Threads_FOUND AND NOT MINGW)
include(FindOpenMP)
if (OpenMP_CXX_FOUND)
set(CMAKE_CXX_FLAGS "${OpenMP_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")
add_definitions(-D_GLIBCXX_PARALLEL)
endif()
endif()
set(CMAKE_CXX_FLAGS "-pthread ${CMAKE_CXX_FLAGS} -fstrict-enums -pipe -fstack-protector-strong -fstack-clash-protection -funwind-tables -fasynchronous-unwind-tables -frtti -fexceptions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstrict-enums -pipe -fstack-protector-strong -fstack-clash-protection -funwind-tables -fasynchronous-unwind-tables -frtti -fexceptions")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ffunction-sections -fdata-sections -fmerge-all-constants -ftree-vectorize")
include(CheckCXXCompilerFlag)
set(CF_PROTECTION "-fcf-protection")
@ -69,7 +71,10 @@ if (${IS_GNU})
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${MINIMAL_GNU})
message(FATAL_ERROR "G++ ${MINIMAL_GNU} or higher is required.")
endif()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fvect-cost-model=unlimited -foptimize-strlen -fsched-pressure -flive-range-shrinkage -fpredictive-commoning -ftree-partial-pre -fzero-call-used-regs=used-gpr-arg -ftree-parallelize-loops=2 -fira-loop-pressure -ftree-loop-distribution -floop-interchange -fsplit-paths -fgcse-las -fgcse-sm -fipa-pta -fstdarg-opt -fivopts")
if (Threads_FOUND)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ftree-parallelize-loops=2")
endif()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fvect-cost-model=unlimited -foptimize-strlen -fsched-pressure -flive-range-shrinkage -fpredictive-commoning -ftree-partial-pre -fzero-call-used-regs=used-gpr-arg -fira-loop-pressure -ftree-loop-distribution -floop-interchange -fsplit-paths -fgcse-las -fgcse-sm -fipa-pta -fstdarg-opt -fivopts")
if (${CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE})
set(CMAKE_CXX_FLAGS_RELEASE "-fwhole-program ${CMAKE_CXX_FLAGS_RELEASE}")
endif()
@ -121,8 +126,11 @@ set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${CMAKE_PROJECT_VERSION}-${TIME}")
include_directories(${CMAKE_CURRENT_LIST_DIR})
add_executable(${EXENAME} src/main.cpp ${CMAKE_CURRENT_BINARY_DIR}/processed/${PROJECT_NAME}.rc src/etc/filefuncs.cpp src/etc/lexer.cpp src/headers/lex.hpp src/headers/misc.hpp src/headers/parsing/ParseComponents.hpp src/headers/transpiler/Target.hpp src/headers/transpiler/implementations/Lua.hpp src/headers/transpiler/implementations/Js.hpp src/headers/transpiler/implementations/Py.hpp src/headers/parsing/Parser.hpp src/headers/arguments.hpp)
target_compile_definitions(ybcon PRIVATE YBCON_VERSION="${CODENAME} ${PROJECT_VERSION}")
target_compile_definitions(${EXENAME} PRIVATE YBCON_VERSION="${CODENAME} ${PROJECT_VERSION}")
target_precompile_headers(${EXENAME} PRIVATE src/headers/Yerbacon.hpp)
if (Threads_FOUND)
target_link_libraries(${EXENAME} PRIVATE Threads::Threads)
endif()
# lpkg = linux package, wpkg = windows package
set(PNAME ${PROJECT_NAME}-${CODENAME}-${TIME})
@ -154,7 +162,7 @@ if (UNIX AND NOT (MINGW OR CMAKE_HOST_WIN32))
COMMENT "Compressing the changelog file"
)
add_custom_target(changelog ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${GZNAME}")
add_dependencies(ybcon changelog)
add_dependencies(${EXENAME} changelog)
string(TOLOWER "${CMAKE_INSTALL_DOCDIR}" DEB_CHANGELOG_DEST_DIR) # Lowercase characters are needed because GNUInstallDirs uses the PROJECT_NAME variable.
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${GZNAME}"
@ -177,10 +185,10 @@ if (UNIX AND NOT (MINGW OR CMAKE_HOST_WIN32))
set(CPACK_GENERATOR TGZ;STGZ;RPM;DEB)
endif()
install(PROGRAMS
${CMAKE_CURRENT_BINARY_DIR}/ybcon
${CMAKE_CURRENT_BINARY_DIR}/${EXENAME}
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
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts/completions DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${EXENAME}.d)
install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/${EXENAME}
DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
elseif(MINGW OR MSVC)
@ -211,7 +219,7 @@ elseif(MINGW OR MSVC)
# CMake 3.22+ is required to ignore the NSIS license page
set(CPACK_NSIS_IGNORE_LICENSE_PAGE TRUE)
set(CPACK_GENERATOR ZIP;NSIS)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ybcon.exe DESTINATION bin)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EXENAME}.exe DESTINATION bin)
endif()
if (NOT DEFINED CXX_TARGET)
set(CXX_TARGET ${CMAKE_HOST_SYSTEM_PROCESSOR})