-
Notifications
You must be signed in to change notification settings - Fork 425
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix #8778 - FindPython in modern cmake and handle issue when LINK_WITH_PYTHON on windows with both Release/debug libraries #8832
Conversation
A conversation with @Myoldmopar lead to this. I'm already bumping to 3.12, but 3.16 added Precompiled Headers (PCH) which is a significant speedup. 3.13 added target_link_options which is also handy.
CMakeLists.txt
Outdated
@@ -9,7 +9,7 @@ cmake_policy(SET CMP0048 NEW) # handling project_version_* variables | |||
|
|||
project(EnergyPlus) | |||
|
|||
cmake_minimum_required(VERSION 3.10) | |||
cmake_minimum_required(VERSION 3.16) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New Minimum version here to 3.16 for precompiled header support.
# If LINK_WITH_PYTHON, also request the Development (libs) at the same time, to ensure consistent version between interpreter and Development | ||
if(LINK_WITH_PYTHON) | ||
find_package(Python 3.6 COMPONENTS Interpreter Development REQUIRED) | ||
else() | ||
find_package(Python 3.6 COMPONENTS Interpreter REQUIRED) | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New way, find both components at the same time to ensure consistent versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it!
@@ -270,7 +275,7 @@ endif() | |||
add_subdirectory(idd) | |||
|
|||
execute_process( | |||
COMMAND ${PYTHON_EXECUTABLE} "${PROJECT_SOURCE_DIR}/scripts/dev/generate_epJSON_schema/generate_epJSON_schema.py" "${PROJECT_SOURCE_DIR}" | |||
COMMAND ${Python_EXECUTABLE} "${PROJECT_SOURCE_DIR}/scripts/dev/generate_epJSON_schema/generate_epJSON_schema.py" "${PROJECT_SOURCE_DIR}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PYTHON_XXXX
variables were retained for backward compatibility, but the official casing is Programname_XXX
so Python_XXX
to be consitent with the rest of cmake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, makes sense. I'm pretty sure if anyone ever adds another call from Python they'll end up just copying whatever we have in place anyway.
@@ -1,12 +1,12 @@ | |||
project(EnergyPlusDocs LANGUAGES NONE) | |||
|
|||
cmake_minimum_required(VERSION 3.5.1) | |||
cmake_minimum_required(VERSION 3.12) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In docs, we only need to bump to 3.12 for FindPython because PCH isn't in the mix... So I did 3.12 instead of 3.16, up for debate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm...I'm not sure. I guess it's best to keep the minimum required to the minimum required for that specific project scope. So 3.12 makes sense for the new FindPython.
src/EnergyPlus/CMakeLists.txt
Outdated
# In case you have both release and debug Python libraries on your system, Python_LIBRARIES might be "optimized;C:/.../python38.lib;debug;C:/.../python38_d.lib" | ||
# so it can't be used directly, we could use a generator expression to find the $<TARGET_FILE:Python::Python> library used and that'd point directly | ||
# to the DLL. But it won't work nicely for the install(code ...) command below... so we do a hack, get the optimized one always... | ||
list(LENGTH Python_LIBRARIES _LEN) | ||
if (_LEN GREATER 1) | ||
set (_Python_DOING_RELEASE FALSE) | ||
foreach(_currentArg ${Python_LIBRARIES}) | ||
message("_currentArg=${_currentArg}") | ||
if ("x${_currentArg}" STREQUAL "xoptimized") | ||
set(_Python_DOING_RELEASE TRUE) | ||
elseif(_Python_DOING_RELEASE) | ||
get_filename_component(RESOLVED_PYTHON_LIBRARY "${_currentArg}" REALPATH) | ||
break() | ||
endif() | ||
endforeach() | ||
# else() | ||
# No-op, already done above | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actual fix for #8778 when you have both Release and Debug python libs on your system.
Well would you look at that!? Happy on all 3 platforms! This is good stuff. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel confident with all of this but I do want some clarification on the loop for finding the right version of Python. If we can get this resolved I believe this is good to go.
@@ -9,7 +9,7 @@ cmake_policy(SET CMP0048 NEW) # handling project_version_* variables | |||
|
|||
project(EnergyPlus) | |||
|
|||
cmake_minimum_required(VERSION 3.10) | |||
cmake_minimum_required(VERSION 3.17) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! This makes the whole PCH thing feel much better too.
# If LINK_WITH_PYTHON, also request the Development (libs) at the same time, to ensure consistent version between interpreter and Development | ||
if(LINK_WITH_PYTHON) | ||
find_package(Python 3.6 COMPONENTS Interpreter Development REQUIRED) | ||
else() | ||
find_package(Python 3.6 COMPONENTS Interpreter REQUIRED) | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it!
@@ -270,7 +275,7 @@ endif() | |||
add_subdirectory(idd) | |||
|
|||
execute_process( | |||
COMMAND ${PYTHON_EXECUTABLE} "${PROJECT_SOURCE_DIR}/scripts/dev/generate_epJSON_schema/generate_epJSON_schema.py" "${PROJECT_SOURCE_DIR}" | |||
COMMAND ${Python_EXECUTABLE} "${PROJECT_SOURCE_DIR}/scripts/dev/generate_epJSON_schema/generate_epJSON_schema.py" "${PROJECT_SOURCE_DIR}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, makes sense. I'm pretty sure if anyone ever adds another call from Python they'll end up just copying whatever we have in place anyway.
@@ -1,12 +1,12 @@ | |||
project(EnergyPlusDocs LANGUAGES NONE) | |||
|
|||
cmake_minimum_required(VERSION 3.5.1) | |||
cmake_minimum_required(VERSION 3.12) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm...I'm not sure. I guess it's best to keep the minimum required to the minimum required for that specific project scope. So 3.12 makes sense for the new FindPython.
elseif(_Python_DOING_RELEASE) | ||
get_filename_component(RESOLVED_PYTHON_LIBRARY "${_currentArg}" REALPATH) | ||
break() | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a code path here missing in case you don't find the optimized keyword? I know it would be random but just trying to make it as robust as possible. Maybe if the finder finds multiple debug build versions on one system?? Would it be debug;C:/Something.lib;debug;C:/SomethingElse.lib
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Myoldmopar AFAIK you cannot install only debug libraries, and optimized are always installed. Either you have both and it's guaranteed you'll have optimized, or you have only one item. See source code here: https://gitlab.kitware.com/cmake/cmake/blob/fc762735196dbbc983dfac2145cd7afd7892bf54/Modules/FindPython/Support.cmake#L63-91
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK thanks.
No point waiting on this to go in. This is a great set of changes. Much more reliable finding! Thanks @jmarrec ! |
Pull request overview
(This is the third version of this branch).
FindPython
instead of the deprecated FindPythonInterp+FindPythonLibsFindPythonInterp
andFindPythonLibs
where called at different points (toplevelCMakeLists.txt
andsrc/EnergyPlus/CMakeLists.txt
respectively), which in my case often resulted in different versions being picked up (I have a 3.6 system python on Ubuntu, and 4 different pyenv versions and several virtualenvs on top of these).This requires bumping the cmake_minimum_version to at least 3.12. Because of we're bumping, we're actually bumping to 3.16 here which adds PCH (precompiled headers) which is an option enabled by default now
EnergyPlus/CMakeLists.txt
Line 30 in 73fc0b1
target_precompile_headers
was added in version 3.16: https://cmake.org/cmake/help/git-stage/command/target_precompile_headers.htmlPull Request Author
Add to this list or remove from it as applicable. This is a simple templated set of guidelines.
Reviewer
This will not be exhaustively relevant to every PR.