Skip to content

Commit

Permalink
build: Fix cmake depends, update version
Browse files Browse the repository at this point in the history
  • Loading branch information
tmmsartor committed Jul 14, 2024
1 parent 2ede89e commit d1322f8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
47 changes: 33 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,48 +1,67 @@
cmake_minimum_required(VERSION 3.12)
project(MadNLP_C VERSION 1.0.0) # Adjust the version as necessary
project(MadNLP_C VERSION 0.1.0) # Adjust the version as necessary


message(CHECK_START "Check Julia binary dir")
set(Julia_EXECUTABLE /usr/bin/julia)
set(BUILD_SCRIPT ${PROJECT_SOURCE_DIR}/compiler/build.jl)
set(MADNLP_VERSION "nd" CACHE STRING "MadNLP Julia Library Version")
set(JULIA_BIN_DIR "nd" CACHE STRING "Julia runtime binary dir default")
if (JULIA_BIN_DIR STREQUAL "nd")
execute_process(
COMMAND ${Julia_EXECUTABLE} --startup-file=no -e "print(dirname(Sys.BINDIR))"
OUTPUT_VARIABLE JULIA_BIN_DIR_PARSED
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
set(JULIA_BIN_DIR ${JULIA_BIN_DIR_PARSED} CACHE STRING "Julia runtime binary dir" FORCE)
endif()
message(CHECK_PASS ${JULIA_BIN_DIR})

message(CHECK_START "Reading MadNLP.jl version")
execute_process(
COMMAND ${Julia_EXECUTABLE} --startup-file=no --project=./ -e "using Pkg; Pkg.instantiate();m=Pkg.dependencies();v=m[findfirst(v->v.name==\"MadNLP\",m)].version; print(v);"
OUTPUT_VARIABLE MADNLP_VERSION
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
message(CHECK_START "Check MadNLP.jl version")
set(MADNLP_VERSION "nd" CACHE STRING "MadNLP Julia Library Version")
if (MADNLP_VERSION STREQUAL "nd")
execute_process(
COMMAND ${Julia_EXECUTABLE} --startup-file=no --project=./ -e "using Pkg; Pkg.instantiate();m=Pkg.dependencies();v=m[findfirst(v->v.name==\"MadNLP\",m)].version; print(v);"
OUTPUT_VARIABLE MADNLP_VERSION_PARSED
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
set(MADNLP_VERSION ${MADNLP_VERSION_PARSED} CACHE STRING "MadNLP Julia Library Version" FORCE)
endif()
message(CHECK_PASS ${MADNLP_VERSION})

set(MADNLP_C_FULLNAME madnlp_c-${MADNLP_VERSION}-${PROJECT_VERSION})
set(BUILD_SCRIPT ${PROJECT_SOURCE_DIR}/compiler/build.jl)

add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/MadNLP_env_status.txt
DEPENDS ${PROJECT_SOURCE_DIR}/Manifest.toml
COMMAND ${Julia_EXECUTABLE} --startup-file=no --project=./ -e "using Pkg; Pkg.instantiate()"
COMMAND ${Julia_EXECUTABLE} --startup-file=no --project=./ -e "using Pkg; Pkg.status()" > ${PROJECT_BINARY_DIR}/MadNLP_env_status.txt
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Instantiating Julia packages"
COMMENT "Instantiate Julia packages"
VERBATIM
)

add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/PackageCompiler_env_status.txt
DEPENDS ${PROJECT_BINARY_DIR}/MadNLP_env_status.txt
COMMAND ${Julia_EXECUTABLE} --startup-file=no --project=./ -e "using Pkg; Pkg.instantiate()"
DEPENDS ${PROJECT_SOURCE_DIR}/compiler/Manifest.toml
COMMAND ${Julia_EXECUTABLE} --startup-file=no --project=compiler -e "using Pkg; Pkg.instantiate()"
COMMAND ${Julia_EXECUTABLE} --startup-file=no --project=compiler -e "using Pkg; Pkg.status()" > ${PROJECT_BINARY_DIR}/PackageCompiler_env_status.txt
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Instantiating Julia build packages"
COMMENT "Instantiate Julia build packages"
VERBATIM
)

add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/${MADNLP_C_FULLNAME}/lib/libmadnlp_c.so
OUTPUT ${PROJECT_BINARY_DIR}/library_precompilation_dummy.txt
DEPENDS ${PROJECT_BINARY_DIR}/PackageCompiler_env_status.txt
DEPENDS ${PROJECT_SOURCE_DIR}/src/MadNLP_C.jl
COMMAND echo 1 > ${PROJECT_BINARY_DIR}/library_precompilation_dummy.txt
COMMAND ${Julia_EXECUTABLE} --startup-file=no --project=compiler ${BUILD_SCRIPT} ${PROJECT_BINARY_DIR}/${MADNLP_C_FULLNAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Create Madnlp precompiled library sysimage"
VERBATIM
)

add_custom_target(madnlp_c ALL
DEPENDS ${PROJECT_BINARY_DIR}/${MADNLP_C_FULLNAME}/lib/libmadnlp_c.so
DEPENDS ${PROJECT_BINARY_DIR}/library_precompilation_dummy.txt
)
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set(CMAKE_VERBOSE_MAKEFILE 1)
set(VERBOSE 1)

set(CASADI_DIR ${PROJECT_SOURCE_DIR}/../../casadi/build_madnlp/test/)
set(MADNLP_DIR ${PROJECT_SOURCE_DIR}/../build/madnlp_c-0.8.3-1.0.0/)
set(MADNLP_DIR ${PROJECT_SOURCE_DIR}/../build/madnlp_c-0.8.3-0.1.0/)
set(JULIA_DIR ${HOME}/.julia/juliaup/julia-1.10.4+0.x64.linux.gnu)

set(JULIA_INCLUDE_DIR ${JULIA_DIR}/include/julia/)
Expand Down

0 comments on commit d1322f8

Please sign in to comment.