JurassicParkTrespasser/jp2_pc/cmake/CMakeCommon.cmake

92 lines
4.3 KiB
CMake

function(add_common_options)
add_compile_definitions(
$<$<CONFIG:Debug>:_DEBUG>
$<$<CONFIG:Debug>:BUILDVER_MODE=MODE_DEBUG>
$<$<CONFIG:Release>:BUILDVER_MODE=MODE_RELEASE>
$<$<CONFIG:Final>:BUILDVER_MODE=MODE_FINAL>
$<$<CONFIG:Release>:_RELEASE>
$<$<CONFIG:Final>:_RELEASE>
$<$<CONFIG:Debug>:TARGET_PROCESSOR=PROCESSOR_PENTIUM>
$<$<CONFIG:Release>:TARGET_PROCESSOR=PROCESSOR_PENTIUMPRO>
$<$<CONFIG:Final>:TARGET_PROCESSOR=PROCESSOR_PENTIUMPRO>
$<$<CONFIG:Debug>:NOMINMAX>
$<$<CONFIG:Release>:NOMINMAX>
$<$<CONFIG:Final>:NOMINMAX>
)
#In CMake, the regular Release configuration has no debug info
#We turn Release and Final into RelWithDebInfo so that we can have it anyway
#While keeping the configuration name "Release"
set(CMAKE_CXX_FLAGS_FINAL ${CMAKE_CXX_FLAGS_RELWITHDEBINFO} PARENT_SCOPE)
set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELWITHDEBINFO} PARENT_SCOPE)
set(CMAKE_EXE_LINKER_FLAGS_RELEASE_TMP ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO})
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE_TMP ${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO})
#Incremental linking bloats the binary with padding
#Optimizing references means dropping unused symbols from binary
#Tip: list the dropped symbols with /VERBOSE:REF
set(CMAKE_EXE_LINKER_FLAGS_RELEASE_TMP "${CMAKE_EXE_LINKER_FLAGS_RELEASE_TMP} /INCREMENTAL:NO /OPT:REF")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE_TMP "${CMAKE_SHARED_LINKER_FLAGS_RELEASE_TMP} /INCREMENTAL:NO /OPT:REF")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG_TMP "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG_TMP "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
set(CMAKE_EXE_LINKER_FLAGS_FINAL_TMP "${CMAKE_EXE_LINKER_FLAGS_RELEASE_TMP}")
set(CMAKE_SHARED_LINKER_FLAGS_FINAL_TMP "${CMAKE_SHARED_LINKER_FLAGS_RELEASE_TMP}")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG_TMP "${CMAKE_EXE_LINKER_FLAGS_DEBUG_TMP} /MAP:${PROJECT_BINARY_DIR}/Debug/${PROJECT_NAME}.map")
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG_TMP "${CMAKE_SHARED_LINKER_FLAGS_DEBUG_TMP} /MAP:${PROJECT_BINARY_DIR}/Debug/{PROJECT_NAME}.map")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE_TMP "${CMAKE_EXE_LINKER_FLAGS_RELEASE_TMP} /MAP:${PROJECT_BINARY_DIR}/Release/${PROJECT_NAME}.map")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE_TMP "${CMAKE_SHARED_LINKER_FLAGS_RELEASE_TMP} /MAP:${PROJECT_BINARY_DIR}/Release/{PROJECT_NAME}.map")
set(CMAKE_EXE_LINKER_FLAGS_FINAL_TMP "${CMAKE_EXE_LINKER_FLAGS_FINAL_TMP} /MAP:${PROJECT_BINARY_DIR}/Final/${PROJECT_NAME}.map")
set(CMAKE_SHARED_LINKER_FLAGS_FINAL_TMP "${CMAKE_SHARED_LINKER_FLAGS_FINAL_TMP} /MAP:${PROJECT_BINARY_DIR}/Final/{PROJECT_NAME}.map")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG ${CMAKE_EXE_LINKER_FLAGS_DEBUG_TMP} PARENT_SCOPE)
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG ${CMAKE_SHARED_LINKER_FLAGS_DEBUG_TMP} PARENT_SCOPE)
set(CMAKE_EXE_LINKER_FLAGS_RELEASE ${CMAKE_EXE_LINKER_FLAGS_RELEASE_TMP} PARENT_SCOPE)
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE ${CMAKE_SHARED_LINKER_FLAGS_RELEASE_TMP} PARENT_SCOPE)
set(CMAKE_EXE_LINKER_FLAGS_FINAL ${CMAKE_EXE_LINKER_FLAGS_FINAL_TMP} PARENT_SCOPE)
set(CMAKE_SHARED_LINKER_FLAGS_FINAL ${CMAKE_SHARED_LINKER_FLAGS_FINAL_TMP} PARENT_SCOPE)
endfunction()
function(createGitVersionFile)
set(GIT_HASH_FULL "undefined")
set(GIT_HASH_SHORT "undefined")
set(GIT_BRANCH_NAME "undefined")
find_package(Git)
if (GIT_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%H OUTPUT_VARIABLE GIT_HASH_FULL)
execute_process(COMMAND ${GIT_EXECUTABLE} "log" "-1" "--pretty=format:%h" OUTPUT_VARIABLE GIT_HASH_SHORT)
#alternative for older git versions is git symbolic-ref --short HEAD
execute_process(COMMAND ${GIT_EXECUTABLE} "branch" "--show-current" OUTPUT_VARIABLE GIT_BRANCH_NAME)
endif()
string(REPLACE "\n" "" GIT_BRANCH_NAME "${GIT_BRANCH_NAME}" )
set(GIT_HEADER_FILENAME "${CMAKE_SOURCE_DIR}/Source/gblinc/versionGit.hpp")
set(GIT_HEADER_CONTENT "")
string(APPEND GIT_HEADER_CONTENT "#pragma once\n")
string(APPEND GIT_HEADER_CONTENT "//This file is autogenerated by a CMake script\n")
string(APPEND GIT_HEADER_CONTENT "\n")
string(APPEND GIT_HEADER_CONTENT "#define GIT_HASH_FULL \"${GIT_HASH_FULL}\"\n" )
string(APPEND GIT_HEADER_CONTENT "#define GIT_HASH_SHORT \"${GIT_HASH_SHORT}\"\n" )
string(APPEND GIT_HEADER_CONTENT "#define GIT_BRANCH_NAME \"${GIT_BRANCH_NAME}\"\n" )
file(WRITE ${GIT_HEADER_FILENAME} "${GIT_HEADER_CONTENT}")
endfunction()