Skip to content

Commit e3f8675

Browse files
committed
fmk - changes for conan2 and compiling on mac with clang, the CMakeLists2.txt, conanfile2.py and SimCenterFunctions2.cmake are temp and will replace original once migration to conan2 is complete, makeMac.sh will cp, build, and mv using these files, the SimCenterConanCompat is new, CmakeLists now uses find_package and the ConanCompat provides mapping between old conan and this new requires and what Mike G. had in the old simcenter_add_exe dependencies (Cluade provided this file)
1 parent 029f10b commit e3f8675

7 files changed

Lines changed: 565 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,4 @@ modules/performREC/pyrecodes/residual_demand_traffic_simulator/projects*
103103
applications.*
104104
modules/performREC/pyrecodes/pyrecodes/*
105105

106+
CMakeUserPresets.json

CMakeLists2.txt

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(SimCenterBackendApplications C CXX)
3+
4+
set(CMAKE_CXX_STANDARD 17)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
set(CMAKE_CXX_EXTENSIONS OFF)
7+
8+
set(CMAKE_COLOR_MAKEFILE ON)
9+
set(CMAKE_VERBOSE_MAKEFILE ON)
10+
11+
include(${CMAKE_BINARY_DIR}/conan_toolchain.cmake)
12+
13+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
14+
#set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE INTERNAL "" FORCE)
15+
16+
include(SimCenterFunctions)
17+
include(CMakeParseArguments)
18+
19+
list(APPEND SIMCENTER_MODULE_DIRS "${PROJECT_SOURCE_DIR}/modules")
20+
list(REMOVE_DUPLICATES SIMCENTER_MODULE_DIRS)
21+
set(SIMCENTER_MODULE_DIRS ${SIMCENTER_MODULE_DIRS} CACHE INTERNAL "All folders that contain SimCenter modules")
22+
23+
# On macOS, Apple Clang ships without OpenMP. Homebrew's libomp provides it but
24+
# is keg-only, so we must hint CMake before find_package(OpenMP) is called anywhere.
25+
if(APPLE)
26+
find_program(_brew brew)
27+
if(_brew)
28+
execute_process(COMMAND ${_brew} --prefix libomp
29+
OUTPUT_VARIABLE _libomp_prefix
30+
OUTPUT_STRIP_TRAILING_WHITESPACE
31+
ERROR_QUIET)
32+
if(_libomp_prefix AND EXISTS "${_libomp_prefix}")
33+
# Flags for FindOpenMP — no -I here, handled separately below
34+
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp")
35+
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp")
36+
set(OpenMP_CXX_LIB_NAMES "omp")
37+
set(OpenMP_C_LIB_NAMES "omp")
38+
set(OpenMP_omp_LIBRARY "${_libomp_prefix}/lib/libomp.dylib")
39+
# Make omp.h findable for any target in the build
40+
include_directories(SYSTEM "${_libomp_prefix}/include")
41+
link_directories("${_libomp_prefix}/lib")
42+
message(STATUS "macOS: using Homebrew libomp at ${_libomp_prefix}")
43+
else()
44+
message(WARNING "macOS: libomp not found via Homebrew. Run: brew install libomp")
45+
endif()
46+
endif()
47+
endif()
48+
49+
# Conan 2 / CMakeDeps: config files are generated into the build dir but targets
50+
# are not active until find_package() is called explicitly for each dependency.
51+
find_package(jansson REQUIRED)
52+
find_package(ZLIB REQUIRED)
53+
find_package(CURL REQUIRED)
54+
find_package(Eigen3 REQUIRED)
55+
find_package(clara REQUIRED)
56+
find_package(nanoflann REQUIRED)
57+
find_package(NLopt REQUIRED)
58+
find_package(kissfft REQUIRED)
59+
find_package(Boost REQUIRED)
60+
find_package(nlohmann_json REQUIRED)
61+
62+
# Re-expose packages under legacy CONAN_PKG:: names so module CMakeLists.txt
63+
# written for Conan 1 build without modification.
64+
include(SimCenterConanCompat)
65+
66+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/modules)
67+
add_subdirectory(modules)

cmake/SimCenterConanCompat.cmake

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
######################################################################################################################
2+
# SimCenterConanCompat.cmake
3+
#
4+
# Provides backward compatibility for module CMakeLists.txt written against Conan 1,
5+
# which used CONAN_PKG::<name> target names and the CONAN_INCLUDE_DIRS variable.
6+
#
7+
# Conan 2 / CMakeDeps generates <Package>::<Component> targets whose names vary by
8+
# recipe version. This file creates ALIAS targets (CONAN_PKG::<name>) pointing at
9+
# whatever real target was actually generated, trying multiple candidate names so
10+
# the mapping stays correct even if conan-center-index recipes change.
11+
#
12+
# Must be included AFTER all find_package() calls in the top-level CMakeLists.txt.
13+
######################################################################################################################
14+
15+
# _simcenter_conan_compat(<conan1_name> <candidate1> [<candidate2> ...])
16+
#
17+
# Finds the first existing candidate target and creates:
18+
# CONAN_PKG::<conan1_name> ALIAS pointing at it
19+
# Appends its include dirs to the CONAN_INCLUDE_DIRS cache variable.
20+
#
21+
function(_simcenter_conan_compat conan1_name)
22+
if(TARGET CONAN_PKG::${conan1_name})
23+
return()
24+
endif()
25+
26+
foreach(_candidate ${ARGN})
27+
if(TARGET ${_candidate})
28+
add_library(CONAN_PKG::${conan1_name} ALIAS ${_candidate})
29+
30+
get_target_property(_incs ${_candidate} INTERFACE_INCLUDE_DIRECTORIES)
31+
if(_incs)
32+
# Global CONAN_INCLUDE_DIRS (all packages combined)
33+
set(_merged ${CONAN_INCLUDE_DIRS} ${_incs})
34+
list(REMOVE_DUPLICATES _merged)
35+
set(CONAN_INCLUDE_DIRS ${_merged} CACHE INTERNAL
36+
"Aggregated Conan include dirs (Conan 1 compat)")
37+
38+
# Per-package CONAN_INCLUDE_DIRS_<NAME> (uppercase)
39+
string(TOUPPER "${conan1_name}" _upper)
40+
set(CONAN_INCLUDE_DIRS_${_upper} ${_incs} CACHE INTERNAL
41+
"Conan 1 compat include dirs for ${conan1_name}")
42+
endif()
43+
return()
44+
endif()
45+
endforeach()
46+
47+
message(WARNING
48+
"SimCenterConanCompat: no target found for CONAN_PKG::${conan1_name}. "
49+
"Tried: ${ARGN}")
50+
endfunction()
51+
52+
# Candidate lists are ordered most-likely-first; the first match wins.
53+
# Multiple candidates handle recipe changes across conan-center-index versions.
54+
_simcenter_conan_compat(jansson jansson::jansson)
55+
_simcenter_conan_compat(zlib ZLIB::ZLIB)
56+
_simcenter_conan_compat(libcurl CURL::libcurl CURL::CURL)
57+
_simcenter_conan_compat(eigen Eigen3::Eigen Eigen3::Eigen3 eigen::eigen)
58+
_simcenter_conan_compat(clara clara::clara)
59+
_simcenter_conan_compat(nanoflann nanoflann::nanoflann)
60+
_simcenter_conan_compat(nlopt NLopt::nlopt nlopt::nlopt)
61+
_simcenter_conan_compat(kissfft kissfft::kissfft)
62+
_simcenter_conan_compat(boost Boost::boost Boost::headers)
63+
_simcenter_conan_compat(jsonformoderncpp nlohmann_json::nlohmann_json)

0 commit comments

Comments
 (0)