Skip to content

Instantly share code, notes, and snippets.

@fikovnik
Created March 31, 2017 14:16
Show Gist options
  • Select an option

  • Save fikovnik/b910135cc457d5d0b1dd7ec9342665ab to your computer and use it in GitHub Desktop.

Select an option

Save fikovnik/b910135cc457d5d0b1dd7ec9342665ab to your computer and use it in GitHub Desktop.
Getting R and Rcpp CPP and LD flags
set(NUM_TRUNC_CHARS 2)
execute_process(
COMMAND R CMD config --cppflags
OUTPUT_VARIABLE RCPPFLAGS)
string(SUBSTRING ${RCPPFLAGS} ${NUM_TRUNC_CHARS} -1 RCPPFLAGS)
include_directories(${RCPPFLAGS})
message("R CPP flags: ${RCPPFLAGS}")
execute_process(
COMMAND R CMD config --ldflags
OUTPUT_VARIABLE RLDFLAGS)
string(LENGTH ${RLDFLAGS} RLDFLAGS_LEN)
message("R LD flags: ${RLDFLAGS}")
if (${RLDFLAGS} MATCHES "[-][L]([^ ;])+")
string(SUBSTRING ${CMAKE_MATCH_0} ${NUM_TRUNC_CHARS} -1 RLDFLAGS_L)
string(STRIP ${RLDFLAGS_L} RLDFLAGS_L )
link_directories(${RLDFLAGS_L})
endif()
if (${RLDFLAGS} MATCHES "[-][l]([^;])+")
string(SUBSTRING ${CMAKE_MATCH_0} ${NUM_TRUNC_CHARS} -1 RLDFLAGS_l)
string(STRIP ${RLDFLAGS_l} RLDFLAGS_l )
link_libraries(${RLDFLAGS_l})
endif()
execute_process(
COMMAND Rscript -e "Rcpp:::CxxFlags()"
OUTPUT_VARIABLE RCPPINCL)
string(SUBSTRING ${RCPPINCL} ${NUM_TRUNC_CHARS} -1 RCPPINCL)
include_directories(${RCPPINCL})
message("Rcpp CPP flags: ${RCPPINCL}")
execute_process(
COMMAND Rscript -e "Rcpp:::LdFlags()"
OUTPUT_VARIABLE RCPPLIBS)
if (${RCPPLIBS} MATCHES "[-][L]([^ ;])+")
string(SUBSTRING ${CMAKE_MATCH_0} ${NUM_TRUNC_CHARS} -1 RCPPLIBS_L)
link_directories(${RCPPLIBS_L} )
endif()
message("Rcpp LD flags: ${RCPPLIBS}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment