satya-das/cppparser

Build on Linux with local Boost

agladilin opened this issue · 1 comments

Ubuntu 22.04 supplies Boost 1.74. I would like to link the cppparser with it. Can we have this supported?
The code below does this.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index f9c14db5..1c5c275a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,7 +4,7 @@ project(cppparser)
 
 enable_testing()
 
-include("../common/cmake/conf.cmake")
+#include("../common/cmake/conf.cmake")
 
 set(CMAKE_CXX_STANDARD 17)
 
@@ -17,9 +17,18 @@ add_subdirectory(third_party/btyacc_tp)
 
 add_definitions(-DBOOST_AUTO_LINK_NOMANGLE)
 
-add_subdirectory(../common/third_party/boost_tp/cmake  ${CMAKE_BINARY_DIR}/boost)
+#add_subdirectory(../common/third_party/boost_tp/cmake  ${CMAKE_BINARY_DIR}/boost)
 
-include_directories(../common/third_party)
+#include_directories(../common/third_party)
+
+set(Boost_USE_STATIC_LIBS OFF)
+set(Boost_USE_MULTITHREADED ON)
+set(Boost_USE_STATIC_RUNTIME OFF)
+find_package(Boost COMPONENTS filesystem program_options REQUIRED)
+
+if (NOT EXISTS "${CMAKE_SOURCE_DIR}/src/catch/catch.hpp")
+  file(DOWNLOAD "https://github.com/catchorg/Catch2/releases/download/v2.13.10/catch.hpp" "${CMAKE_SOURCE_DIR}/src/catch/catch.hpp")
+endif()
 
 #############################################
 ## CppParser
@@ -72,18 +81,18 @@ set(CPPPARSER_SOURCES
 )
 
 add_library(cppparser STATIC ${CPPPARSER_SOURCES})
-add_dependencies(cppparser btyacc boost_filesystem boost_program_options)
+#add_dependencies(cppparser btyacc boost_filesystem boost_program_options)
 target_link_libraries(cppparser
 	PUBLIC
-		boost_filesystem
-		boost_program_options
+		${Boost_FILESYSTEM_LIBRARY}
+		${Boost_PROGRAM_OPTIONS_LIBRARY}
 		boost_system
 )
 target_include_directories(
 	cppparser
 	PUBLIC
 		pub
-		../common/third_party/boost_tp
+		#../common/third_party/boost_tp
 	PRIVATE
 		hack
 )
diff --git a/third_party/btyacc_tp/CMakeLists.txt b/third_party/btyacc_tp/CMakeLists.txt
index a1cfa01d..c675f138 100644
--- a/third_party/btyacc_tp/CMakeLists.txt
+++ b/third_party/btyacc_tp/CMakeLists.txt
@@ -1,4 +1,4 @@
-include("../../../common/cmake/conf.cmake")
+#include("../../../common/cmake/conf.cmake")
 
 project(btyacc)
 

Also please note that the file(DOWNLOAD ...) directive is used in order to download catch.hpp. Thus I got rid of https://github.com/satya-das/common.git repo usage.

Using local boost is too complicated and doesn't guarantee compilation on all machines.