Skip to content

Commit

Permalink
r u working
Browse files Browse the repository at this point in the history
  • Loading branch information
lyndskg committed Jan 6, 2024
1 parent 853f4e2 commit e78c616
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 40 deletions.
43 changes: 19 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# Set the minimum required version of CMake
cmake_minimum_required(VERSION 3.26)

# Set the policy for find_package to use upper-case <PACKAGENAME>_ROOT variables
cmake_policy(SET CMP0144 OLD)

# Project configuration
project(black-scholes-cpp VERSION 1.0 LANGUAGES CXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=x86-64")
Expand All @@ -13,17 +16,6 @@ message(STATUS "C++ Compiler Flags: ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)

FetchContent_MakeAvailable(googletest)

# Set the policy for find_package to use upper-case <PACKAGENAME>_ROOT variables
cmake_policy(SET CMP0146 NEW)

# Locate the Google Test library
find_package(GTest REQUIRED)

Expand All @@ -40,12 +32,9 @@ add_subdirectory(test)
file(GLOB SOURCES "src/*.cpp" "include/black-scholes-cpp/*.h")

# Add the source files for the library
add_library(blackScholesLibrary
${SOURCES}
# Add other source files as needed
)
add_library(blackScholesLibrary ${SOURCES})

# Include directories for the library
# Add include directories for the library
target_include_directories(blackScholesLibrary
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
Expand All @@ -55,33 +44,39 @@ target_include_directories(blackScholesLibrary
# Set compiler features
target_compile_features(blackScholesLibrary PUBLIC cxx_std_20)

# Link against Threads library (if needed)
target_link_libraries(blackScholesLibrary PRIVATE Threads::Threads)

# Add the main executable
add_executable(black_scholes_cpp ${SOURCES})

# Add include directories for the main executable
target_include_directories(black_scholes_cpp
PRIVATE
# Add include directories
include_directories(${GTEST_INCLUDE_DIRS})
include_directories(black_scholes_cpp PRIVATE include/black-scholes-cpp)
include_directories(black_scholes_cpp PRIVATE include/third_party)

# Include directories for the library
target_include_directories(blackScholesLibrary
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
${GTEST_INCLUDE_DIRS}
include/black-scholes-cpp
include/third_party
# Add other include directories as needed
)

# Set compiler features
target_compile_features(blackScholesLibrary PUBLIC cxx_std_20)

# Link against Google Test, blackScholesLibrary, Threads, and other necessary libraries
target_link_libraries(black_scholes_cpp
PRIVATE
GTest::GTest
GTest::Main
GTest::gtest_main
blackScholesLibrary
curl
Threads::Threads
)

# Optionally, enable CTest for running tests with 'make test'
enable_testing()

include(GoogleTest)

gtest_discover_tests(black_scholes_cpp)
Expand Down
18 changes: 6 additions & 12 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CMakeLists.txt for the src directory

# Set the minimum required version of CMake
cmake_minimum_required(VERSION 3.26)

# Set the policy for find_package to use upper-case <PACKAGENAME>_ROOT variables
cmake_policy(SET CMP0144 OLD)

# Specify the C++ standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -13,18 +19,6 @@ include_directories(${GTEST_INCLUDE_DIRS})
# Collect source files
file(GLOB SOURCES "src/*.cpp" "include/black-scholes-cpp/*.h")

# Add the source files for the library
add_library(blackScholesLibrary ${SOURCES})

# Add include directories for the library
target_include_directories(blackScholesLibrary PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

# Set compiler features
target_compile_features(blackScholesLibrary PUBLIC cxx_std_20)

# Link against Threads library (if needed)
target_link_libraries(blackScholesLibrary PRIVATE Threads::Threads)

# Add the include directories for the main application
include_directories(src)

Expand Down
9 changes: 5 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
# Set the minimum required version of CMake
cmake_minimum_required(VERSION 3.26)

# Set the policy for find_package to use upper-case <PACKAGENAME>_ROOT variables
cmake_policy(SET CMP0144 OLD)

# Set GTest root directory
set(GTEST_ROOT "/opt/homebrew/Cellar/googletest/1.14.0" CACHE PATH "Google Test root directory")

# assume built-in pthreads on MacOS
IF(APPLE)
if(APPLE)
set(CMAKE_THREAD_LIBS_INIT "-lpthread")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(CMAKE_USE_WIN32_THREADS_INIT 0)
set(CMAKE_USE_PTHREADS_INIT 1)
set(THREADS_PREFER_PTHREAD_FLAG ON)
ENDIF()

find_package(Threads REQUIRED)
endif()

# Find and include Google Test
find_package(GTest REQUIRED)
Expand Down

0 comments on commit e78c616

Please sign in to comment.