Skip to content
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

Building with with LLVM's libc++ (and general cmake configuration) #1118

Open
jmarrec opened this issue Dec 22, 2023 · 1 comment
Open

Building with with LLVM's libc++ (and general cmake configuration) #1118

jmarrec opened this issue Dec 22, 2023 · 1 comment

Comments

@jmarrec
Copy link

jmarrec commented Dec 22, 2023

Describe the bug

This should never be done like this:

target_link_libraries(ssc -lpthread -lm -ldl -lstdc++)

Please remove the lstdc++. Side note but the rest is also supoptimal:

-target_link_libraries(ssc -lpthread -lm -ldl -lstdc++)
+find_package(Threads REQUIRED)
+target_link_libraries(ssc PUBLIC Threads::Threads ${CMAKE_DL_LIBS}) 
+find_library(MATH_LIBRARY m)
+if(MATH_LIBRARY)
+    target_link_libraries(ssc PUBLIC ${MATH_LIBRARY})
+endif()

CMAKE_DL_LIBS

That bit below defines CMAKE_CXX_STANDARD twice (and it does it globally... which is frowned upon). The CMAKE_C_COMPILER block is super strange and should be removed. The projectcommand should use the LANGUAGES CXX which would take care of linking to a C++ std lib, and defining the C/CXX compilers as needed.

ssc/CMakeLists.txt

Lines 28 to 48 in 9d76d0c

if (UNIX AND NOT CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER gcc)
set(CMAKE_CXX_COMPILER g++)
endif()
set(CMAKE_CXX_STANDARD 11)
if ( NOT APPLE)
set(CURL_DIR build_resources/libcurl_ssl_x64)
endif()
Project(sam_simulation_core VERSION 1.0.0)
#####################################################################################################################
#
# Compile Options per Platform
#
#####################################################################################################################
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_STANDARD 11)

Generally speaking, the project could benefit from a deep cleaning and modernization of the CMake config (eg: avoid polluting the global space and use target specific compilation flags). I know that's probably not a priority and not a sexy task, just saying.

Additional context

I noticed some issues while trying to build EnergyPlus with clang-17 on macOS M1.

@brtietz
Copy link
Collaborator

brtietz commented Jan 23, 2024

Thank you for flagging this! We have some pending CMakeLists changes coming with #1035, we'll see if we can bundle these fixes in with those changes.

@brtietz brtietz added this to the SAM Fall 2024 Release milestone Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants