-
Notifications
You must be signed in to change notification settings - Fork 1
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
Could you add a findOpenFOAM script for existing OpenFOAM? #15
Comments
I came up with this idea because I can use the following script to build a solver using openfoam 6 docker image : cmake_minimum_required (VERSION 3.8)
# cxx11
set( CMAKE_CXX_STANDARD 11 )
set(LIBS OpenFOAM dl m)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Xlinker --no-as-needed -Xlinker --add-needed")
link_directories($ENV{FOAM_LIBBIN})
add_definitions(-Dlinux64 -DWM_ARCH_OPTION=64 -DWM_DP -DWM_LABEL_SIZE=32 -DNoRepository -m64 -fPIC )
# Add source to this project's executable.
add_executable (laplacianFoam "laplacianFoam.C")
include_directories( $ENV{FOAM_SRC}/finiteVolume/lnInclude )
include_directories( $ENV{FOAM_SRC}/meshTools/lnInclude )
include_directories( $ENV{FOAM_SRC}/OpenFOAM/lnInclude )
include_directories( $ENV{FOAM_SRC}/OSspecific/POSIX/lnInclude )
set(LIBS finiteVolume fvOptions meshTools ${LIBS})
target_link_libraries(laplacianFoam ${LIBS}) So I think it is possible to write a separate findOpenFOAM script to get something like libOpenFOAM libMeshTool. Then users could write their own cmake script with easiness comparable to wmake's |
More example: cmake_minimum_required (VERSION 3.2 FATAL_ERROR)
# project setting
project(laplacianFoam VERSION 6 LANGUAGES CXX)
set( SOURCES laplacianFoam.C)
add_executable( ${PROJECT_NAME} ${SOURCES} )
# common settings
## set PIC for executables, randonization make it hard to attack.
set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON)
## recommended by CMake, see: https://rix0r.nl/blog/2015/08/13/cmake-guide/
include(GNUInstallDirs)
# create OpenFOAM target
add_library(OpenFOAM SHARED IMPORTED)
# cxx 11
target_compile_features(OpenFOAM INTERFACE cxx_std_11)
# include dirs
target_include_directories(OpenFOAM INTERFACE $ENV{FOAM_SRC}/OpenFOAM/lnInclude)
target_include_directories(OpenFOAM INTERFACE $ENV{FOAM_SRC}/OSspecific/POSIX/lnInclude)
# locate the libOpenFOAM.so file
unset(of_lib_path CACHE)
find_library(of_lib_path OpenFOAM PATHS $ENV{FOAM_LIBBIN})
set_property(TARGET OpenFOAM PROPERTY IMPORTED_LOCATION ${of_lib_path})
# definition
target_compile_definitions(OpenFOAM INTERFACE -Dlinux64 -DWM_ARCH_OPTION=64 -DWM_DP -DWM_LABEL_SIZE=32 -DNoRepository )
# depedent libs
target_link_libraries(OpenFOAM INTERFACE -ldl -lm)
# create finiteVolume target
add_library(finiteVolume SHARED IMPORTED)
target_include_directories(finiteVolume INTERFACE $ENV{FOAM_SRC}/finiteVolume/lnInclude)
# locate the libOpenFOAM.so file
unset(of_lib_path CACHE)
find_library(of_lib_path finiteVolume PATHS $ENV{FOAM_LIBBIN})
set_property(TARGET finiteVolume PROPERTY IMPORTED_LOCATION ${of_lib_path})
add_dependencies(finiteVolume OpenFOAM)
# create finiteVolume target
add_library(meshTools SHARED IMPORTED)
target_include_directories(meshTools INTERFACE $ENV{FOAM_SRC}/meshTools/lnInclude)
# locate the libOpenFOAM.so file
unset(of_lib_path CACHE)
find_library(of_lib_path meshTools PATHS $ENV{FOAM_LIBBIN})
set_property(TARGET meshTools PROPERTY IMPORTED_LOCATION ${of_lib_path})
add_dependencies(meshTools OpenFOAM)
# finalize setting
# warnings
target_compile_options(${PROJECT_NAME} PUBLIC -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -Wno-attributes)
# link options
## `--add-needed` is replaced by `--copy-dt-needed-entries`
target_link_libraries(${PROJECT_NAME} PUBLIC -Wl,--copy-dt-needed-entries)
## do not ignore supplied libraries even if they are unused. It seems useless now.
target_link_libraries(${PROJECT_NAME} PUBLIC -Wl,--no-as-needed )
# library dependencies, set final inc_dir,lib_dir automatically by deduction.
target_link_libraries(${PROJECT_NAME} PUBLIC OpenFOAM meshTools finiteVolume)
# debug setting
set(CMAKE_VERBOSE_MAKEFILE ON)
# note
## `-m64` is unnecessary
Comparing the command line of wmake and cmake:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
None yet
0 participants
I think it would be helpful.
The text was updated successfully, but these errors were encountered: