-
Notifications
You must be signed in to change notification settings - Fork 65
[ML] Generate windows resource files using CMake functionality #2321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4764513
757b24a
452f28c
161299c
65985c8
247322f
dd29063
f38b0a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,23 +28,55 @@ endif() | |
# that is linked into the Windows executables | ||
# | ||
function(ml_generate_resources _target) | ||
if(NOT WIN32) | ||
return() | ||
|
||
set(ML_VERSION_STR "${ML_VERSION_NUM}") | ||
|
||
if(ENV{VERSION_QUALIFIER}) | ||
set(ML_VERSION_STR "${ML_VERSION_STR}-$ENV{VERSION_QUALIFIER}") | ||
endif() | ||
|
||
if(NOT ENV{SNAPSHOT} STREQUAL no) | ||
set(ML_VERSION_STR "${ML_VERSION_STR}-SNAPSHOT") | ||
endif() | ||
|
||
if(${ML_VERSION_STR} MATCHES "([0-9.]+)") | ||
set(ML_VERSION ${CMAKE_MATCH_1}) | ||
endif() | ||
string(REPLACE "." "," ML_VERSION "${ML_VERSION}") | ||
|
||
set(ML_PATCH "0") | ||
|
||
execute_process(COMMAND git -c core.fileMode=false update-index -q --refresh ERROR_FILE /dev/null OUTPUT_FILE /dev/null) | ||
execute_process(COMMAND git -c core.fileMode=false diff-index --quiet HEAD -- RESULT_VARIABLE UNCOMMITTED_CHANGES) | ||
|
||
if(UNCOMMITED_CHANGES EQUAL 0) | ||
set(ML_FILEFLAGS "0") | ||
else() | ||
set(ML_FILEFLAGS "VS_FF_PRIVATEBUILD") | ||
endif() | ||
set( ${_target}_LINKFLAGS ${CMAKE_CURRENT_BINARY_DIR}/${_target}.res ) | ||
set_target_properties( ${_target} PROPERTIES LINK_FLAGS ${${_target}_LINKFLAGS} ) | ||
execute_process(COMMAND bash -c "${CMAKE_SOURCE_DIR}/mk/make_rc_defines.sh ${_target}.exe" OUTPUT_VARIABLE | ||
RC_DEFINES OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/tmp.sh "rc -nologo ${CPPFLAGS} ${RC_DEFINES} -Fo${_target}.res ${CMAKE_SOURCE_DIR}/mk/ml.rc") | ||
add_custom_target( | ||
${_target}.res | ||
DEPENDS ${CMAKE_SOURCE_DIR}/mk/ml.rc ${CMAKE_SOURCE_DIR}/gradle.properties ${CMAKE_SOURCE_DIR}/mk/ml.ico ${CMAKE_SOURCE_DIR}/mk/make_rc_defines.sh ${CMAKE_CURRENT_BINARY_DIR}/tmp.sh | ||
COMMAND bash -c ${CMAKE_CURRENT_BINARY_DIR}/tmp.sh | ||
) | ||
add_dependencies(${_target} ${_target}.res) | ||
|
||
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_CURRENT_BINARY_DIR}/tmp.sh) | ||
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_CURRENT_BINARY_DIR}/${_target}.res) | ||
if("${_target}" MATCHES ".dll$") | ||
set(ML_FILETYPE "VFT_DLL") | ||
else() | ||
set(ML_FILETYPE "VFT_APP") | ||
endif() | ||
|
||
set(ML_FILENAME ${_target}) | ||
|
||
if(${_target} MATCHES "([^.]+).") | ||
set(ML_NAME ${CMAKE_MATCH_1}) | ||
endif() | ||
set(ML_YEAR ${BUILD_YEAR}) | ||
set(ML_ICON ${CMAKE_SOURCE_DIR}/mk/ml.ico) | ||
|
||
configure_file( | ||
"${CMAKE_SOURCE_DIR}/mk/ml.rc.in" | ||
edsavage marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"${CMAKE_CURRENT_BINARY_DIR}/${ML_NAME}.rc" | ||
@ONLY | ||
) | ||
|
||
set(ML_FILEFLAGS ${ML_FILEFLAGS} PARENT_SCOPE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is OK, but it does now mean that in addition to the resource file all our C++ code is getting compiled with this extra symbol defined. I'm sure it won't be a problem as none of our source will contain this string. It might be nicer to substitute it only into the resource file using the |
||
|
||
endfunction() | ||
|
||
# | ||
|
@@ -95,6 +127,12 @@ function(ml_add_library _target _type) | |
|
||
add_compile_definitions(BUILDING_lib${_target}) | ||
|
||
if (WIN32 AND _type STREQUAL "SHARED") | ||
ml_generate_resources(lib${_target}.dll) | ||
list(APPEND PLATFORM_SRCS ${CMAKE_CURRENT_BINARY_DIR}/lib${_target}.rc) | ||
edsavage marked this conversation as resolved.
Show resolved
Hide resolved
|
||
add_compile_definitions(ML_FILEFLAGS=${ML_FILEFLAGS}) | ||
endif() | ||
|
||
add_library(${_target} ${_type} ${PLATFORM_SRCS}) | ||
|
||
if(ML_LINK_LIBRARIES) | ||
|
@@ -140,6 +178,12 @@ function(ml_add_executable _target) | |
add_library(Ml${_target} OBJECT ${PLATFORM_SRCS}) | ||
endif() | ||
|
||
if (WIN32) | ||
ml_generate_resources(${_target}.exe) | ||
list(APPEND PLATFORM_SRCS ${CMAKE_CURRENT_BINARY_DIR}/${_target}.rc) | ||
add_compile_definitions(ML_FILEFLAGS=${ML_FILEFLAGS}) | ||
endif() | ||
|
||
add_executable(${_target} Main.cc ${PLATFORM_SRCS}) | ||
|
||
if (ML_EXE_LINKER_FLAGS) | ||
|
@@ -150,8 +194,6 @@ function(ml_add_executable _target) | |
|
||
ml_install(${_target}) | ||
|
||
ml_generate_resources(${_target}) | ||
|
||
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "Linux") | ||
target_link_libraries(${_target} PRIVATE "${COVERAGE}") | ||
endif() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <Windows.h> | ||
|
||
1 VERSIONINFO | ||
FILEVERSION @ML_VERSION@,@ML_PATCH@ | ||
edsavage marked this conversation as resolved.
Show resolved
Hide resolved
|
||
PRODUCTVERSION @ML_VERSION@,@ML_PATCH@ | ||
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK | ||
FILEFLAGS (0 | @ML_FILEFLAGS@) | ||
FILEOS VOS_NT_WINDOWS32 | ||
FILETYPE @ML_FILETYPE@ | ||
BEGIN | ||
BLOCK "StringFileInfo" | ||
BEGIN | ||
BLOCK "080904E4" | ||
BEGIN | ||
#if ML_FILEFLAGS | ||
edsavage marked this conversation as resolved.
Show resolved
Hide resolved
|
||
VALUE "Comments", "Build @ML_BUILD_STR@ by @ML_USER@" | ||
#else | ||
VALUE "Comments", "Build @ML_BUILD_STR@" | ||
#endif | ||
VALUE "CompanyName", "Elasticsearch BV" | ||
VALUE "FileDescription", "@ML_FILENAME@ (part of Elasticsearch machine learning)" | ||
VALUE "FileVersion", "@ML_VERSION_STR@" | ||
VALUE "InternalName", "@ML_NAME@" | ||
VALUE "LegalCopyright", "Copyright (c) @ML_YEAR@ Elasticsearch BV" | ||
#if 0 | ||
VALUE "LegalTrademarks", "TODO" | ||
#endif | ||
VALUE "OriginalFilename", "@ML_FILENAME@" | ||
#if ML_FILEFLAGS | ||
edsavage marked this conversation as resolved.
Show resolved
Hide resolved
|
||
VALUE "PrivateBuild", "Built by @ML_USER@" | ||
#endif | ||
VALUE "ProductName", "Elasticsearch machine learning" | ||
VALUE "ProductVersion", "@ML_VERSION_STR@" | ||
END | ||
END | ||
BLOCK "VarFileInfo" | ||
BEGIN | ||
VALUE "Translation", 0x0809, 1252 | ||
END | ||
END | ||
|
||
2 ICON "@ML_ICON@" | ||
|
Uh oh!
There was an error while loading. Please reload this page.